digitalmars.D - default args for templates
- Manu (14/14) Jan 17 2014 Observing strange behaviour, just want to know if it's correct...
- Jacob Carlborg (5/19) Jan 17 2014 Yeah, that's a really annoying limitation. I'm wonder if there's a
- bearophile (5/7) Jan 17 2014 If the instantiation is automatic, then what's the literal to
- Jacob Carlborg (4/6) Jan 17 2014 Perhaps based on the context, but that might be a bad idea.
- Dicebot (5/10) Jan 17 2014 I think it is impossible in general case:
- Jacob Carlborg (5/9) Jan 17 2014 The compiler would first try the template symbol, if that fails try the
- Manu (3/9) Jan 17 2014 The context gives everything it needs. It's clearly being used to declar...
- bearophile (8/9) Jan 17 2014 I don't think so. If you pass one of those literals to a template
- Jacob Carlborg (5/9) Jan 17 2014 Template name, because you can override that with !() to mean template
- John Colvin (5/25) Jan 17 2014 There's enough subtlety in function identifiers vs function
- monarch_dodra (29/49) Jan 17 2014 The funny part though is that it works if the template is a
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.
Jan 17 2014
On 2014-01-17 13:18, 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.Yeah, that's a really annoying limitation. I'm wonder if there's a bugzilla entry for it. -- /Jacob Carlborg
Jan 17 2014
Jacob Carlborg:Yeah, that's a really annoying limitation. I'm wonder if there's a bugzilla entry for it.If the instantiation is automatic, then what's the literal to specify the un-instantiated template? Bye, bearophile
Jan 17 2014
On 2014-01-17 13:53, bearophile wrote:If the instantiation is automatic, then what's the literal to specify the un-instantiated template?Perhaps based on the context, but that might be a bad idea. -- /Jacob Carlborg
Jan 17 2014
On Friday, 17 January 2014 at 13:40:05 UTC, Jacob Carlborg wrote:On 2014-01-17 13:53, bearophile wrote:I think it is impossible in general case: pragma(msg, StructSymbol.stringof); // "StructSymbol" or "StructSymbol!(void)" ? Add aliases on top of it and it quickly gets messy.If the instantiation is automatic, then what's the literal to specify the un-instantiated template?Perhaps based on the context, but that might be a bad idea.
Jan 17 2014
On 2014-01-17 14:44, Dicebot wrote:I think it is impossible in general case: pragma(msg, StructSymbol.stringof); // "StructSymbol" or "StructSymbol!(void)" ? Add aliases on top of it and it quickly gets messy.The compiler would first try the template symbol, if that fails try the instantiation. -- /Jacob Carlborg
Jan 17 2014
On 17 January 2014 22:53, bearophile <bearophileHUGS lycos.com> wrote:Jacob Carlborg: Yeah, that's a really annoying limitation. I'm wonder if there's aThe context gives everything it needs. It's clearly being used to declare a variable.bugzilla entry for it.If the instantiation is automatic, then what's the literal to specify the un-instantiated template?
Jan 17 2014
Manu:The context gives everything it needs.I don't think so. If you pass one of those literals to a template by alias, you are passing the template name (the type constructor) or the instantiated template (the type)? Both are valid usages and I think the compiler can't choose by itself. So I think this is a bad idea. Bye, bearophile
Jan 17 2014
On 2014-01-17 15:47, bearophile wrote:I don't think so. If you pass one of those literals to a template by alias, you are passing the template name (the type constructor) or the instantiated template (the type)? Both are valid usages and I think the compiler can't choose by itself. So I think this is a bad idea.Template name, because you can override that with !() to mean template instantiation. -- /Jacob Carlborg
Jan 17 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.
Jan 17 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() //----
Jan 17 2014