Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-02-25 08:00:19


"Sam Partington" <Sam.Partington_at_[hidden]> writes:

> Hi,
>
> While making myself an interim shared_resource class, I found myself reusing
> the shared_ptr safe-bool conversion, and thought that really the idiom ought
> to go into the operators library.
>
> I am unsure about the name, but for now bool_testable seems to match the
> naming style used by the rest of operators, and be reasonably clear about
> its intent. Any suggestions gratefully received
>
> Essentially you supply a operator! and it supplies an unspecified-bool-type
> conversion operator.
>
>
> //Key
> //T: primary operand type
> //t: values of type T
>
>
> // Template Supplied Operations Requirements
> //
> // bool_testable<T> operator unspecified-bool-type() !t
>
> template <class T, class B = ::boost::detail::empty_base> struct
> bool_testable : B
> {
> private:
> void safe_bool_conversion() const { }
> public:
>
> typedef void (bool_testable<T, B>::*unspecified_bool_type)() const;
> operator unspecified_bool_type() const
> {
> return !static_cast<const T&>(*this) ? 0 : &bool_testable<T,
> B>::safe_bool_conversion;
> }
> };
>
> Any problems with this?

None that I can see.

If you want to submit it, make a patch that includes changes to the
tests and the documentation, and post it here *as an attachment* so
that line-wrapping doesn't wreck it ;-)

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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