Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
April 16, 2008 ref storage class in templates | ||||
---|---|---|---|---|
| ||||
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' |
April 16, 2008 Re: ref storage class in templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Extrawurst | How is that a bug? I certainly wouldn't have expected that to compile. You can't pass "storage classes" to templates. |
April 16, 2008 Re: ref storage class in templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Janice Caron | 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
|
April 16, 2008 Re: ref storage class in templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Extrawurst | 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
|
April 16, 2008 Re: ref storage class in templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | Regan Heath wrote:
> 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
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, too
|
Copyright © 1999-2021 by the D Language Foundation