Boost logo

Boost :

Subject: Re: [boost] compact_optional -- prompting interest
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2015-09-25 12:19:59


On 25.09.2015 19:06, Marc Glisse wrote:
> On Fri, 25 Sep 2015, Andrzej Krzemienski wrote:
>
>> Hi Everyone,
>> I would like to inquire if there would be an interest in Boost in another
>> library for storing optional objects, but working under different design
>> goals.
>>
>> Compact optional T has (or can have) the same sizeof as T. It uses one
>> indicated value of T to represent the "empty" (or "singular") value. You
>> can declare it like this:
>>
>> compact_optional<evp_int<int, -1>> oi;
>>
>> This reads: we have an optional int, with type int inside, where -1
>> represents the empty value. It can never have a genuine (non-empty value
>> -1). This can be used, for instance, to wrap the std::string::npos into:
>>
>> compact_optional<evp_int<string::size_type, string::npos>>
>>
>> With the same memory layout as std::string::size_type, but with the
>> special
>> syntax for managing the singular value.
>>
>> It is not meant to be an alternative to Boost.Optional: it targets a
>> different application space.
>
> In my opinion, this is not an alternative to Boost.Optional because it
> should be part of Boost.Optional. For the interface, you could either
> add a second template parameter to boost::optional specifying the
> policy, or specialize boost::optional<magic_name<T>>.

I'm not opposed to making it part of Boost.Optional library, but not as
a specialization of optional<>. The proposed class is very different
from optional<>.


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