Boost logo

Boost :

Subject: Re: [boost] [variant2] Need rationale for never-empty guarantee
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2019-03-02 20:49:26


AMDG

On 3/2/19 12:47 PM, Mathias Gaunard via Boost wrote:
> On Fri, 1 Mar 2019 at 09:59, Peter Dimov via Boost <boost_at_[hidden]>
> wrote:
>
>>
>> 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.
>>
>
> That is not true.
> A typical implementation would just add an extra value to the switch, there
> is no extra branch.
>

That may be true in theory, but both libc++ and
libstdc++ have if(__v.valueless_by_exception())
scattered everywhere. Not to mention that neither
uses switch.

In Christ,
Steven Watanabe


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