returning different types via function

Brad Anderson eco at gnuk.net
Tue Nov 19 11:17:49 PST 2013


On Tuesday, 19 November 2013 at 19:15:10 UTC, seany wrote:
> Consider this:
>
> I have a function FUNC, it takes a string array, and does 
> something with it, and retruns the same. Implemented based on a 
> previous thread, here is what i have
>
> string[] FUNC (ref string[] ZZ)
> {
> /*
> do something
> */
> }
>
> and the calling is, ZZ = FUNC(ZZ)
>
> 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 could use std.typecons.Nullable, std.variant.Variant, or 
switch to using exceptions for error reporting.


More information about the Digitalmars-d-learn mailing list