forked from boostorg/type_traits
Fix has_trivial* traits and improve their tests.
This commit is contained in:
1 parent
24548d6158
commit
2d71379074
12 files changed
+194
-25
No files matched your search
@@ -12,6 +12,23 @@
|
||||
# include <boost/type_traits/has_trivial_assign.hpp>
|
||||
#endif
|
||||
|
||||
struct non_assignable
|
||||
{
|
||||
non_assignable();
|
||||
private:
|
||||
non_assignable& operator=(const non_assignable&);
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
|
||||
struct non_assignable2
|
||||
{
|
||||
non_assignable2();
|
||||
non_assignable2& operator=(const non_assignable2&) = delete;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
TT_TEST_BEGIN(has_trivial_assign)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<bool>::value, true);
|
||||
@@ -180,9 +197,10 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<int&>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<int&&>::value, false);
|
||||
#endif
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<const int&>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<int[2]>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<int[3][2]>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<int[2][4][5][6][3]>::value, true);
|
||||
// Arrays can not be explicitly assigned:
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<int[2]>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<int[3][2]>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<int[2][4][5][6][3]>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<UDT>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<empty_UDT>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<void>::value, false);
|
||||
@@ -203,6 +221,11 @@ BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_assign<wrap<trivial_except_
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<test_abc1>::value, false);
|
||||
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<non_assignable2>::value, false);
|
||||
#endif
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_assign<non_assignable>::value, false);
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
|
||||
|
||||
@@ -27,6 +27,22 @@ public:
|
||||
explicit bug11324_derived(char arg) : data(arg) {}
|
||||
};
|
||||
|
||||
struct private_construct
|
||||
{
|
||||
private_construct(int);
|
||||
private:
|
||||
private_construct();
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
|
||||
struct deleted_construct
|
||||
{
|
||||
deleted_construct(int);
|
||||
deleted_construct() = delete;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
TT_TEST_BEGIN(has_trivial_constructor)
|
||||
|
||||
@@ -167,7 +183,8 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<int[3][2]>::value, t
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<int[2][4][5][6][3]>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<UDT>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<empty_UDT>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<void>::value, true);
|
||||
// Can't construct type void:
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<void>::value, false);
|
||||
// cases we would like to succeed but can't implement in the language:
|
||||
BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<empty_POD_UDT>::value, true, false);
|
||||
BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<POD_UDT>::value, true, false);
|
||||
@@ -187,6 +204,11 @@ BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<wrap<trivial_ex
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<test_abc1>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<bug11324_derived>::value, false);
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<private_construct>::value, false);
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor<deleted_construct>::value, false);
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,13 @@ public:
|
||||
|
||||
#endif
|
||||
|
||||
struct private_copy
|
||||
{
|
||||
private_copy();
|
||||
private:
|
||||
private_copy(const private_copy&);
|
||||
};
|
||||
|
||||
TT_TEST_BEGIN(has_trivial_copy)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<bool>::value, true);
|
||||
@@ -220,6 +227,7 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<test_abc1>::value, false);
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<bug_10389>::value, false);
|
||||
#endif
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy<private_copy>::value, false);
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
|
||||
@@ -12,6 +12,23 @@
|
||||
# include <boost/type_traits/has_trivial_destructor.hpp>
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
|
||||
struct deleted_destruct
|
||||
{
|
||||
deleted_destruct();
|
||||
~deleted_destruct() = delete;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
struct private_destruct
|
||||
{
|
||||
private_destruct();
|
||||
private:
|
||||
~private_destruct();
|
||||
};
|
||||
|
||||
TT_TEST_BEGIN(has_trivial_destructor)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<bool>::value, true);
|
||||
@@ -170,6 +187,11 @@ BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<wrap<trivial_exc
|
||||
BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<wrap<trivial_except_construct> >::value, true, false);
|
||||
BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<wrap<trivial_except_assign> >::value, true, false);
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<private_destruct>::value, false);
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_destructor<deleted_destruct>::value, false);
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,38 @@
|
||||
# include <boost/type_traits/has_trivial_move_assign.hpp>
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
|
||||
struct non_copyable_movable
|
||||
{
|
||||
int val;
|
||||
non_copyable_movable(int);
|
||||
non_copyable_movable(const non_copyable_movable&) = delete;
|
||||
non_copyable_movable& operator=(const non_copyable_movable&) = delete;
|
||||
//non_copyable_movable(non_copyable_movable&&) = default;
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1800)
|
||||
non_copyable_movable& operator=(non_copyable_movable&& o)
|
||||
{
|
||||
val = std::move(o.val);
|
||||
return *this;
|
||||
}
|
||||
#else
|
||||
non_copyable_movable& operator=(non_copyable_movable&&) = default;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct copyable_non_moveable
|
||||
{
|
||||
int val;
|
||||
copyable_non_moveable(int);
|
||||
copyable_non_moveable(const copyable_non_moveable&) = default;
|
||||
copyable_non_moveable& operator=(const copyable_non_moveable&) = default;
|
||||
copyable_non_moveable(copyable_non_moveable&&) = delete;
|
||||
copyable_non_moveable& operator=(copyable_non_moveable&&) = delete;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
TT_TEST_BEGIN(has_trivial_move_assign)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_move_assign<bool>::value, true);
|
||||
@@ -204,6 +236,11 @@ BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_move_assign<wrap<trivial_ex
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_move_assign<test_abc1>::value, false);
|
||||
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_move_assign<non_copyable_movable>::value, true, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_move_assign<copyable_non_moveable>::value, false);
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,39 @@
|
||||
# include <boost/type_traits/has_trivial_move_constructor.hpp>
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
|
||||
struct non_copyable_movable
|
||||
{
|
||||
int val;
|
||||
non_copyable_movable(int);
|
||||
non_copyable_movable(const non_copyable_movable&) = delete;
|
||||
non_copyable_movable& operator=(const non_copyable_movable&) = delete;
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1800)
|
||||
non_copyable_movable(non_copyable_movable&& o) : val(o.val){}
|
||||
non_copyable_movable& operator=(non_copyable_movable&& o)
|
||||
{
|
||||
val = std::move(o.val);
|
||||
return *this;
|
||||
}
|
||||
#else
|
||||
non_copyable_movable(non_copyable_movable&&) = default;
|
||||
non_copyable_movable& operator=(non_copyable_movable&&) = default;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct copyable_non_moveable
|
||||
{
|
||||
int val;
|
||||
copyable_non_moveable(int);
|
||||
copyable_non_moveable(const copyable_non_moveable&) = default;
|
||||
copyable_non_moveable& operator=(const copyable_non_moveable&) = default;
|
||||
copyable_non_moveable(copyable_non_moveable&&) = delete;
|
||||
copyable_non_moveable& operator=(copyable_non_moveable&&) = delete;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
TT_TEST_BEGIN(has_trivial_move_constructor)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_move_constructor<bool>::value, true);
|
||||
@@ -204,6 +237,11 @@ BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_move_constructor<wrap<trivi
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_move_constructor<test_abc1>::value, false);
|
||||
|
||||
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_move_constructor<non_copyable_movable>::value, true, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_move_constructor<copyable_non_moveable>::value, false);
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user