|
Boost : |
Subject: Re: [boost] safe-bool CRTP class
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2011-06-01 19:30:44
I tried to put together all, that had been said in this thread, and I
prepared boost/utility/safe_bool.hpp (attached). I haven't tested it yet. I
took compiler workarounds from <boost/smart_ptr/detail/operator_bool.hpp>
To view the file online:
http://codepaste.net/c83uuj
The file contains the following safe-bool tools:
- a CRTP class save_bool_convertilbe<Derived,Base=*,Policy=*>, that
implements a conversion operator to a safe-bool in terms of operator! by
default, and can be customized by a policy,
- a safe_bool_t<tag> - a safe-bool type, implemented in terms of
safe_bool_convertible,
- 3 macros for defining operator safe-bool inside a class:
- BOOST_OPERATOR_SAFE_BOOL_TAGGED(tag,expr) - implemented in terms of
safe_bool_t<tag>,
- BOOST_OPERATOR_SAFE_BOOL(expr) - which introduces a tag, and is
implemented in terms of BOOST_OPERATOR_SAFE_BOOL_TAGGED,
- BOOST_EXPLICIT_OPERATOR_BOOL(expr) - which implements an explicit
conversion to bool if available, or falls back to BOOST_OPERATOR_SAFE_BOOL
otherwise.
>From what had been seid in this thread, I understand, that there is interest
in all of the above safe-bool tools.
So, does each of these tools deserve its place in boost? Maybe they need to
be renamed? What did I miss in the implementation?
Regards
Kris
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk