Boost logo

Boost :

Subject: Re: [boost] compact_optional -- prompting interest
From: Marc Glisse (marc.glisse_at_[hidden])
Date: 2015-09-25 12:06:15


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>>.

> The (single-header) implementation is at:
> https://github.com/akrzemi1/compact_optional
>
> The documentation is at:
> https://github.com/akrzemi1/compact_optional/blob/master/documentation.md
>
> For the motivation and design rationale see this article:
> https://akrzemi1.wordpress.com/2015/07/15/efficient-optional-values/
>
> Any feedback is welcome.

-- 
Marc Glisse

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