Template explosion

Timothee Cour thelastmammoth at gmail.com
Tue Jul 16 20:29:42 PDT 2013


On Tue, Jul 16, 2013 at 7:52 PM, JS <js.mdnq at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130716/2e6b06f5/attachment.html>


More information about the Digitalmars-d-learn mailing list