Re: Return or Not?

From: Alwyn (dt015a1979_at_mac.com.invalid)
Date: 11/19/04


Date: Fri, 19 Nov 2004 07:27:30 +0000

In article
<Pine.LNX.4.60-041.0411190037200.27018@unix44.andrew.cmu.edu>, Arthur
J. O'Dwyer <ajo@nospam.andrew.cmu.edu> wrote:
>
> You're complaining ( ;-) ) that when you try to write a function that
> both returns an error code and returns an integer value, you can't do it
> unless you return a pair of values somewhere. Well, duh. Several of
> the most obvious solutions, in order of elegance (IMVHO), are:

I suppose these situations would be best served by a 'Maybe' data type
as in Haskell:

data Maybe a = Nothing | Just a

partial :: Int -> Maybe Int

which returns 'Just x' if it succeeds and 'Nothing' if it fails.

I suppose it could be approximated, though somewhat clunkily, in C++:

emun Perhaps {Nothing, Just};

template <class T>
struct Maybe
{
   Perhaps c;
   T v;
};

Maybe<int> partial(int n);

then if 'c' in the returned structure has a value of 'Nothing', you
ignore 'v' but can use it if 'c' is 'Just'.

But I still think there's a strong case for using an
'std::domain_error' exception here. Isn't this what it's for, after
all?

Alwyn



Relevant Pages

  • Re: Forestprep Error code 0X8000500C
    ... French Exchange Administrator ... > Entering ScHavePermissionToCreateDSObject ... > Error code 0X8000500C: ... > converted to/from a native DS data type. ...
    (microsoft.public.exchange.setup)
  • Problems building gsoap on AIX 5.1
    ... limited range of data type ... 1254-059 The signal code from the last command is 13. ... 1254-004 The error code from the last command is 1. ...
    (comp.unix.aix)
  • Re: Problems building gsoap on AIX 5.1
    ... limited range of data type ... 1254-059 The signal code from the last command is 13. ... 1254-004 The error code from the last command is 1. ...
    (comp.unix.aix)
  • Forestprep Error code 0X8000500C
    ... I have been trying to install exchange for days. ... Entering ScHavePermissionToCreateDSObject ... Error code 0X8000500C: The data type cannot be ...
    (microsoft.public.exchange.setup)