Is variable void?

bauss jj_1337 at live.dk
Tue Nov 28 05:10:39 UTC 2017


On Monday, 27 November 2017 at 02:12:40 UTC, codephantom wrote:
> On Saturday, 25 November 2017 at 15:34:21 UTC, John Chapman 
> wrote:
>> Is there any way of determining whether a variable has been 
>> initialized or not? For example, if something is declared like 
>> this:
>>
>>   int x = void;
>>
>> can I check if it's void before I use it, say, in a function 
>> it's been passed to?
>
> // ----------------------------------
>
> module test;
>
> import std.stdio;
> import std.typecons; // see: 
> https://dlang.org/phobos/std_typecons.html#Nullable
>
> void main()
> {
>     Nullable!int x;  // requires: import std.typecons
>     assert(x.isNull);
>     writeln("x is ", x);
>
>     x = 1;
>     assert(!x.isNull);
>     writeln("x is ", x);
>
>     x.nullify(); //  	Forces x back to a null state.
>     assert(x.isNull);
>     writeln("x is ", x);
>
> }
> // ----------------------------------

null != void


More information about the Digitalmars-d-learn mailing list