Lazy variadic not working, any alternatives?
John Colvin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue May 26 07:14:02 PDT 2015
On Tuesday, 26 May 2015 at 06:04:59 UTC, Tofu Ninja wrote:
> On Tuesday, 26 May 2015 at 05:54:11 UTC, John Colvin wrote:
>> Something like this appears to work:
>>
>> import std.typetuple : allSatisfy;
>>
>> enum implicityConvertibleToBool(T) = is(T : bool);
>>
>> bool tok_and(Args...)(lazy Args terms)
>> if(allSatisfy!(implicitlyConvertibleToBool, Args))
>> {
>> auto backup = getInputLocation();
>> foreach(term; terms)
>> {
>> if(term == false)
>> {
>> rewind(backup);
>> return false;
>> }
>> }
>> return true;
>> }
>
> Hmmm.... this does seem to work. Does this essentially expand
> out to tok_and(lazy bool arg1, lazy bool arg2, ...)?
Apparently yes, which surprised me. Storage classes and
TypeTuples (or Arguments, as they are now) are a bit of a dark
corner. E.g.
void foo(ref int, ref int);
alias A(T...) = T;
static assert(is(ParameterTypeTuple!foo ==
A!(ParameterTypeTuple!foo)));
That fails.
More information about the Digitalmars-d-learn
mailing list