Boost logo

Boost :

Subject: Re: [boost] compact_optional -- prompting interest
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2015-09-30 08:14:58


2015-09-27 13:00 GMT+02:00 Matt Calabrese <rivorus_at_[hidden]>:

> On Sat, Sep 26, 2015 at 1:12 PM, Nevin Liber <nevin_at_[hidden]>
> wrote:
> >
> > I'm strongly against the word "optional" appearing the name, for the
> > following reasons:
> >
> >
> > - optional<int> allows me to use every single value that can be stored
> > in an int. This doesn't.
> > - optional<string> allows one to shorten the lifetime of the string it
> > holds. This doesn't.
> > - optional<T> has a nothrow default constructor. This doesn't.
> >
> > At best, it resembles optional only superficially. Please give it a
> > different name.
>
>
> This. However, I do think that there is a place for a separate
> intrusive_optional as well, though the empty value should not be a valid
> value of the type, but rather, just be able to take advantage of its
> storage, and the type should not be constructed while the in the empty
> state. I.E. an optional reference only takes up the size of a pointer
> because it uses the "0" value for empty. Similarly, any type that contains
> a reference (or a pointer that cannot be null) also can take advantage of
> this by way of an intrusive optional. The user would have to provide a
> predicate that operates on the raw storage of the value, and access it in a
> way that is well-formed whether the object is constructed there or not, so
> it is a little bit trickier to specify properly.

I have now implemented this capability in compact_optional. See the related
docs section:
https://github.com/akrzemi1/compact_optional/blob/master/documentation.md#using-pod-storage-for-empty-value

Regards,
&rzej


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