diff --git a/doc/html/explicit_operator_bool.html b/doc/html/explicit_operator_bool.html new file mode 100644 index 0000000..78a844f --- /dev/null +++ b/doc/html/explicit_operator_bool.html @@ -0,0 +1,115 @@ + + + +BOOST_EXPLICIT_OPERATOR_BOOL and BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+
+
+
+

+BOOST_EXPLICIT_OPERATOR_BOOL and BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL

+

+Andrey Semashev +

+
+
+

+ Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +

+
+
+
+
+
+

Table of Contents

+
+
Overview
+
Examples
+
History
+
+
+
+ +

+ BOOST_EXPLICIT_OPERATOR_BOOL() and BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL() are compatibility helper macros that expand + to an explicit conversion operator to bool. + For compilers not supporting explicit conversion operators introduced in C++11 + the macros expand to a conversion operator that implements the safe + bool idiom. In case if the compiler is not able to handle safe bool + idiom well the macros expand to a regular conversion operator to bool. +

+
+
+ +

+ Both macros are intended to be placed within a user's class definition. The + generated conversion operators will be implemented in terms of operator!() + that should be defined by user in this class. In case of BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL() the generated conversion operator will be + declared constexpr which requires + the corresponding operator!() + to also be constexpr. +

+
template< typename T >
+class my_ptr
+{
+    T* m_p;
+
+public:
+    BOOST_EXPLICIT_OPERATOR_BOOL()
+
+    bool operator!() const
+    {
+        return !m_p;
+    }
+};
+
+

+ Now my_ptr can be used in conditional + expressions, similarly to a regular pointer: +

+
my_ptr< int > p;
+if (p)
+    std::cout << "true" << std::endl;
+
+
+
+ +

+ + boost + 1.55 +

+
  • + The macro was extracted from Boost.Log. +
+
+
+ + + +

Last revised: November 17, 2013 at 17:08:52 GMT

+
+
+ + diff --git a/index.html b/index.html index 41c8c15..98c82f1 100644 --- a/index.html +++ b/index.html @@ -35,8 +35,8 @@ throw_exception
utility
string_ref
- value_init - BOOST_EXPLICIT_OPERATOR_BOOL and BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL
+ value_init
+ BOOST_EXPLICIT_OPERATOR_BOOL and BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL