Boost logo

Boost :

Subject: Re: [boost] [optional] std::tr2::optional
From: Robert Ramey (ramey_at_[hidden])
Date: 2011-11-28 23:51:01


Matt Chambers wrote:
> On 11/28/2011 6:05 PM, Dave Abrahams wrote:
>> on Fri Nov 18 2011, paul Fultz<pfultz2-AT-yahoo.com> wrote:
>>>> I provide a list of
>>>> modifications that I could think of. What is your opinion?
>>> This is more of an addition to your list, but I think adding
>>>
>>> the | operator for getting the optional value or a default value
>>> would be nice. For example:
>>>
>>> optional<double> safe_sqrt(double x)
>>> {
>>> if (x< 0) return none;
>>> else return sqrt(x);
>>> }
>>>
>>> double x = safe_sqrt(4) | 0; //x = 4
>>> double y = safe_sqrt(-1) | 0; //y = 0
>>>
>>> I dont know if this is possible for tr2, but would be really nice
>>> addition in the future. Especially, since a lot of times i just
>>> want a default value if the optional value doesn't exist.
>> +1
> +sqrt(4)

-1

since we're all chiming in - I hate ideas like this. Silently giving
a seemingly valid answer to an invalid question just hides a bug
and makes it harder to find. It's a big source of problems with
much component type software.

Robert Ramey

>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk