D's metaprogramming could be flawed

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 22 05:38:21 PST 2016


On 01/22/2016 01:57 PM, maik klein wrote:
>
> It seems that D doesn't have a way to express C++'s fold
> expression/template expansions.
>
>
> For example in C++ I could write
>
> std::make_tuple(std::ref(ts)...);
>
> and it would expand like
>
> std::make_tuple(std::ref(t1), std::ref(t2), ... , std::ref(tn));
> ...
> For example I need to be able to expand TupleRef like this
>
> f(someTupleRef.expand);
> f(t[0].get(), t[1].get(), ... , t[n].get());

Custom expansions can be built with string mixins.

mixin(`f(`~iota(t.length).map!(i=>text(`t[`,i,`].get()`)).join(",")~`);`);


More information about the Digitalmars-d mailing list