No static fold in phobos ?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Nov 27 15:46:32 PST 2015


On 11/27/2015 12:57 PM, userabcABC123 wrote:
> That would work on an AliasSeq ?
> I'm surprised not to find one:
>
> eg:
>
> ~~~~~~~
> enum seq = AliasSeq!("aa", "bb");
> enum val = staticFold!((a,b)=>a~b, seq);
> static assert(val == "aabb");
> ~~~~~~~
>
> it works with foreach or a eponymous template that consumes the sequence
> , but as said where is it in phobos ?

Thanks to CTFE, there is usually no need for static of anything in D. 
Your code works with a few changes:

import std.meta;
import std.algorithm;

void main() {
     enum seq = AliasSeq!("aa", "bb");
     enum val = [ seq ].reduce!((a, b) => a ~ b);
     static assert(val == "aabb");
}

Ali



More information about the Digitalmars-d-learn mailing list