mirror of
https://github.com/boostorg/type_traits.git
synced 2025-08-03 06:24:36 +02:00
Improve has_nothrow_constructor with check for constructibility where required.
This commit is contained in:
@@ -17,11 +17,28 @@
|
||||
#if defined(BOOST_MSVC) || defined(BOOST_INTEL)
|
||||
#include <boost/type_traits/has_trivial_constructor.hpp>
|
||||
#endif
|
||||
#if defined(__GNUC__ ) || defined(__SUNPRO_CC)
|
||||
#include <boost/type_traits/is_default_constructible.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <class T> struct has_nothrow_constructor : public integral_constant<bool, BOOST_HAS_NOTHROW_CONSTRUCTOR(T)>{};
|
||||
|
||||
#elif !defined(BOOST_NO_CXX11_NOEXCEPT)
|
||||
|
||||
#include <boost/type_traits/is_default_constructible.hpp>
|
||||
#include <boost/type_traits/remove_all_extents.hpp>
|
||||
|
||||
namespace boost { namespace detail{
|
||||
|
||||
template <class T, bool b> struct has_nothrow_constructor_imp : public boost::integral_constant<bool, false>{};
|
||||
template <class T> struct has_nothrow_constructor_imp<T, true> : public boost::integral_constant<bool, noexcept(typename remove_all_extents<T>::type())>{};
|
||||
|
||||
}
|
||||
|
||||
template <class T> struct has_nothrow_constructor : public detail::has_nothrow_constructor_imp<T, is_default_constructible<T>::value>{};
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/type_traits/has_trivial_constructor.hpp>
|
||||
|
@@ -243,7 +243,7 @@
|
||||
# define BOOST_HAS_TRIVIAL_COPY(T) ((__has_trivial_copy(T) BOOST_INTEL_TT_OPTS) && !is_reference<T>::value && ! ::boost::is_volatile<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_NOTHROW_CONSTRUCTOR(T) (__has_nothrow_constructor(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_VIRTUAL_DESTRUCTOR(T) __has_virtual_destructor(T)
|
||||
@@ -278,7 +278,7 @@
|
||||
# define BOOST_HAS_TRIVIAL_COPY(T) (__oracle_has_trivial_copy(T) && !is_reference<T>::value && ! ::boost::is_volatile<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_NOTHROW_CONSTRUCTOR(T) (__oracle_has_nothrow_constructor(T) || __oracle_has_trivial_constructor(T) || __oracle_is_trivial(T))
|
||||
# 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)
|
||||
# define BOOST_HAS_VIRTUAL_DESTRUCTOR(T) __oracle_has_virtual_destructor(T)
|
||||
|
@@ -29,7 +29,7 @@ rule all-tests {
|
||||
{
|
||||
result += [ run $(source) ] ;
|
||||
}
|
||||
for local source in has_nothrow_assign_test
|
||||
for local source in has_nothrow_assign_test has_nothrow_constr_test
|
||||
{
|
||||
result += [ run $(source).cpp : : : <define>BOOST_TT_DISABLE_INTRINSICS : $(source)_no_intrinsics ] ;
|
||||
}
|
||||
|
@@ -26,6 +26,35 @@ public:
|
||||
explicit bug11324_derived(char arg) : data(arg) {}
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
|
||||
struct deleted_default_construct
|
||||
{
|
||||
deleted_default_construct() = delete;
|
||||
deleted_default_construct(char val) : member(val) {}
|
||||
char member;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
struct private_default_construct
|
||||
{
|
||||
private:
|
||||
private_default_construct();
|
||||
public:
|
||||
private_default_construct(char val) : member(val) {}
|
||||
char member;
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_CXX11_NOEXCEPT
|
||||
struct noexcept_default_construct
|
||||
{
|
||||
noexcept_default_construct()noexcept;
|
||||
noexcept_default_construct(char val)noexcept : member(val) {}
|
||||
char member;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
TT_TEST_BEGIN(has_nothrow_constructor)
|
||||
|
||||
@@ -178,6 +207,13 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<nothrow_copy_UDT>::v
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<test_abc1>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<bug11324_derived>::value, false);
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<deleted_default_construct>::value, false);
|
||||
#endif
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<private_default_construct>::value, false);
|
||||
#ifndef BOOST_NO_CXX11_NOEXCEPT
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor<noexcept_default_construct>::value, true);
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
|
Reference in New Issue
Block a user