digitalmars.D.learn - Template explosion
- JS (8/8) Jul 16 2013 It seems that one must use two templates to process built in
- Timothee Cour (19/27) Jul 16 2013 template a(T...)if(T.length==1){
- Timothee Cour (11/44) Jul 16 2013 A)
- JS (3/59) Jul 16 2013 I think this is the real problem, else it would be rather easy. I
It seems that one must use two templates to process built in times and strings template A(string a) { ... } template A(a) { enum A = A(typeof(a).stringof); } This is so we can do stuff like A!(double) and A!("double"). The problem is when we have many parameters the number of permutations increases exponentially. Is there a better way to unify the two?
Jul 16 2013
On Tue, Jul 16, 2013 at 7:52 PM, JS <js.mdnq gmail.com> wrote:It seems that one must use two templates to process built in times and strings template A(string a) { ... } template A(a) { enum A = A(typeof(a).stringof); } This is so we can do stuff like A!(double) and A!("double"). The problem is when we have many parameters the number of permutations increases exponentially. Is there a better way to unify the two?template a(T...)if(T.length==1){ enum a=1; } void main(){ auto a1=a!double; auto a2=a!"double"; } However: This syntax sucks. Why not support the following syntax: template a(auto T) {...} with same semantics? Because this is problematic with more arguments: I'd like this: template a(auto T1, double T2){...} but instead have to do that: template a(T...)if(is(T[1]==double)) {...} and it gets quickly more complicated
Jul 16 2013
On Tue, Jul 16, 2013 at 8:29 PM, Timothee Cour <thelastmammoth gmail.com>wrote:On Tue, Jul 16, 2013 at 7:52 PM, JS <js.mdnq gmail.com> wrote:A) actually, I'm not sure if auto would be the best keyword here, but maybe another keyword. B) What's the rationale why alias can't match to a primitive type in the first place? C) correction: above, it should be: template a(T...)if(T.length==2 && is(T[1]==double)) {...} which is quite verbose.It seems that one must use two templates to process built in times and strings template A(string a) { ... } template A(a) { enum A = A(typeof(a).stringof); } This is so we can do stuff like A!(double) and A!("double"). The problem is when we have many parameters the number of permutations increases exponentially. Is there a better way to unify the two?template a(T...)if(T.length==1){ enum a=1; } void main(){ auto a1=a!double; auto a2=a!"double"; } However: This syntax sucks. Why not support the following syntax: template a(auto T) {...} with same semantics? Because this is problematic with more arguments: I'd like this: template a(auto T1, double T2){...} but instead have to do that: template a(T...)if(is(T[1]==double)) {...} and it gets quickly more complicated
Jul 16 2013
On Wednesday, 17 July 2013 at 03:34:17 UTC, Timothee Cour wrote:On Tue, Jul 16, 2013 at 8:29 PM, Timothee Cour <thelastmammoth gmail.com>wrote:I think this is the real problem, else it would be rather easy. I don't mind writing static if's for each argument as that's linear.On Tue, Jul 16, 2013 at 7:52 PM, JS <js.mdnq gmail.com> wrote:A) actually, I'm not sure if auto would be the best keyword here, but maybe another keyword. B) What's the rationale why alias can't match to a primitive type in the first place?It seems that one must use two templates to process built in times and strings template A(string a) { ... } template A(a) { enum A = A(typeof(a).stringof); } This is so we can do stuff like A!(double) and A!("double"). The problem is when we have many parameters the number of permutations increases exponentially. Is there a better way to unify the two?template a(T...)if(T.length==1){ enum a=1; } void main(){ auto a1=a!double; auto a2=a!"double"; } However: This syntax sucks. Why not support the following syntax: template a(auto T) {...} with same semantics? Because this is problematic with more arguments: I'd like this: template a(auto T1, double T2){...} but instead have to do that: template a(T...)if(is(T[1]==double)) {...} and it gets quickly more complicatedC) correction: above, it should be: template a(T...)if(T.length==2 && is(T[1]==double)) {...} which is quite verbose.
Jul 16 2013