Boost logo

Boost :

Subject: Re: [boost] [outcome] To variant, or not to variant?
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2017-06-01 18:47:12


On 01/06/2017 18:47, Peter Dimov via Boost wrote:
> Robert Ramey wrote:
>
>> Right - so isn't variant the place to "fix" it? if outcome, expected,
>> optional ... need a never-empty guarantee, should variant (std, boost,
>> whatever) have that guarantee as well? Shouldn't these discussions
>> take place in the context of variant?
>
> There were prolonged and furious debates on this topic while
> std::variant was getting standardized, and the side who wanted a
> never-valueless variant (that would be me) lost.

I haven't met a soul from WG21 who thinks variant should go empty as
frequently as the C++ 17 standard says it should.

I think it's acceptable if the user supplies types more than one of
which has a throwing move constructor. Otherwise you'd need to double
storage used.

If one or fewer types supplied to variant have throwing move
constructors, then a hard never-empty guarantee needs to be made, and
with some static flag or observer to let you know. Or just don't
implement .valueless_by_exception() :)

Niall

-- 
ned Productions Limited Consulting
http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/

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