default args for templates
monarch_dodra
monarchdodra at gmail.com
Fri Jan 17 05:50:51 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.
The funny part though is that it works if the template is a
function.
//----
template foo(T = int)
{
T foo();
}
void main()
{
foo(); //Calls foo!int.foo();
}
//----
I guess it's the "()" that saves our butts. Without it, we need
explicit instantiation:
//----
template foo(T = int)
{
T foo();
}
void main()
{
pragma(msg, typeof(foo).stringof);
pragma(msg, typeof(foo!int).stringof);
}
//----
void
int()
//----
More information about the Digitalmars-d
mailing list