isExpressions -> isValuesSeq

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sat Dec 12 12:05:44 PST 2015


On 12/12/2015 07:41 AM, Shriramana Sharma wrote:
> This is w.r.t. http://dlang.org/phobos/std_traits.html#isExpressions:
>
> I am trying the following code:
>
> import std.stdio, std.meta, std.traits;
> void main()
> {
>      alias a = AliasSeq!(1 + 2, "foo" == "goo");
>      if (isExpressions!a) write("This AliasSeq contains expressions: ");
>      foreach (v; a) { write(v.stringof, ", "); } writeln();
>      writeln("This should be: ", (1 + 2).stringof, ", ", ("foo" ==
> "goo").stringof);
> }
>
> The output is:
>
> This AliasSeq contains expressions: 3, false,
> This should be: 1 + 2, "foo" == "goo"
>
> Clearly, the AliasSeq is not able to store the expressions themselves since
> they are automatically evaluated at compile time. It stores only the values
> that the expressions evaluate to. Further, expressions which are not
> evaluable at compile time aren't permitted in the AliasSeq. (I tried it.)
> Thus the appropriate name would thus be isValuesSeq, no?
>

There is also this:

import std.stdio;
int x,y;
@(x+1,y) void foo(){}
void main(){ writeln(__traits(getAttributes,foo)); }

(However, variadic template arguments that are non-symbol expressions 
are always evaluated, therefore isExpressions does not work on the 
result of __traits(getAttributes,foo).)


More information about the Digitalmars-d mailing list