[Issue 9591] std.typetuple.staticApplyMap

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Sep 15 12:46:35 UTC 2017


https://issues.dlang.org/show_bug.cgi?id=9591

Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |schveiguy at yahoo.com
         Resolution|WONTFIX                     |---

--- Comment #2 from Steven Schveighoffer <schveiguy at yahoo.com> ---
std.typetuple was moved to std.meta, so the request is still valid.

We have ApplyLeft and ApplyRight, which take a template as the first parameter,
and combined with staticMap, could work as long as the parameters are reversed
(the template comes last). Having something that applies a single parameter (or
even multipe ones) to a list of templates would be useful as well, and is
difficult to do directly.

However, I don't think we need a specific function, a helper like this would
work:

template ApplyWith(Args...)
{
   alias ApplyWith = ApplyLeft!(Args[$-1], Args[0 .. $-1]);
}

alias T = staticMap!(ApplyLeft!(ApplyWith, string), leftJustify, center,
rightJustify);

void main()
{
   foreach(f; T)
      writeln(f("hello", 20));
}

It's not perfect. The resulting T isn't a tuple of instantiated templates, it's
a tuple of ApplyLeft aliases, awaiting instantiation.

But a helper like the above would be useful. Is there an "Instantiate" template
that could be used in place of ApplyLeft inside the ApplyWith template? That
might be more proper.

--


More information about the Digitalmars-d-bugs mailing list