mirror of
https://github.com/boostorg/type_traits.git
synced 2025-07-29 20:17:21 +02:00
Fix test case: arrays are not explicitly copyable
This commit is contained in:
@ -19,16 +19,11 @@ must be a complete type.
|
||||
|
||||
These two traits are synonyms for each other.
|
||||
|
||||
__compat If the compiler does not support partial-specialization of class
|
||||
templates, then this template can not be used with function types.
|
||||
|
||||
Without some (as yet unspecified) help from the compiler,
|
||||
`has_nothrow_copy` will never report that a class or struct has a
|
||||
non-throwing copy-constructor; this is always safe, if possibly sub-optimal.
|
||||
Currently (May 2011) compilers more recent than Visual C++ 8, GCC-4.3, Greenhills 6.0,
|
||||
Intel-11.0, and Codegear have the necessary compiler __intrinsics to ensure that this
|
||||
trait "just works". You may also test to see if the necessary __intrinsics are available
|
||||
by checking to see if the macro `BOOST_HAS_NOTHROW_COPY` is defined.
|
||||
__compat Either requires C++11 `noexcept` and `decltype` or else some (unspecified) help from the compiler.
|
||||
Currently (June 2015) compilers more recent than Visual C++ 8, GCC-4.3, Greenhills 6.0,
|
||||
Intel-11.0, and Codegear and all recent GCC versions have the necessary compiler __intrinsics to ensure that this
|
||||
trait "just works". You may test to see if the necessary support is available
|
||||
by checking to see if `defined(BOOST_HAS_NOTHROW_COPY) || (!defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_CXX11_NOEXCEPT))` is true.
|
||||
|
||||
__header ` #include <boost/type_traits/has_nothrow_copy.hpp>` or ` #include <boost/type_traits.hpp>`
|
||||
|
||||
|
@ -16,18 +16,41 @@
|
||||
|
||||
#if defined(BOOST_CLANG) || defined(__GNUC__) || defined(__ghs__) || defined(__CODEGEARC__)
|
||||
#include <boost/type_traits/is_volatile.hpp>
|
||||
#include <boost/type_traits/is_constructible.hpp>
|
||||
#include <boost/type_traits/is_reference.hpp>
|
||||
#ifdef BOOST_INTEL
|
||||
#include <boost/type_traits/is_pod.hpp>
|
||||
#endif
|
||||
#elif defined(BOOST_MSVC) || defined(BOOST_INTEL)
|
||||
#include <boost/type_traits/has_trivial_copy.hpp>
|
||||
#include <boost/type_traits/is_array.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <class T> struct has_nothrow_copy_constructor : public integral_constant<bool, BOOST_HAS_NOTHROW_COPY(T)>{};
|
||||
|
||||
#elif !defined(BOOST_NO_CXX11_NOEXCEPT)
|
||||
|
||||
#include <boost/type_traits/detail/decl.hpp>
|
||||
#include <boost/type_traits/is_constructible.hpp>
|
||||
|
||||
namespace boost{
|
||||
|
||||
namespace detail{
|
||||
|
||||
template <class T, bool b>
|
||||
struct has_nothrow_copy_constructor_imp : public boost::integral_constant<bool, false>{};
|
||||
template <class T>
|
||||
struct has_nothrow_copy_constructor_imp<T, true> : public boost::integral_constant<bool, noexcept(T(tt_declval<const T&>()))>{};
|
||||
|
||||
}
|
||||
|
||||
template <class T> struct has_nothrow_copy_constructor : public detail::has_nothrow_copy_constructor_imp<T, boost::is_constructible<T, T const&>::value>{};
|
||||
template <class T> struct has_nothrow_copy_constructor<T&> : public integral_constant<bool, false>{};
|
||||
template <class T> struct has_nothrow_copy_constructor<T&&> : public integral_constant<bool, false>{};
|
||||
template <class T> struct has_nothrow_copy_constructor<T volatile> : public integral_constant<bool, false>{};
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/type_traits/has_trivial_copy.hpp>
|
||||
|
@ -10,35 +10,25 @@
|
||||
#define BOOST_TT_HAS_TRIVIAL_COPY_HPP_INCLUDED
|
||||
|
||||
#include <boost/type_traits/intrinsics.hpp>
|
||||
#include <boost/type_traits/is_volatile.hpp>
|
||||
#include <boost/type_traits/is_pod.hpp>
|
||||
#include <boost/type_traits/is_reference.hpp>
|
||||
|
||||
#ifdef __clang__
|
||||
#include <boost/type_traits/is_copy_constructible.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <typename T> struct has_trivial_copy
|
||||
: public integral_constant<bool,
|
||||
#ifdef BOOST_HAS_TRIVIAL_COPY
|
||||
# ifdef __clang__
|
||||
BOOST_HAS_TRIVIAL_COPY(T) && boost::is_copy_constructible<T>::value
|
||||
# else
|
||||
BOOST_HAS_TRIVIAL_COPY(T)
|
||||
# endif
|
||||
#else
|
||||
::boost::is_pod<T>::value && ! ::boost::is_volatile<T>::value
|
||||
::boost::is_pod<T>::value
|
||||
#endif
|
||||
>{};
|
||||
|
||||
#ifdef __clang__
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct has_trivial_copy<T[N]> : public has_trivial_copy<T>{};
|
||||
|
||||
#endif
|
||||
// Arrays are not explicitly copyable:
|
||||
template <typename T, std::size_t N> struct has_trivial_copy<T[N]> : public false_type{};
|
||||
template <typename T> struct has_trivial_copy<T[]> : public false_type{};
|
||||
// Are volatile types ever trivial? We don't really know, so assume not:
|
||||
template <typename T> struct has_trivial_copy<T volatile> : public false_type{};
|
||||
|
||||
template <> struct has_trivial_copy<void> : public false_type{};
|
||||
#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
|
||||
|
@ -212,9 +212,10 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<int&>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<int&&>::value, false);
|
||||
#endif
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<const int&>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<int[2]>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<int[3][2]>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<int[2][4][5][6][3]>::value, true);
|
||||
// These used to be true, but are now false to match std conforming behavior:
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<int[2]>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<int[3][2]>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<int[2][4][5][6][3]>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<UDT>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<void>::value, false);
|
||||
// cases we would like to succeed but can't implement in the language:
|
||||
@ -236,8 +237,10 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<delete_copy>::value, false)
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<noexcept_copy>::value, true);
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800)
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy<non_copy>::value, false);
|
||||
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
|
||||
|
@ -194,9 +194,10 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<int&>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<int&&>::value, false);
|
||||
#endif
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<const int&>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<int[2]>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<int[3][2]>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<int[2][4][5][6][3]>::value, true);
|
||||
// Arrays can not be explicitly copied:
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<int[2]>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<int[3][2]>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<int[2][4][5][6][3]>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<UDT>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<void>::value, false);
|
||||
// cases we would like to succeed but can't implement in the language:
|
||||
|
Reference in New Issue
Block a user