Boost logo

Boost :

Subject: Re: [boost] safe-bool CRTP class
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-05-27 12:28:55


Krzysztof Czainski wrote:
>
> Vladimir Batov prepared a safebool helper class as part of his
> Pimpl library.
[snip]
> In the review of Pimpl Joej Falcou suggested to make safebool a
> CRTP base class.
>
> I had prepared such a class some time ego, and I've been using
> it for a while now. Is there interest in adding it to boost?
> Perhaps as part of the operators library?

+1

> template < class Derived, class Base = empty_t >

I like that you're allowing for a base class.

> class boolable : public Base

Why not s/boolable/safe_bool/?

> {
> void unspecified_bool_t_f() {}
>
> typedef void (boolable::*unspecified_bool_t)();
>
> public:
>
> operator unspecified_bool_t() const
> {
> return ! static_cast<Derived const&>( *this ) ? 0 :
> &boolable::unspecified_bool_t_f;

This doesn't support types that have no other reason to define operator !() or that have a ready-made is_valid() sort of function. IOW, the "valid" or "invalid" function on which to rely should be configurable. (It should be possible to provide either one.)

I understand that you're assuming that if one can write if (x), one might assume that if (!x) should also work, but that should work anyway with the safe-bool operator, right?

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP http://www.sig.com




IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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