Boost logo

Boost :

Subject: Re: [boost] [variant2] documentation request
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2019-03-06 15:08:36


sob., 2 mar 2019 o 13:18 Andrzej Krzemienski <akrzemi1_at_[hidden]>
napisał(a):

> Hi Peter,
> Given that the never-empty guarantee appears to be at the heart of the
> motivation for boost::variant2, I would suggest to:
> 1. put in the documentation some motivation behind pursuing the
> never-empty guarantee.
> 2. Make it clear that never-empty guarantee is not a strong
> exception-safety guarantee.
> 3. Describe the algorithm for achieving the guarantee.
>

Somewhat related to that. When I try to study the documentation to see what
the assignment guarantees, I get this:

constexpr variant& operator=( const variant& r )
  noexcept( mp_all<std::is_nothrow_copy_constructible<T>...,
    std::is_nothrow_copy_assignable<T>...>::value );

   -

   Let j be r.index().
   Effects:
   -

      If index() == j, assigns the value contained in r to the value
      contained in *this.
      -

      Otherwise, equivalent to emplace<j>(get<j>(r)).

I am interested in the latter ("Otherwise") case, so, going to emplace:

template<size_t I, class... A>
  constexpr variant_alternative_t<I, variant<T...>>&
    emplace( A&&... a );

   - Requires:

   I < sizeof(T…).
   Effects:

   Destroys the currently contained value, then initializes a new contained
   value as if using the expression Ti(std::forward<A>(a)…).

This doesn't mention any double buffering. No tricks, no "monostate". It
reads as if the variant is left with no contained object whatsoever.

Regards,
Andrzej


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