Compile-time fold expression vs recursive template

Manu turkeyman at gmail.com
Sun Jun 14 12:01:51 UTC 2020


On Sun, Jun 14, 2020 at 9:50 PM Nick Treleaven via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> 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
>
>

It's implemented in my branch too if you wanna try it out!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20200614/d319c9d2/attachment.htm>


More information about the Digitalmars-d mailing list