www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Partially instantiated template as argument to alias parameter.

reply Yuxuan Shui <yshuiv7 gmail.com> writes:
I think this is a reasonable use case:

auto A(R, S)(R a,S b) {return a+b;}

auto B(alias f)(){return f(1, 1.0);}

void main{writeln(B!(A!int)());}
Nov 04 2015
next sibling parent Yuxuan Shui <yshuiv7 gmail.com> writes:
On Wednesday, 4 November 2015 at 23:07:42 UTC, Yuxuan Shui wrote:
 I think this is a reasonable use case:

 auto A(R, S)(R a,S b) {return a+b;}

 auto B(alias f)(){return f(1, 1.0);}

 void main{writeln(B!(A!int)());}
For now I have to explicitly write A like this: template A(R){auto A(S)(R a, S b){...}}
Nov 04 2015
prev sibling parent reply Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
On Wednesday, 4 November 2015 at 23:07:42 UTC, Yuxuan Shui wrote:
 I think this is a reasonable use case:

 auto A(R, S)(R a,S b) {return a+b;}

 auto B(alias f)(){return f(1, 1.0);}

 void main{writeln(B!(A!int)());}
Currently this is doable by moving the parameters that are to be explicitly instantiated to an outer template: template A(R) { auto A(S)(R a,S b) {return a+b;} }
Nov 04 2015
parent Yuxuan Shui <yshuiv7 gmail.com> writes:
On Wednesday, 4 November 2015 at 23:10:09 UTC, Vladimir Panteleev 
wrote:
 On Wednesday, 4 November 2015 at 23:07:42 UTC, Yuxuan Shui 
 wrote:
 I think this is a reasonable use case:

 auto A(R, S)(R a,S b) {return a+b;}

 auto B(alias f)(){return f(1, 1.0);}

 void main{writeln(B!(A!int)());}
Currently this is doable by moving the parameters that are to be explicitly instantiated to an outer template: template A(R) { auto A(S)(R a,S b) {return a+b;} }
I'm aware of this, but this is clumsy and limiting. For example, I can have a template with N parameters, I want to be able to use any partially instantiation of this template as arguments.
Nov 04 2015