Boost logo

Boost :

Subject: Re: [boost] What about "Maybe" ?
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-12-20 21:55:00


On Sun, Dec 20, 2009 at 7:30 PM, Larry Evans <cppljevans_at_[hidden]> wrote:
> On 12/20/09 20:11, OvermindDL1 wrote:
>>
>> On Sun, Dec 20, 2009 at 6:48 PM, Arnaud Masserann <arnaud1602_at_[hidden]>
>> wrote:
>>>
>>> Hi,
>>>
>>> Is there any interest for a "Maybe" utility class, like the one in
>>> Haskell ?
>>>
>>> For those who don't know about Maybe, here is the Haskell ref :
>>>
>>> http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/Prelude.html#t%3AMaybe
>>> And a code snippet showing its use :
>>> http://pastebin.com/m3a590d6e
>>
>> It looks like Boost.Optional from how it is used in your pastebin
>> snippet.  How is it different from Boost.Optional?
>
> Boost Optional looks like variant with a single component and
> *without* the never empty guarantee:
>
> http://www.boost.org/doc/libs/1_41_0/doc/html/variant/design.html#variant.design.never-empty
>
> Instead of Optional, why not adapt variant to do both what variant does
> and what optional does?  All that would be required is simply allowing
> an empty variant which could always be detected with a test for
> which() == -1.

Actually optional is pretty near to being exactly:
  optional<T> == variant<nil_t,T>
And an easier accessor function of course.


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