Boost logo

Boost :

Subject: Re: [boost] [variant] Maintainer
From: Larry Evans (cppljevans_at_[hidden])
Date: 2015-07-06 10:10:16


On 06/28/2015 03:38 AM, Vicente J. Botet Escriba wrote:> Le 27/06/15
21:32, Agustín K-ballo Bergé a écrit :
[snip]
> I know that your variant is possibly empty and the C++ standard proposal
> is never-empty, and this makes them different from the user point of
> view. Bjarne S. and Anthony W. are pushing towards a possible empty
> variant, we don't know yet what the std::experimental::variant will be
> and less yet what std::variant will be in C++17.
>
> boost::variant combined with boost::blanc gives this kind of possibly
> empty variant, but IMHO this is a quite different type.
>
> template <class ...Ts>
> using optional_variant = boost::variant<boost::blanc, Ts...>; // +/-
>
> I suggest to name them as
> variant<Ts...> : never-empty
> optionals<Ts...> : possibly empty
>
> I believe that the usage of these classes is quite different.
>
> There is something that I don't like of the possibly empty variant. It
> confounds the empty state and a hidden error state. When we assign a
> type A to variant containing a type B the resulting variant can be
> empty (contains a different type C).

The above example is unclear to me.
Is this what you mean:

  #include <assert.h>
  int main()
  {
    variant<B> vb;
    assert(is_empty(vb));
    assert(!is_error(vb));
    vb = B{};
    assert(!is_empty(vb));
    assert(!is_error(vb));
    vb = A{}
    assert(is_empty(vb));//?
    assert(is_error(vb));//?
    return 0;
  }

where the is_empty and is_error return true if the variant
is empty or in error, respectively.
[snip]

-Larry


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