$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] [optional] Safe optional
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2014-11-19 17:12:53
Le 19/11/14 22:36, Vladimir Batov a écrit :
>
> On 11/20/2014 08:22 AM, Vladimir Batov wrote:
>>
>> On 11/19/2014 07:37 PM, Andrzej Krzemienski wrote:
>>
>>> ...
>>> optional<double> Aircraft::weight()
>>> {
>>> if (Impl* impl = get_impl())
>>> return impl->compute_weight();
>>> else
>>> return none;
>>> }
>>>
>>> double Aircraft::max_weight()
>>> {
>>> return 10000.0;
>>> }
>>>
>>> bool too_heavy(Aircraft& ac)
>>> {
>>> return ac.weight() > ac.max_weight();
>>> // in "safe" optional compiler would spot the bug
>>> }
>>
>> There is no bug here! Not from the human perspectives. You are
>> comparing two extremely closely related types! As long as we agree on
>> how "none" is treated, then all kosher. We do compare "ints" with
>> "doubles", don't we? No "safety" concerns.
>
> On the second thought I might probably agree that op<() might be
> questionable... Can we address that differently then? Say,
>
> bool operator<(T const&, optional<T> const&) { BOOST_STATIC_ASSERT(); }
>
>
I don't think this is a solution. User defining its own function
void f(optional<T>, optional<T>);
would need to add the following?
void f(T, optional<T>) { BOOST_STATIC_ASSERT(); }
void f(optional<T>, T) { BOOST_STATIC_ASSERT(); }
What if there are 3 optional parameters? We can not say to the user that
they need to program this way.
Vicente