Boost logo

Boost :

Subject: Re: [boost] [variant2] Andrzej's review -- documentation
From: Peter Dimov (pdimov_at_[hidden])
Date: 2019-04-07 12:09:45


Andrzej Krzemienski wrote:
> Specification of function `emplace<I>()`:
> It says:
>
> >
> > On exception: If the list of alternatives contains monostate, the
> > contained value is either unchanged, or monostate{};
> >
>
> In what situation on exception is the contained value left unchanged? This
> question applies to the next bullet as well.

I prefer to leave this unspecified.

> swap():
> What does it throw and when? Other functions specify it but this one does
> not.

swap() is defined as equivalent to code sequences (depending on whether the
indices match), so the effects, including exceptions thrown, are the effects
of those code sequences.

> get<I>():
> Specification says,
>
> >
> > If v.index() is I, returns a reference to the object stored in the
> > variant. Otherwise, throws bad_variant_access.
> >
>
> This means that if I provide an index that is far greater than
> `sizeof...(T)`, the program should compile fine and throw an exception at
> run-time.

Not quite, because get<> returns variant_alternative_t<I, variant<T...>>,
and this expression causes a substitution failure when I >= sizeof...(T). So
there's an implicit "Constraints: I < sizeof...(T)". Maybe it needs to be
made explicit.

> According to the specs, the following should work:
>
> ```
> void f() {}
> variant2::visit(f);
> ```
> which is not incorrect, but strange.

This is also the case with std::variant if I'm not mistaken? The purpose is
probably to support variant<> parameter packs in a consistent way, even when
the pack is empty.


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