Fix has_trivial* traits and improve their tests.

This commit is contained in:
jzmaddock committed 2015-06-11 10:00:09 +01:00
1 parent 24548d6158
commit 2d71379074
12 files changed
+194 -25

No files matched your search

@@ -13,29 +13,33 @@
#include <boost/type_traits/intrinsics.hpp>
#include <boost/type_traits/integral_constant.hpp>
#if !defined(BOOST_HAS_TRIVIAL_ASSIGN) || defined(BOOST_MSVC) || defined(__GNUC__) || defined(BOOST_INTEL) || defined(__SUNPRO_CC)
#if !defined(BOOST_HAS_TRIVIAL_ASSIGN) || defined(BOOST_MSVC) || defined(__GNUC__) || defined(BOOST_INTEL) || defined(__SUNPRO_CC) || defined(__clang)
#include <boost/type_traits/is_pod.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_volatile.hpp>
#include <boost/type_traits/is_assignable.hpp>
#endif
namespace boost {
template <typename T>
struct has_trivial_assign : public integral_constant<bool,
template <typename T>
struct has_trivial_assign : public integral_constant < bool,
#ifdef BOOST_HAS_TRIVIAL_ASSIGN
BOOST_HAS_TRIVIAL_ASSIGN(T)
BOOST_HAS_TRIVIAL_ASSIGN(T)
#else
::boost::is_pod<T>::value && !::boost::is_const<T>::value && !::boost::is_volatile<T>::value
::boost::is_pod<T>::value && !::boost::is_const<T>::value && !::boost::is_volatile<T>::value
#endif
> {};
template<> struct has_trivial_assign<void> : public false_type{};
template<> struct has_trivial_assign<void> : public false_type{};
#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
template<> struct has_trivial_assign<void const> : public false_type{};
template<> struct has_trivial_assign<void const volatile> : public false_type{};
template<> struct has_trivial_assign<void volatile> : public false_type{};
template<> struct has_trivial_assign<void const> : public false_type{};
template<> struct has_trivial_assign<void const volatile> : public false_type{};
template<> struct has_trivial_assign<void volatile> : public false_type{};
#endif
// Arrays are not explictly assignable:
template <typename T, std::size_t N> struct has_trivial_assign<T[N]> : public false_type{};
template <typename T> struct has_trivial_assign<T[]> : public false_type{};
} // namespace boost
@@ -11,6 +11,7 @@
#include <boost/type_traits/intrinsics.hpp>
#include <boost/type_traits/is_pod.hpp>
#include <boost/type_traits/is_default_constructible.hpp>
#ifdef BOOST_HAS_TRIVIAL_CONSTRUCTOR
#ifdef BOOST_HAS_SGI_TYPE_TRAITS
@@ -27,7 +28,7 @@ namespace boost {
template <typename T> struct has_trivial_constructor
#ifdef BOOST_HAS_TRIVIAL_CONSTRUCTOR
: public integral_constant <bool, (::boost::is_pod<T>::value || BOOST_HAS_TRIVIAL_CONSTRUCTOR(T))>{};
: public integral_constant <bool, ((::boost::is_pod<T>::value || BOOST_HAS_TRIVIAL_CONSTRUCTOR(T)) && is_default_constructible<T>::value)>{};
#else
: public integral_constant <bool, ::boost::is_pod<T>::value>{};
#endif
@@ -21,6 +21,10 @@
#include <boost/type_traits/is_same.hpp>
#endif
#if defined(__GNUC__) || defined(__clang) || defined(__SUNPRO_CC)
#include <boost/type_traits/is_destructible.hpp>
#endif
namespace boost {
template <typename T> struct has_trivial_destructor : public integral_constant<bool, BOOST_HAS_TRIVIAL_DESTRUCTOR(T)>{};
@@ -23,6 +23,10 @@
#endif
#endif
#if defined(__GNUC__) || defined(__clang)
#include <boost/type_traits/is_assignable.hpp>
#endif
namespace boost {
template <typename T>
+13 -8
View File
@@ -174,10 +174,10 @@
# define BOOST_HAS_TRIVIAL_COPY(T) (__has_trivial_copy(T) && !is_reference<T>::value)
# endif
# if __has_feature(has_trivial_assign)
# define BOOST_HAS_TRIVIAL_ASSIGN(T) (__has_trivial_assign(T) && !is_volatile<T>::value)
# define BOOST_HAS_TRIVIAL_ASSIGN(T) (__has_trivial_assign(T) && !is_volatile<T>::value && is_assignable<T&, const T&>::value)
# endif
# if __has_feature(has_trivial_destructor)
# define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T)
# define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T) && is_destructible<T>::value)
# endif
# if __has_feature(has_nothrow_constructor)
# define BOOST_HAS_NOTHROW_CONSTRUCTOR(T) (__has_nothrow_constructor(T) && is_default_constructible<T>::value)
@@ -210,10 +210,10 @@
# define BOOST_IS_POLYMORPHIC(T) __is_polymorphic(T)
# endif
# if __has_feature(has_trivial_move_constructor)
# define BOOST_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T) __has_trivial_move_constructor(T)
# define BOOST_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T) (__has_trivial_move_constructor(T) && is_constructible<T, T&&>::value)
# endif
# if __has_feature(has_trivial_move_assign)
# define BOOST_HAS_TRIVIAL_MOVE_ASSIGN(T) __has_trivial_move_assign(T)
# define BOOST_HAS_TRIVIAL_MOVE_ASSIGN(T) (__has_trivial_move_assign(T) && is_assignable<T&, T&&>::value)
# endif
# define BOOST_ALIGNMENT_OF(T) __alignof(T)
# if __has_feature(is_final)
@@ -241,8 +241,8 @@
# define BOOST_IS_EMPTY(T) __is_empty(T)
# define BOOST_HAS_TRIVIAL_CONSTRUCTOR(T) ((__has_trivial_constructor(T) BOOST_INTEL_TT_OPTS) && ! ::boost::is_volatile<T>::value)
# define BOOST_HAS_TRIVIAL_COPY(T) ((__has_trivial_copy(T) BOOST_INTEL_TT_OPTS) && !is_reference<T>::value)
# define BOOST_HAS_TRIVIAL_ASSIGN(T) ((__has_trivial_assign(T) BOOST_INTEL_TT_OPTS) && ! ::boost::is_volatile<T>::value && ! ::boost::is_const<T>::value)
# define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T) BOOST_INTEL_TT_OPTS)
# define BOOST_HAS_TRIVIAL_ASSIGN(T) ((__has_trivial_assign(T) BOOST_INTEL_TT_OPTS) && ! ::boost::is_volatile<T>::value && ! ::boost::is_const<T>::value && is_assignable<T&, const T&>::value)
# define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T) BOOST_INTEL_TT_OPTS && is_destructible<T>::value)
# 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 && is_constructible<T, 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)
@@ -263,6 +263,11 @@
# define BOOST_IS_FINAL(T) __is_final(T)
# endif
# if __GNUC__ >= 5
# define BOOST_HAS_TRIVIAL_MOVE_ASSIGN(T) (__is_trivially_assignable(T&, T&&) && is_assignable<T&, T&&>::value)
# define BOOST_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T) (__is_trivially_constructible(T, T&&) && is_constructible<T, T&&>::value)
# endif
# define BOOST_HAS_TYPE_TRAITS_INTRINSICS
#endif
@@ -276,8 +281,8 @@
# define BOOST_IS_EMPTY(T) __oracle_is_empty(T)
# define BOOST_HAS_TRIVIAL_CONSTRUCTOR(T) (__oracle_has_trivial_constructor(T) && ! ::boost::is_volatile<T>::value)
# define BOOST_HAS_TRIVIAL_COPY(T) (__oracle_has_trivial_copy(T) && !is_reference<T>::value)
# define BOOST_HAS_TRIVIAL_ASSIGN(T) ((__oracle_has_trivial_assign(T) || __oracle_is_trivial(T)) && ! ::boost::is_volatile<T>::value && ! ::boost::is_const<T>::value)
# define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) __oracle_has_trivial_destructor(T)
# define BOOST_HAS_TRIVIAL_ASSIGN(T) ((__oracle_has_trivial_assign(T) || __oracle_is_trivial(T)) && ! ::boost::is_volatile<T>::value && ! ::boost::is_const<T>::value && is_assignable<T&, const T&>::value)
# define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) (__oracle_has_trivial_destructor(T) && is_destructible<T>::value)
# define BOOST_HAS_NOTHROW_CONSTRUCTOR(T) ((__oracle_has_nothrow_constructor(T) || __oracle_has_trivial_constructor(T) || __oracle_is_trivial(T)) && is_default_constructible<T>::value)
# define BOOST_HAS_NOTHROW_COPY(T) ((__oracle_has_nothrow_copy(T) || __oracle_has_trivial_copy(T) || __oracle_is_trivial(T)) && !is_volatile<T>::value && !is_reference<T>::value)
# define BOOST_HAS_NOTHROW_ASSIGN(T) ((__oracle_has_nothrow_assign(T) || __oracle_has_trivial_assign(T) || __oracle_is_trivial(T)) && !is_volatile<T>::value && !is_const<T>::value)
@@ -43,12 +43,13 @@ namespace boost{
#else
#include <boost/type_traits/has_trivial_constructor.hpp>
#include <boost/type_traits/is_pod.hpp>
namespace boost{
// We don't know how to implement this:
template <class T> struct is_default_constructible : public has_trivial_constructor<T>{};
// We don't know how to implement this, note we can not use has_trivial_constructor here
// because the correct implementation of that trait requires this one:
template <class T> struct is_default_constructible : public is_pod<T>{};
template <> struct is_default_constructible<void> : public integral_constant<bool, false>{};
template <> struct is_default_constructible<void const> : public integral_constant<bool, false>{};
template <> struct is_default_constructible<void volatile> : public integral_constant<bool, false>{};