Boost logo

Boost :

Subject: Re: [boost] compact_optional -- prompting interest
From: Nevin Liber (nevin_at_[hidden])
Date: 2015-09-27 18:48:13


On 27 September 2015 at 17:20, Matt Calabrese <rivorus_at_[hidden]> wrote:

> On Sun, Sep 27, 2015 at 3:08No, in other words you cannot construct a
> card with a not-a-card state.
>

Except that every function in its implementation may assume the card is
*never* in the not-a-card state.

For instance, one could add ASSERT(1 <= cardIndex && cardIndex <= 52) all
over the place, including in the beginning of the body of the destructor,
and not expect anything to break.

> Internally there is obviously room in storage to represent it, since we are
> only using 52 values on the possible set of values that can exist for a
> byte, but with just this abstraction there is no valid way to get there.
>

It isn't just about room. The class has to know about it so that it can,
at a minimum, weaken its invariants to support it. And if you have to do
that, I don't see any need for some generic class to wrap it.

-- 
 Nevin ":-)" Liber  <mailto:nevin_at_[hidden]>  (847) 691-1404

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