|
Boost : |
Subject: Re: [boost] [optional] Safe optional
From: Olaf van der Spek (ml_at_[hidden])
Date: 2014-11-20 17:42:45
On Thu, Nov 20, 2014 at 11:49 AM, Andrzej Krzemienski
<akrzemi1_at_[hidden]> wrote:
>> http://www.boost.org/doc/libs/1_57_0/libs/optional/doc/html/boost_optional/quick_start/storage_in_containers.html
>>
>> By containers you specifically mean map, right?
>> Unordered map for example would not require operator<
>>
>> Containers (maps) always come up as the primary rationale for operator<
>> However, the user could also define his own comparison function for
>> this purpose.
>>
>> Perhaps other use cases of operator< could be presented.
>>
>
> I was trying to illustrate how it is useful to think of optional<T> as
> extending the domain of T (rather than representing "either T or error").
> Not to illustrate the storage in containers.
Optional really is either T or none (no value) isn't it?
What do other languages do? Do they have something like optional? How
are comparisons defined?
> The user-provided int can be any value of int plus the situation where user
> decides not to type any input. the latter is a valid and useful
> information. E.g. when an int represents some threshold, having boost::none
> means "go with no threshold". boost::none is just a value. this in turn
> implies the implicit conversions:
>
> optional<int>() != 2;
>
> The above is logical and useful, even outside of the containers.
Right, but if there's no threshold, would 2 be above or below this
non-existant threshold?
And if none means unknown or not yet available, what does the answer become?
>> But is it what people have problems with isn't it?
>>
>
> Some people are surprised by the implicit conversion, because they expect
> it would not be there. the have this expectation because they do not
> understand the conceptual model behind optional<T>.
>
> True, they have a problem. I claim, the root of the problem is not
> understanding the tool they have.
Should the tool match common user expectations (including novice
users) or do you expect users to bend their models to the tools? ;)
-- Olaf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk