
Date: Wed, 28 Aug 2013 12:14:51 +0400 From: andrey.semashev@gmail.com
I'd like to extract some general-purpose components from Boost.Log to Boost.Utility so that they could be used in other libraries and user's code that is not related to logging. The components are mostly standalone already and are not tied to Boost.Log specifics.
1. BOOST_EXPLICIT_OPERATOR_BOOL() macro for defining explicit operator bool() for a class. For C++03 compilers the macro implements safe bool idiom or just a regular operator bool(), if the compiler doesn't handle safe bool well. The generated operator is implemented in terms of operator!(), which should be defined for the class:
template< typename T> class my_ptr { T* m_p;
public: BOOST_EXPLICIT_OPERATOR_BOOL() bool operator! () const { return !m_p; } };
Various different implementations of explicit/safe bool operator are present in different libraries. It would be good to unify them.
Implementation: boost/log/utility/explicit_operator_bool.hpp [TRUNCATE]
I could add this to my touch-ups of Boost.Rational, but I see two minor problems using it: a. It isn't marked "constexpr." I can add that myself before using "BOOST_EXPLICIT_OPERATOR_BOOL" in "boost/rational.hpp," but what happens if someone corrects it in "explicit_operator_bool.hpp"? Will the (temporary) double definition cause an error? b. Its #included Boost.Log-specific configuration header file flags an error if RTTI isn't active. And it's unconditional, which would make Boost.Rational unusable for small environments that skip RTTI. But I don't know if Boost.Rational is already unsuitable for such systems, since it uses exceptions and such. Maybe I'll just make a custom solution for now.... Daryle W.