Fix MSVC11 test (refs #8189).

Added C++11 noexcept implementation of is_nothrow_move_constructible and is_nothrow_move_assignable traits and changed C++03 version to to work close to C++11 (refs #8189).

[SVN r83245]
This commit is contained in:
Antony Polukhin
2013-03-02 16:15:30 +00:00
parent 703afdc9c1
commit 40d87a0683
5 changed files with 81 additions and 32 deletions

View File

@@ -110,7 +110,7 @@
# if defined(_MSC_VER) && (_MSC_VER >= 1700)
# define BOOST_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T) (__has_trivial_move_constructor(T) || ( ::boost::is_pod<T>::value && !::boost::is_volatile<T>::value))
# define BOOST_HAS_TRIVIAL_MOVE_ASSIGN(T) (__has_trivial_move_assign(T) || ( ::boost::is_pod<T>::value && !::boost::is_volatile<T>::value))
# define BOOST_HAS_TRIVIAL_MOVE_ASSIGN(T) (__has_trivial_move_assign(T) || ( ::boost::is_pod<T>::value && ! ::boost::is_const<T>::value && !::boost::is_volatile<T>::value))
# endif
# define BOOST_HAS_TYPE_TRAITS_INTRINSICS

View File

@@ -14,6 +14,12 @@
#include <boost/config.hpp>
#include <boost/type_traits/has_trivial_move_assign.hpp>
#include <boost/type_traits/has_nothrow_assign.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/detail/ice_and.hpp>
#include <boost/type_traits/detail/ice_or.hpp>
#include <boost/type_traits/detail/ice_not.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/utility/declval.hpp>
// should be the last #include
@@ -23,24 +29,44 @@ namespace boost {
namespace detail{
#ifndef BOOST_NO_CXX11_NOEXCEPT
template <class T, class Enable = void>
struct false_or_cpp11_noexcept_move_assignable: public ::boost::false_type {};
template <class T>
struct false_or_cpp11_noexcept_move_assignable <
T,
typename ::boost::enable_if_c<sizeof(T) && BOOST_NOEXCEPT_EXPR(::boost::declval<T&>() = ::boost::declval<T>())>::type
> : public ::boost::integral_constant<bool, BOOST_NOEXCEPT_EXPR(::boost::declval<T&>() = ::boost::declval<T>())>
{};
template <class T>
struct is_nothrow_move_assignable_imp{
#if 0
// #ifndef BOOST_NO_CXX11_NOEXCEPT
BOOST_STATIC_CONSTANT(bool, value = (
::boost::type_traits::ice_or<
::boost::has_trivial_move_assign<T>::value,
BOOST_NOEXCEPT_EXPR(::boost::declval<T>() = ::boost::declval<T>())
BOOST_STATIC_CONSTANT(bool, value = (
::boost::type_traits::ice_and<
::boost::type_traits::ice_not< ::boost::is_volatile<T>::value >::value,
::boost::type_traits::ice_not< ::boost::is_reference<T>::value >::value,
::boost::detail::false_or_cpp11_noexcept_move_assignable<T>::value
>::value));
#else
BOOST_STATIC_CONSTANT(bool, value = (
::boost::type_traits::ice_or<
::boost::has_trivial_move_assign<T>::value,
::boost::has_nothrow_assign<T>::value
>::value));
#endif
};
#else
template <class T>
struct is_nothrow_move_assignable_imp{
BOOST_STATIC_CONSTANT(bool, value = (
::boost::type_traits::ice_and<
::boost::type_traits::ice_or<
::boost::has_trivial_move_assign<T>::value,
::boost::has_nothrow_assign<T>::value
>::value,
::boost::type_traits::ice_not< ::boost::is_array<T>::value >::value
>::value));
};
#endif
}
BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_nothrow_move_assignable,T,::boost::detail::is_nothrow_move_assignable_imp<T>::value)

View File

@@ -14,7 +14,10 @@
#include <boost/config.hpp>
#include <boost/type_traits/has_trivial_move_constructor.hpp>
#include <boost/type_traits/has_nothrow_copy.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/detail/ice_or.hpp>
#include <boost/type_traits/detail/ice_and.hpp>
#include <boost/utility/declval.hpp>
// should be the last #include
@@ -24,24 +27,44 @@ namespace boost {
namespace detail{
#ifndef BOOST_NO_CXX11_NOEXCEPT
template <class T, class Enable = void>
struct false_or_cpp11_noexcept_move_constructible: public ::boost::false_type {};
template <class T>
struct false_or_cpp11_noexcept_move_constructible <
T,
typename ::boost::enable_if_c<sizeof(T) && BOOST_NOEXCEPT_EXPR(T(::boost::declval<T>()))>::type
> : public ::boost::integral_constant<bool, BOOST_NOEXCEPT_EXPR(T(::boost::declval<T>()))>
{};
template <class T>
struct is_nothrow_move_constructible_imp{
#if 0
//#ifndef BOOST_NO_CXX11_NOEXCEPT
BOOST_STATIC_CONSTANT(bool, value =
(::boost::type_traits::ice_or<
::boost::has_trivial_move_constructor<T>::value,
BOOST_NOEXCEPT_EXPR(T(::boost::declval<T>()))
(::boost::type_traits::ice_and<
::boost::type_traits::ice_not< ::boost::is_volatile<T>::value >::value,
::boost::type_traits::ice_not< ::boost::is_reference<T>::value >::value,
::boost::detail::false_or_cpp11_noexcept_move_constructible<T>::value
>::value));
#else
BOOST_STATIC_CONSTANT(bool, value =
(::boost::type_traits::ice_or<
::boost::has_trivial_move_constructor<T>::value,
::boost::has_nothrow_copy<T>::value
>::value));
#endif
};
#else
template <class T>
struct is_nothrow_move_constructible_imp{
BOOST_STATIC_CONSTANT(bool, value =(
::boost::type_traits::ice_and<
::boost::type_traits::ice_or<
::boost::has_trivial_move_constructor<T>::value,
::boost::has_nothrow_copy<T>::value
>::value,
::boost::type_traits::ice_not< ::boost::is_array<T>::value >::value
>::value));
};
#endif
}
BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_nothrow_move_constructible,T,::boost::detail::is_nothrow_move_constructible_imp<T>::value)

View File

@@ -189,9 +189,9 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_assignable<int&>::value, fal
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_assignable<int&&>::value, false);
#endif
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_assignable<const int&>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_assignable<int[2]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_assignable<int[3][2]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_assignable<int[2][4][5][6][3]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_assignable<int[2]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_assignable<int[3][2]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_assignable<int[2][4][5][6][3]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_assignable<UDT>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_assignable<empty_UDT>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_assignable<void>::value, false);

View File

@@ -186,9 +186,9 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_constructible<int&>::value,
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_constructible<int&&>::value, false);
#endif
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_constructible<const int&>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_constructible<int[2]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_constructible<int[3][2]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_constructible<int[2][4][5][6][3]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_constructible<int[2]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_constructible<int[3][2]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_constructible<int[2][4][5][6][3]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_constructible<UDT>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_nothrow_move_constructible<void>::value, false);
// cases we would like to succeed but can't implement in the language: