forked from boostorg/type_traits
Add is_assignable.
Update has_nothrow_assign to make use of it.
This commit is contained in:
1 parent
34805a673f
commit
acf6e41edb
6 files changed
+275
-12
No files matched your search
@@ -41,6 +41,7 @@
|
||||
#include "boost/type_traits/has_trivial_move_constructor.hpp"
|
||||
#include "boost/type_traits/has_virtual_destructor.hpp"
|
||||
#include "boost/type_traits/is_abstract.hpp"
|
||||
#include "boost/type_traits/is_assignable.hpp"
|
||||
#include "boost/type_traits/is_arithmetic.hpp"
|
||||
#include "boost/type_traits/is_array.hpp"
|
||||
#include "boost/type_traits/is_base_and_derived.hpp"
|
||||
@@ -52,6 +53,7 @@
|
||||
#include "boost/type_traits/is_convertible.hpp"
|
||||
#include "boost/type_traits/is_copy_constructible.hpp"
|
||||
#include "boost/type_traits/is_copy_assignable.hpp"
|
||||
#include "boost/type_traits/is_default_constructible.hpp"
|
||||
#include "boost/type_traits/is_empty.hpp"
|
||||
#include "boost/type_traits/is_enum.hpp"
|
||||
#include "boost/type_traits/is_float.hpp"
|
||||
|
||||
@@ -19,11 +19,14 @@
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
#include <boost/type_traits/is_volatile.hpp>
|
||||
#include <boost/type_traits/is_reference.hpp>
|
||||
#include <boost/type_traits/is_assignable.hpp>
|
||||
#include <boost/type_traits/add_reference.hpp>
|
||||
#endif
|
||||
#endif
|
||||
#if defined(__GNUC__) || defined(__SUNPRO_CC)
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
#include <boost/type_traits/is_volatile.hpp>
|
||||
#include <boost/type_traits/is_assignable.hpp>
|
||||
#ifdef BOOST_INTEL
|
||||
#include <boost/type_traits/is_pod.hpp>
|
||||
#endif
|
||||
@@ -35,28 +38,32 @@ namespace boost {
|
||||
|
||||
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; };
|
||||
template <class T, bool b1, bool b2> struct has_nothrow_assign_imp{ static const bool value = false; };
|
||||
template <class T> struct has_nothrow_assign_imp<T, false, true>{ 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, true>{ static const bool value = has_nothrow_assign_imp<T, false, true>::value; };
|
||||
template <class T> struct has_nothrow_assign_imp<T[], false, true>{ static const bool value = has_nothrow_assign_imp<T, false, true>::value; };
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
struct has_nothrow_assign : public integral_constant<bool,
|
||||
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
|
||||
// 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),
|
||||
is_assignable<typename add_reference<T>::type, typename add_reference<const T>::type>::value
|
||||
>::value
|
||||
#else
|
||||
::boost::has_trivial_assign<T>::value
|
||||
::boost::has_trivial_assign<T>::value
|
||||
#endif
|
||||
#else
|
||||
BOOST_HAS_NOTHROW_ASSIGN(T)
|
||||
BOOST_HAS_NOTHROW_ASSIGN(T)
|
||||
#endif
|
||||
>{};
|
||||
> {};
|
||||
|
||||
template <class T, std::size_t N> struct has_nothrow_assign <T[N]> : public has_nothrow_assign<T> {};
|
||||
template <> struct has_nothrow_assign<void> : public false_type{};
|
||||
#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
|
||||
template <> struct has_nothrow_assign<void const> : public false_type{};
|
||||
|
||||
@@ -245,7 +245,7 @@
|
||||
# define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T) BOOST_INTEL_TT_OPTS)
|
||||
# define BOOST_HAS_NOTHROW_CONSTRUCTOR(T) (__has_nothrow_constructor(T) && is_default_constructible<T>::value BOOST_INTEL_TT_OPTS)
|
||||
# define BOOST_HAS_NOTHROW_COPY(T) ((__has_nothrow_copy(T) BOOST_INTEL_TT_OPTS) && !is_volatile<T>::value && !is_reference<T>::value)
|
||||
# define BOOST_HAS_NOTHROW_ASSIGN(T) ((__has_nothrow_assign(T) BOOST_INTEL_TT_OPTS) && !is_volatile<T>::value && !is_const<T>::value)
|
||||
# define BOOST_HAS_NOTHROW_ASSIGN(T) ((__has_nothrow_assign(T) BOOST_INTEL_TT_OPTS) && !is_volatile<T>::value && !is_const<T>::value && is_assignable<T&, const T&>::value)
|
||||
# define BOOST_HAS_VIRTUAL_DESTRUCTOR(T) __has_virtual_destructor(T)
|
||||
|
||||
# define BOOST_IS_ABSTRACT(T) __is_abstract(T)
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
|
||||
// (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_IS_ASSIGNABLE_HPP_INCLUDED
|
||||
#define BOOST_TT_IS_ASSIGNABLE_HPP_INCLUDED
|
||||
|
||||
#include <boost/type_traits/integral_constant.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
namespace boost{
|
||||
|
||||
template <class T, class U = T> struct is_assignable;
|
||||
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800)
|
||||
|
||||
#include <boost/type_traits/detail/yes_no_type.hpp>
|
||||
#include <boost/type_traits/detail/decl.hpp>
|
||||
|
||||
namespace boost{
|
||||
|
||||
namespace detail{
|
||||
|
||||
struct is_assignable_imp
|
||||
{
|
||||
template<typename T, typename U, typename = decltype(tt_declval<T>() = tt_declval<U>())>
|
||||
static boost::type_traits::yes_type test(int);
|
||||
|
||||
template<typename, typename>
|
||||
static boost::type_traits::no_type test(...);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <class T, class U> struct is_assignable : public integral_constant<bool, sizeof(detail::is_assignable_imp::test<T, U>(0)) == sizeof(boost::type_traits::yes_type)>{};
|
||||
template <class T, std::size_t N, class U> struct is_assignable<T[N], U> : public is_assignable<T, U>{};
|
||||
template <class T, std::size_t N, class U> struct is_assignable<T(&)[N], U> : public is_assignable<T&, U>{};
|
||||
template <class T, class U> struct is_assignable<T[], U> : public is_assignable<T, U>{};
|
||||
template <class T, class U> struct is_assignable<T(&)[], U> : public is_assignable<T&, U>{};
|
||||
template <class U> struct is_assignable<void, U> : public integral_constant<bool, false>{};
|
||||
template <class U> struct is_assignable<void const, U> : public integral_constant<bool, false>{};
|
||||
template <class U> struct is_assignable<void volatile, U> : public integral_constant<bool, false>{};
|
||||
template <class U> struct is_assignable<void const volatile, U> : public integral_constant<bool, false>{};
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/type_traits/has_trivial_assign.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
|
||||
namespace boost{
|
||||
|
||||
// We don't know how to implement this:
|
||||
template <class T, class U> struct is_assignable : public integral_constant<bool, false>{};
|
||||
template <class T, class U> struct is_assignable<T&, U> : public integral_constant<bool, is_pod<T>::value && is_pod<typename remove_reference<U>::type>::value>{};
|
||||
template <class T, class U> struct is_assignable<const T&, U> : public integral_constant<bool, false>{};
|
||||
template <class U> struct is_assignable<void, U> : public integral_constant<bool, false>{};
|
||||
template <class U> struct is_assignable<void const, U> : public integral_constant<bool, false>{};
|
||||
template <class U> struct is_assignable<void volatile, U> : public integral_constant<bool, false>{};
|
||||
template <class U> struct is_assignable<void const volatile, U> : public integral_constant<bool, false>{};
|
||||
/*
|
||||
template <> struct is_assignable<void, void> : public integral_constant<bool, false>{};
|
||||
template <> struct is_assignable<void const, void const> : public integral_constant<bool, false>{};
|
||||
template <> struct is_assignable<void volatile, void volatile> : public integral_constant<bool, false>{};
|
||||
template <> struct is_assignable<void const volatile, void const volatile> : public integral_constant<bool, false>{};
|
||||
*/
|
||||
#endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_TT_IS_ASSIGNABLE_HPP_INCLUDED
|
||||
Reference in new issue
Block a user