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

Bill Baxter dnewsgroup at billbaxter.com
Wed Jul 18 17:01:11 PDT 2007


BCS wrote:
> Reply to Don,
> 
>> int [] is not an allowed as a template value parameter. Only char[],
>> wchar[], dchar[], integers, and floating-point types can be template
>> value parameters. (In C++, only integers are allowed).
>>
> 
> 
> strange, this works
> 
> |template Types(A...)
> |{
> |  template Values(B...)
> |  {
> |  }
> |}
> |
> |alias Types!(int, bool, int[]).Values!(1,true,[1,2,3]) bob;
> 
> And while I'm thinking about it; why isn't there something like a "one 
> space tuple"?
> 
> 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!();
> 
> 
> (alias dosen't work)

Rather than proposing a bunch of new syntax, isn't the solution just to 
make those things work as expected?  If you want at least one thing it 
seems perfectly reasonable to me to do:

template Foo(A, B...) {
    alias Tuple!(A,B) ArgTuple;
    ...
}

if that doesn't work, then that's what needs to be fixed.

I don't really understand the point of wanting to be able to specify a 
template argument that could be *anything* -- alias, value, or symbol. 
Other than a big static if, I can't see how you would be able to 
implement any functionality when it could be any one of those things.

But I'm probably just being dense.

--bb


More information about the Digitalmars-d-learn mailing list