Added a new macro BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT, which implements a noexcept operator. Also added explicit noexcept specification for the constexpr macro.

This commit is contained in:
Andrey Semashev
2014-04-26 15:11:35 +04:00
parent 1c247b7fe7
commit aaadc128f3
4 changed files with 121 additions and 11 deletions
+2 -2
View File
@@ -5,7 +5,7 @@
* http://www.boost.org/LICENSE_1_0.txt)
*/
/*!
* \file explicit_operator_bool_compile.cpp
* \file explicit_operator_bool.cpp
* \author Andrey Semashev
* \date 17.07.2010
*
@@ -13,7 +13,7 @@
* the valid contexts.
*/
#define BOOST_TEST_MODULE explicit_operator_bool_compile
#define BOOST_TEST_MODULE explicit_operator_bool
#include <boost/utility/explicit_operator_bool.hpp>
+89
View File
@@ -0,0 +1,89 @@
/*
* Copyright Andrey Semashev 2007 - 2013.
* 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)
*/
/*!
* \file explicit_operator_bool_noexcept.cpp
* \author Andrey Semashev
* \date 26.04.2014
*
* \brief This test checks that explicit operator bool is noexcept when possible.
*/
#define BOOST_TEST_MODULE explicit_operator_bool_noexcept
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_NOEXCEPT)
#include <boost/detail/lightweight_test.hpp>
#include <boost/utility/explicit_operator_bool.hpp>
namespace {
struct checkable1
{
BOOST_EXPLICIT_OPERATOR_BOOL()
bool operator! () const
{
return false;
}
};
struct checkable2
{
BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()
BOOST_CONSTEXPR bool operator! () const
{
return false;
}
};
struct noexcept_checkable1
{
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
bool operator! () const noexcept
{
return false;
}
};
struct noexcept_checkable2
{
BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()
BOOST_CONSTEXPR bool operator! () const noexcept
{
return false;
}
};
} // namespace
int main(int, char*[])
{
checkable1 val1;
checkable2 val2;
noexcept_checkable1 noexcept_val1;
noexcept_checkable2 noexcept_val2;
BOOST_TEST(!noexcept(static_cast< bool >(val1)));
// constexpr functions are implicitly noexcept
BOOST_TEST(noexcept(static_cast< bool >(val2)));
BOOST_TEST(noexcept(static_cast< bool >(noexcept_val1)));
BOOST_TEST(noexcept(static_cast< bool >(noexcept_val2)));
return boost::report_errors();
}
#else
int main(int, char*[])
{
return 0;
}
#endif