returning different types via function

Dicebot public at dicebot.lv
Tue Nov 19 11:20:27 PST 2013


On Tuesday, 19 November 2013 at 19:15:10 UTC, seany wrote:
> Now, I want, should the function be not successful in doing 
> what it intends to do, to return a boolean value of false, to 
> ZZ, un fortunately ZZ is already a string[] (so i want liek a C 
> style fopen -like function, that , although called with the 
> syntax: file *f = fopen(balh, "bla"); can set f to be false)
>
> Is this possible in D?

You can wrap return type in Variant 
(http://dlang.org/phobos/std_variant.html) but it is inefficient, 
weakens typing and considered a bad approach in natively compiled 
language. Better approach probably is to use null as an indicator 
(as string[] is a reference type) or throw an exception.


More information about the Digitalmars-d-learn mailing list