Add generic version of has_nothrow_assign.

Does not require a compiler intrinsic - makes it easier to port to other/unknown compilers going forward as long as they are C++11.
This commit is contained in:
jzmaddock
2015-06-04 18:59:21 +01:00
parent e31d0ab7bd
commit 916adca633
3 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,29 @@
// (C) Copyright John Maddock 2015.
// Use, modification and distribution are subject to 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).
//
// See http://www.boost.org/libs/type_traits for most recent version including documentation.
#ifndef BOOST_TT_DETAIL_DECL_HEADER
#define BOOST_TT_DETAIL_DECL_HEADER
#include <boost/config.hpp>
#include <boost/type_traits/add_rvalue_reference.hpp>
#include <boost/type_traits/add_lvalue_reference.hpp>
#include <boost/type_traits/remove_reference.hpp>
namespace boost { namespace detail{
template <typename T>
typename add_rvalue_reference<T>::type tt_declval() BOOST_NOEXCEPT; // as unevaluated operand
template <typename T>
typename add_lvalue_reference<typename remove_reference<T>::type const>::type tt_decl_const_ref() BOOST_NOEXCEPT; // as unevaluated operand
template <typename T>
typename add_lvalue_reference<typename remove_reference<T>::type>::type tt_decl_ref() BOOST_NOEXCEPT; // as unevaluated operand
}} // namespace boost
#endif // BOOST_TT_DETAIL_DECL_HEADER

View File

@ -14,6 +14,12 @@
#if !defined(BOOST_HAS_NOTHROW_ASSIGN) || defined(BOOST_MSVC) || defined(BOOST_INTEL)
#include <boost/type_traits/has_trivial_assign.hpp>
#if !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
#include <boost/type_traits/detail/decl.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_volatile.hpp>
#include <boost/type_traits/is_reference.hpp>
#endif
#endif
#if defined(__GNUC__) || defined(__SUNPRO_CC)
#include <boost/type_traits/is_const.hpp>
@ -25,10 +31,27 @@
namespace boost {
#if !defined(BOOST_HAS_NOTHROW_ASSIGN) && !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
namespace detail
{
template <class T, bool b1> struct has_nothrow_assign_imp{ static const bool value = false; };
template <class T> struct has_nothrow_assign_imp<T, false>{ static const bool value = noexcept(detail::tt_decl_ref<T>() = detail::tt_decl_const_ref<T>()); };
template <class T, std::size_t N> struct has_nothrow_assign_imp<T[N], false>{ static const bool value = has_nothrow_assign_imp<T, false>::value; };
template <class T> struct has_nothrow_assign_imp<T[], false>{ static const bool value = has_nothrow_assign_imp<T, false>::value; };
}
#endif
template <class T>
struct has_nothrow_assign : public integral_constant<bool,
#ifndef BOOST_HAS_NOTHROW_ASSIGN
#if !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
// Portable C++11 version:
detail::has_nothrow_assign_imp<T, is_const<typename remove_reference<T>::type>::value || is_volatile<typename remove_reference<T>::type>::value || is_reference<T>::value>::value
#else
::boost::has_trivial_assign<T>::value
#endif
#else
BOOST_HAS_NOTHROW_ASSIGN(T)
#endif

View File

@ -29,6 +29,10 @@ rule all-tests {
{
result += [ run $(source) ] ;
}
for local source in has_nothrow_assign_test
{
result += [ run $(source).cpp : : : <define>BOOST_TT_DISABLE_INTRINSICS : $(source)_no_intrinsics ] ;
}
return $(result) ;
}