DIP 88: Simple form of named parameters

xenon325 via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 25 23:05:53 PST 2016


On Sunday, 24 January 2016 at 13:33:50 UTC, Jacob Carlborg wrote:
> On 2016-01-24 14:24, Michel Fortin wrote:
>
>> On further thought, how do you make templates with 
>> specialization take
>> named arguments?
>>
>>      template TFoo(T)        { ... } // #1
>>      template TFoo(T : T[])  { ... } // #2
>>      template TFoo(T : char) { ... } // #3
>>
>> My guess would be this:
>>
>>      template TFoo(T:)        { ... } // #1
>>      template TFoo(T: : T[])  { ... } // #2
>>      template TFoo(T: : char) { ... } // #3
>>
>> ... but it makes the declaration a bit strange.
>
> Yes. Rule 7 covers that. There's also an example showing the 
> syntax, search for "Template specialization with named 
> parameter". Yes, it does look a bit strange.

Just like C++98 used to require space between two `>` in 
templates ? ;)
I see no way Walter would accept that.

Why not just:
```
@namedParams
template TFoo(T : char)
```

Other thoughts:
1. How often would one need to mix named and unnamed parameters ?
2. And how often would one need named params at all, so dlang 
should provide super-easy syntax with inline `:` ?
3. `:` is not very visible, nor searchable. (OTOH, with a lot of 
a)


More information about the Digitalmars-d mailing list