Argument S to typeof is not an expression
Jacob Carlborg
doob at me.com
Tue May 7 04:03:31 PDT 2013
On 2013-05-07 08:41, Meta wrote:
> template Test(alias N)
> if (isIntegral!(typeof(N)))
> {
> struct S
> {
> typeof(N) n = N;
>
> auto opAdd(T)(T rhs)
> {
> //Error: argument S to typeof is not an expression
> pragma(msg, typeof(T));
> //Error: variable rhs cannot be read at compile time
> return Test!(n + rhs.n);
> }
> }
> auto st = S(N);
> alias Test = st;
> }
>
> void main()
> {
> auto a = Test!2;
> auto b = Test!3;
> writeln(typeof(a).stringof ~ " a = ", a, ", ",
> typeof(b).stringof ~ " b = ", b, ", ",
> typeof(a + b).stringof ~ " a + b = ");
> }
>
> 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?
As a workaround for "typeof" you can use this:
https://github.com/jacob-carlborg/orange/blob/master/orange/util/Traits.d#L213
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list