Rebind template
Engine Machine via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Aug 20 17:06:07 PDT 2016
On Saturday, 20 August 2016 at 22:21:00 UTC, ag0aep6g wrote:
> On 08/21/2016 12:11 AM, Engine Machine wrote:
>> Is there a way to rebind the arguments of a template?
>>
>> template foo(X)
>> {
>> // X is like A!(a,b,c)
>> Y = Rebind!(X,d,e,f);
>> // Y is like A!(d,e,f);
>> }
>>
>> foo(A!(a,b,c));
>>
>> ?
>
> template Rebind(alias instance, newArgs...)
> {
> import std.traits: TemplateOf;
> alias tmpl = TemplateOf!instance;
> alias Rebind = tmpl!newArgs;
> }
This doesn't work because the rebound type is of type tmpl and
not the original
e.g.,
Rebind!(T!b, a)
is tmpl!a not T!a.
More information about the Digitalmars-d-learn
mailing list