instantiate each of a tuple of templates (Take 2)

monarch_dodra monarchdodra at gmail.com
Fri Aug 2 05:55:19 PDT 2013


On Friday, 2 August 2013 at 12:37:00 UTC, John Colvin wrote:
> On Friday, 2 August 2013 at 11:26:41 UTC, monarch_dodra wrote:
>> Is this what you want?
>
> Thankyou, yes that's exactly right.
>
> Are all types guaranteed to have a working .init value? I can't 
> think of any way not to, but I just want to be sure.

Yes, but there's a catch: T.init is an RValue, so if you have 
"foo(ref T)", then:
foo(T.init)
won't compile (and rightly so).

user denis-sh proposed the lvalueOf functionional "trait":
https://github.com/D-Programming-Language/phobos/pull/1261
@property ref T lvalueOf(T)(inout int = 0);

This can be used *only* at compile time (no body, so it won't 
link), and is meant to be used in constraints/static ifs.

In this case:
static assert(is(typeof(foo(lvalueOf!T))));
*Will* work.


More information about the Digitalmars-d-learn mailing list