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

BCS BCS at pathlink.com
Wed Jul 18 10:07:35 PDT 2007


Bill Baxter wrote:
> Jarrett Billingsley wrote:
> 
>> "BCS" <ao at pathlink.com> wrote in message 
>> news:ce0a3343bf268c99691d2e8b71a at news.digitalmars.com...
>>
>>> 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...
>>>
>>
>> The issue is that there's currently no way to specify that a template 
>> parameter can be 'anything'.  T means it's a type, alias T means it's 
>> a symbol, and <sometype> T means it's a value.  If you could specify 
>> that a parameter could take anything, this would be trivial.  How 
>> about using .. - it means it's kind of like a tuple, but shorter ;)
>>
>> template Foo(A.., B...)
>> {
>>
>> }
>>
>> Or, take a page from Erlang:
>>
>> template Foo(A | B...)
>> {
>>
>> }
>>
>> In this case, A can be anything, and not just a type, because it's on 
>> the left of a bar.  An issue with this, however, is that you can't 
>> have a type parameter. 
> 
> 
> Walter resoundingly rejected some other proposal that involved '..' on 
> the grounds that '..' looks far too much like '...' to bleary eyes.  So 
> I think .. is out.
> 
> --bb

How about

A[1]...  or A...[1]

This would be a tuple that must have exactly 1 item. Plainly this would 
also allow A[4]... , a tuple with 4 items and might also extend to 
A[3..5]... a tuple with 3,4 or 5 items. (or would that be 3 or 4 to 
match the slice semantics?) This last bit wouldn't mix with normal 
tuples though.


More information about the Digitalmars-d-learn mailing list