Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
October 28, 2016 Default struct member initializer ? | ||||
---|---|---|---|---|
| ||||
Hi ! Is there such a magic ? struct S { uint k = 2; } enum Value = Foo!(S.k); // Value == 2 Thanks. |
October 28, 2016 Re: Default struct member initializer ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Temtaime | On Friday, 28 October 2016 at 11:20:50 UTC, Temtaime wrote:
> Hi !
>
> Is there such a magic ?
>
> struct S { uint k = 2; }
>
> enum Value = Foo!(S.k); // Value == 2
>
> Thanks.
struct S { int k = 2; }
enum Value = S.init.k;
static assert (Value == 2);
|
October 28, 2016 Re: Default struct member initializer ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Friday, 28 October 2016 at 11:23:47 UTC, John Colvin wrote:
> On Friday, 28 October 2016 at 11:20:50 UTC, Temtaime wrote:
>> Hi !
>>
>> Is there such a magic ?
>>
>> struct S { uint k = 2; }
>>
>> enum Value = Foo!(S.k); // Value == 2
>>
>> Thanks.
>
> struct S { int k = 2; }
>
> enum Value = S.init.k;
>
> static assert (Value == 2);
Oh i see, thanks
|
October 28, 2016 Re: Default struct member initializer ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Temtaime | But what about the case when default ctor is disabled ? |
October 28, 2016 Re: Default struct member initializer ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Temtaime | On Friday, 28 October 2016 at 11:37:52 UTC, Temtaime wrote:
> But what about the case when default ctor is disabled ?
Only relevant if you've written something like `@disable static S init();`, which you shouldn't be doing anyway. `.init` is independent of `@disable this()`
|
Copyright © 1999-2021 by the D Language Foundation