Rebind template

Jack Applegame via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Aug 20 23:28:25 PDT 2016


On Sunday, 21 August 2016 at 00:06:07 UTC, Engine Machine wrote:
> 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.

You are wrong. tmpl is just alias of template T. So tmpl!a and 
T!a are the same type.

alias X = T!(int, short, char);
alias Y = Rebind!(X, short, char, int);
static assert(is(Y == T!(short, char, int))); // passes



More information about the Digitalmars-d-learn mailing list