Compile-time fold expression vs recursive template
Nick Treleaven
nick at geany.org
Sun Jun 14 11:45:36 UTC 2020
On Saturday, 13 June 2020 at 10:52:46 UTC, Nick Treleaven wrote:
> Recently 2 ideas have been proposed to reduce the need for
> recursive templates:
The reason for these is that recursive template expansion is slow
and can use a lot of memory which is never freed.
> * A `Seq...` expression to expand inline a named sequence, or
> an expression containing one or more named sequences.
Sorry, this should've read: "`Expression...` to expand an
expression containing one or more named sequences". Here's the
DIP link:
https://github.com/dlang/DIPs/blob/f9790ee6760b2d3cd0dbc1e816080c29c00c6dc2/DIPs/DIP10xx.md#add-unary-operator-
> This is essentially just a compiler intrinsic to perform the
> std.meta.Map operation, so it cannot wholly implement the other
> recursive templates in std.meta (though in some cases it may
> help).
Manu did propose a follow up to that would support a very basic
fold expression, but it seems to be limited to using an operator
between element expressions (no `static if`):
>> Static reduce would allow `...` as an argument to a BinOp
>> Ie; `Tup + ...` would expand `Tup[0] + Tup[1] + Tup[2] + ...`
>> You could do `is(FindType == Tup) || ...`, and it would
>> evaluate true if
>> FindType exists in Tup, with no junk template instantiations!
https://forum.dlang.org/post/mailman.2786.1587566241.31109.digitalmars-d@puremagic.com
More information about the Digitalmars-d
mailing list