Argument S to typeof is not an expression

Dicebot m.strashun at gmail.com
Thu May 9 05:21:23 PDT 2013


On Thursday, 9 May 2013 at 01:08:28 UTC, Meta wrote:
> I can't get the structs to be evaluated at compile time, so I 
> guess that's a lost cause.

Well, structs can be evaluated at compile-time but can't be value 
template parameters. You can do a small trick in this case though:

http://dpaste.1azy.net/c2188c90

struct Test(int N)
{
	enum n = N;
	
	auto add(int i)()
	{
		return Test!(n + i)();
	}
	
	alias n this;
}

void main()
{
	import std.stdio;
	enum a = Test!5();
	enum b = Test!3();
	writeln(a.add!b());
}

Will this do?

But actually this feels more like a task for CTFE. You can write 
a normal opAdd that does bounds check at run-time and then add 
"if (!__ctfe) assert(0);" to guarantee it will never be used in 
real run-time.


More information about the Digitalmars-d-learn mailing list