Boost logo

Boost :

Subject: Re: [boost] [variant2] documentation request
From: Peter Dimov (pdimov_at_[hidden])
Date: 2019-03-05 00:44:20


Niall Douglas wrote:

> You seem very wedded to not breaking out single_buffer_variant and
> double_buffer_variant Peter. You seem keen we should accept your preferred
> mix of when each ought to be employed using your hardcoded logic. Can I
> ask why?

I don't have a good answer to this question. Breaking out into two separate
classes per number of buffers seems sensible and straightforward, and I
don't have any waterproof arguments against it apart from the fact that I
intuitively dislike it.

I prefer having a single variant, named "variant", which is almost always a
drop-in replacement for std::variant, for the fairly obvious reason that (a)
it's easy to recommend to users: just use variant2::variant instead of
std::variant, and your problems will be gone (not valid in all
jurisdictions) and (b) it would be possible, in theory, to one day replace
std::variant with it.

For people who'd rather have single_buffer_variant<T...>, I can provide a
static constexpr member function `bool variant<T...>::is_single_buffered()`,
which they can static_assert. So

template<class... T> using single_buffer_variant =
    mp_if_c<variant<T...>::is_single_buffered(), variant<T...>>;

To those who'd rather have double_buffer_variant, though, I don't have a
good offer.


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