default args for templates

John Colvin john.loughran.colvin at gmail.com
Fri Jan 17 05:04:47 PST 2014


On Friday, 17 January 2014 at 12:18:51 UTC, Manu wrote:
> Observing strange behaviour, just want to know if it's 
> correct...
>
> struct VertexBuffer(VertexDataType = void) {}
>
> VertexBuffer x;
>   Error: struct VertexBuffer(VertexDataType = void) is used as 
> a type
>
> auto y = VertexBuffer();
>   Error: struct VertexBuffer(VertexDataType = void) cannot 
> deduce template
> function from argument types !()()
>
> But this works:
> VertexBuffer!() z;
>
>
> Why should I need to supply an empty argument list? This 
> defeats the
> purpose of the default arg, and obscures my code in the common 
> case.
>
> Untyped vertex buffers are the default, and it would be nice to 
> be able to
> declare them trivially.
>
> Also, those error messages are quite unhelpful.

There's enough subtlety in function identifiers vs function 
results due to optional parenthesis, I'd rather not have the same 
for templates too. Even if it could be made unambiguous, it would 
likely get pretty confusing.


More information about the Digitalmars-d mailing list