mirror of
https://github.com/boostorg/core.git
synced 2025-12-01 06:39:32 +01:00
Simplify index documentation and add author information
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
[section:explicit_operator_bool Header <boost/core/explicit_operator_bool.hpp>]
|
||||
[section:explicit_operator_bool explicit_operator_bool]
|
||||
|
||||
[/
|
||||
/ Copyright (c) 2013 Andrey Semashev
|
||||
@@ -7,11 +7,27 @@
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[/===============]
|
||||
[section Authors]
|
||||
[/===============]
|
||||
|
||||
* Andrey Semashev
|
||||
|
||||
[endsect]
|
||||
|
||||
[/===============]
|
||||
[section Overview]
|
||||
[/===============]
|
||||
|
||||
`BOOST_EXPLICIT_OPERATOR_BOOL()`, `BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()` 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 [@http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool 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`.
|
||||
Header `<boost/core/explicit_operator_bool.hpp>` provides
|
||||
`BOOST_EXPLICIT_OPERATOR_BOOL()`, `BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()`
|
||||
and `BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()` 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
|
||||
[@http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool 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`.
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -19,27 +35,36 @@
|
||||
[section Examples]
|
||||
[/===============]
|
||||
|
||||
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`.
|
||||
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
|
||||
``
|
||||
template< typename T >
|
||||
class my_ptr
|
||||
{
|
||||
T* m_p;
|
||||
|
||||
public:
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL()
|
||||
|
||||
bool operator!() const
|
||||
{
|
||||
T* m_p;
|
||||
|
||||
public:
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL()
|
||||
|
||||
bool operator!() const
|
||||
{
|
||||
return !m_p;
|
||||
}
|
||||
};
|
||||
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;
|
||||
``
|
||||
my_ptr< int > p;
|
||||
if (p)
|
||||
std::cout << "true" << std::endl;
|
||||
``
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -47,10 +72,12 @@ Now `my_ptr` can be used in conditional expressions, similarly to a regular poin
|
||||
[section History]
|
||||
[/===============]
|
||||
|
||||
[heading boost 1.55]
|
||||
[section boost 1.55]
|
||||
|
||||
* The macro was extracted from Boost.Log.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
Reference in New Issue
Block a user