digitalmars.D.learn - Test if variable has void value
- Andrey (4/10) Aug 22 2018 Tried this:
- Rene Zwanenburg (8/18) Aug 22 2018 You can't. When using a void initializer the actual value is
Hello, How to test if variable has void value?string text = void; if(text == void) { writeln("Is void"); }Tried this:if(is(text == void))but doesn't work.
Aug 22 2018
On Wednesday, 22 August 2018 at 13:50:07 UTC, Andrey wrote:Hello, How to test if variable has void value?You can't. When using a void initializer the actual value is garbage until initialized properly, and that garbage can look like anything including a valid instance. So if the flow of your program can't guarantee that the value has been initialized at a certain point, you'll have to track it yourself some way. Nullable may be of help: https://dlang.org/phobos/std_typecons.html#Nullablestring text = void; if(text == void) { writeln("Is void"); }Tried this:if(is(text == void))but doesn't work.
Aug 22 2018