
On Sun, Dec 20, 2009 at 7:30 PM, Larry Evans <cppljevans@suddenlink.net> wrote:
On 12/20/09 20:11, OvermindDL1 wrote:
On Sun, Dec 20, 2009 at 6:48 PM, Arnaud Masserann <arnaud1602@gmail.com> 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%3A... 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.de...
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.