Why can't templates use tuples for for argument types?

BCS ao at pathlink.com
Tue Jul 17 13:59:27 PDT 2007


Reply to Jarrett,

> "BCS" <ao at pathlink.com> wrote in message
> news:ce0a3343bf108c99670e3f3ff2c at news.digitalmars.com...
> 
>> A few times, I have wanted a template that works just like a tuple
>> taking template but where one or more of the spots must be filled and
>> a keep separate from the rest.
>> 
>> template Foo(A, B...) {}
>> 
>> these should work
>> 
>> Foo!(1, int);
>> Foo!(int, 1);
>> Foo!(Foo!(int, 1));
>> this shouldn't
>> 
>> Foo!();
>> 
> template Foo(A...)
> {
> static assert(A.length >= 1, "Foo needs at least one parameter");
> do something with A[0];
> do something else with A[1 .. $];
> }

How did you hack my system!!!! I'm sure you copied that right off my hard 
drive }:-|

<g>
All joking aside, I keep running into that so often that I want a cleaner 
way to do it. I want the proper usage documented in the code, not the comments 
and the asserts. I want to be able to talk about things by name without having 
to make aliases. It's a minor point but...




More information about the Digitalmars-d-learn mailing list