Argument S to typeof is not an expression

Dicebot m.strashun at gmail.com
Tue May 7 03:33:57 PDT 2013


On Tuesday, 7 May 2013 at 06:41:25 UTC, Meta wrote:
> I don't really understand why either of these error messages 
> are occurring. The first is just incomprehensible, and the 
> second seems like it should work. In this case, rhs is fully 
> accessible at compile time in the expression (a + b), so why 
> does the compiler complain?

1) typeof don't work on types. Period. It is often inconvenient 
in generic code (I'd love it typeof(T) to be T for simplicity) 
but it is how it is done now. In your case pragma(msg, T) will be 
correct one.

2) template parameter must be known at compile time. "rhs" is a 
plain function parameter, so compiler can't be sure it is known 
at compile time, so it is an error. Same goes for n. In general, 
only enum's and template parameters can be assumed to be known at 
compile-time. Your code seems to wrongly mix plain variables with 
template code all over.

If you can explain for behavior/API you are trying to achieve, 
most likely I'll be able to provide a more idiomatic D solution.



More information about the Digitalmars-d-learn mailing list