digitalmars.D - ref storage class in templates
- Extrawurst (18/18) Apr 16 2008 the documentation states that ref is a storage class for function
- Janice Caron (2/2) Apr 16 2008 How is that a bug? I certainly wouldn't have expected that to compile.
- Regan Heath (8/10) Apr 16 2008 I suspect the confusion arises because 'const' is used as both a storage...
- Robert Fraser (4/19) Apr 16 2008 We need to get rid of const the type modifier and keep const the type
- Christian Kamm (4/6) Apr 16 2008 As the others have pointed out, it is intended behavior: storage classes...
the documentation states that ref is a storage class for function parameters. just that this code piece wont compile cause the compiler doesn't. const in contrast works in templates too. so if no one has a veto i will file this as a bug for dmd. [CODE] void call(U...)(void delegate(U) dg, U args) { dg(args); } void main() { void plus(ref int x) {} int val = 2; call!(ref int)(&plus,val); } [/CODE] dmd2.012: main.d(13): expression expected, not 'ref'
Apr 16 2008
How is that a bug? I certainly wouldn't have expected that to compile. You can't pass "storage classes" to templates.
Apr 16 2008
Janice Caron wrote:How is that a bug? I certainly wouldn't have expected that to compile. You can't pass "storage classes" to templates.I suspect the confusion arises because 'const' is used as both a storage class and as a type modifier. eg. const int a = 5; //storage class void foo(const int a) {} //type modifier and you can pass type modifiers to templates. Regan
Apr 16 2008
Regan Heath wrote:Janice Caron wrote:We need to get rid of const the type modifier and keep const the type constructor as the only way to do it. That would solve the return-type const problem, tooHow is that a bug? I certainly wouldn't have expected that to compile. You can't pass "storage classes" to templates.I suspect the confusion arises because 'const' is used as both a storage class and as a type modifier. eg. const int a = 5; //storage class void foo(const int a) {} //type modifier and you can pass type modifiers to templates. Regan
Apr 16 2008
Extrawurst Wrote:call!(ref int)(&plus,val); dmd2.012: main.d(13): expression expected, not 'ref'As the others have pointed out, it is intended behavior: storage classes are only valid in function parameter declarations and thus can't be passed to a template as a type parameter. You can pass 'ref int' within a type tuple using variadic template arguments for some reason, but I'm pretty sure that's useless (unless you resort to string mixins). See bugs 1818, 1411 and 1424 for related issues. Christian
Apr 16 2008