Is there a way to see if .init has been set by the user?

simendsjo simendsjo at gmail.com
Sat Sep 21 06:30:17 PDT 2013


On Saturday, 21 September 2013 at 12:50:20 UTC, Andrej Mitrovic 
wrote:
> On 9/21/13, bearophile <bearophileHUGS at lycos.com> wrote:
>> I think there is no simple
>> way to know if a variable has being default-initialized or not.
>> Why do you want to know it?
>
> There is however a way to extract it if it's a part of an 
> aggregate:
>
> -----
> struct S
> {
>     int x = 1;
> }
>
> void main()
> {
>     static assert(S.x.init == 0);
>     static assert(S.init.x == 1);
> }
> -----

I'm though of using if for aggregates, yes. But this doesn't 
handle the case where you set the same value is T.init.


More information about the Digitalmars-d-learn mailing list