Boost logo

Boost :

Subject: Re: [boost] [variant2] Need rationale for never-empty guarantee
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2019-03-01 13:17:37

pt., 1 mar 2019 o 10:59 Peter Dimov via Boost <boost_at_[hidden]>

> Andrzej Krzemienski wrote:
> > So, does the following recommendation correctly capture the design goals
> > for boost::variant2?
> >
> > If you require the never-empty guarantee (and accept the costs) use
> > boost::variant2.
> >
> > If you do not require the never empty guarantee use std::variant.
> Kind of, but as written this implies that std::variant has no costs, which
> is not true. The checks for valueless do carry a cost. Each visit(), for
> example, starts with `if(valueless) throw`, which is not necessary in
> variant2.

This reply actually addresses my question: visitation on boost::variant2 is
faster than on std::variant because it does not have to account for the
valueless state.


Boost list run by bdawes at, gregod at, cpdaniel at, john at