1 Mar
2019
1 Mar
'19
1:17 p.m.
pt., 1 mar 2019 o 10:59 Peter Dimov via Boost
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. Regards, Andrzej