From: Aristid Breitkreuz (aribrei_at_[hidden])
Date: 2006-03-26 12:49:18
Am Sonntag, den 12.03.2006, 11:38 +0100 schrieb VÃ¡clav VeselÃ½:
> There is a common need of getting a value from an optional with possibility
> define a default value in case of the optional is uninitialized. I suggest
I recently had this need too. Modern C++ also means clean and
nice-looking code, IMHO. So we need this! I am really posting only to
this relatively old thread because I find the need real and stumbled
upon it very recently.
> optional<int> o;
> int i = o.get(123); // a meber function get with an additional parameter
> int j = from_optional(o, 123); // a free function
> Both alternatives can be implemented simultaneously.
> What do you think about it?
I'd prefer a member function because I also don't like free functions
like "get". I'd rather write x.template foo. A nice method name would be
get_with_default. The alternative get_or_default is hardly readable.
Just with_default would be fine for me, too.
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost