mirror of
https://github.com/boostorg/move.git
synced 2026-05-05 12:04:13 +02:00
- Reworked some traits to refactor code
- is_trivially_copy_xxxxable updated to add is_pod - Updated is_pod adding scalar and void as some compilers' __is_pod intrinsic doesn't work with scalars - Added test for type_traits. Only a few tested, more to come.
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2015-2015.
|
||||
//
|
||||
// Distributed under 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/move for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
#include <boost/move/detail/type_traits.hpp>
|
||||
#include <boost/move/core.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
//
|
||||
// pod_struct
|
||||
//
|
||||
#if defined(BOOST_MOVE_IS_POD)
|
||||
struct pod_struct
|
||||
{
|
||||
int i;
|
||||
float f;
|
||||
};
|
||||
#endif
|
||||
|
||||
//
|
||||
// deleted_copy_and_assign_type
|
||||
//
|
||||
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
|
||||
struct deleted_copy_and_assign_type
|
||||
{
|
||||
deleted_copy_and_assign_type(const deleted_copy_and_assign_type&) = delete;
|
||||
deleted_copy_and_assign_type & operator=(const deleted_copy_and_assign_type&) = delete;
|
||||
};
|
||||
|
||||
#endif //defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
|
||||
//
|
||||
// boost_move_type
|
||||
//
|
||||
class boost_move_type
|
||||
{
|
||||
BOOST_MOVABLE_BUT_NOT_COPYABLE(boost_move_type)
|
||||
public:
|
||||
boost_move_type(BOOST_RV_REF(boost_move_type)){}
|
||||
boost_move_type & operator=(BOOST_RV_REF(boost_move_type)){ return *this; }
|
||||
};
|
||||
|
||||
namespace is_pod_test
|
||||
{
|
||||
|
||||
void test()
|
||||
{
|
||||
BOOST_STATIC_ASSERT((boost::move_detail::is_pod<int>::value));
|
||||
#if defined(BOOST_MOVE_IS_POD)
|
||||
BOOST_STATIC_ASSERT((boost::move_detail::is_pod<pod_struct>::value));
|
||||
#endif
|
||||
}
|
||||
|
||||
} //namespace is_pod_test
|
||||
|
||||
namespace trivially_memcopyable_test {
|
||||
|
||||
void test()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_constructible<deleted_copy_and_assign_type>::value));
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_assignable<deleted_copy_and_assign_type>::value));
|
||||
#endif //#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
//boost_move_type
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_constructible<boost_move_type>::value));
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_assignable<boost_move_type>::value));
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_constructible<boost_move_type>::value));
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_assignable<boost_move_type>::value));
|
||||
//POD
|
||||
BOOST_STATIC_ASSERT((boost::move_detail::is_trivially_copy_constructible<int>::value));
|
||||
BOOST_STATIC_ASSERT((boost::move_detail::is_trivially_copy_assignable<int>::value));
|
||||
BOOST_STATIC_ASSERT((boost::move_detail::is_copy_constructible<int>::value));
|
||||
BOOST_STATIC_ASSERT((boost::move_detail::is_copy_assignable<int>::value));
|
||||
#if defined(BOOST_MOVE_IS_POD)
|
||||
BOOST_STATIC_ASSERT((boost::move_detail::is_trivially_copy_constructible<pod_struct>::value));
|
||||
BOOST_STATIC_ASSERT((boost::move_detail::is_trivially_copy_assignable<pod_struct>::value));
|
||||
BOOST_STATIC_ASSERT((boost::move_detail::is_copy_constructible<pod_struct>::value));
|
||||
BOOST_STATIC_ASSERT((boost::move_detail::is_copy_assignable<pod_struct>::value));
|
||||
#endif
|
||||
}
|
||||
|
||||
} //namespace trivially_memcopyable_test {
|
||||
|
||||
int main()
|
||||
{
|
||||
trivially_memcopyable_test::test();
|
||||
is_pod_test::test();
|
||||
boost::report_errors();
|
||||
}
|
||||
+23
-18
@@ -149,12 +149,30 @@ void test()
|
||||
} //namespace unique_ptr_element_type {
|
||||
|
||||
////////////////////////////////
|
||||
// main
|
||||
// unique_ptr_construct_assign_traits
|
||||
////////////////////////////////
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
#include <memory>
|
||||
#endif
|
||||
namespace unique_ptr_construct_assign_traits {
|
||||
|
||||
void test()
|
||||
{
|
||||
typedef bml::unique_ptr<int> unique_ptr_t;
|
||||
//Even if BOOST_MOVE_TT_CXX11_IS_COPY_CONSTRUCTIBLE is not defined
|
||||
//boost::unique_ptr shall work with boost::movelib traits
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_constructible<unique_ptr_t>::value));
|
||||
//Even if BOOST_MOVE_TT_CXX11_IS_COPY_ASSIGNABLE is not defined
|
||||
//boost::unique_ptr shall work with boost::movelib traits
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_assignable<unique_ptr_t>::value));
|
||||
//Important traits for containers like boost::vector
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_constructible<unique_ptr_t>::value));
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_assignable<unique_ptr_t>::value));
|
||||
}
|
||||
|
||||
} //namespace unique_ptr_construct_assign_traits {
|
||||
|
||||
////////////////////////////////
|
||||
// main
|
||||
////////////////////////////////
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -162,23 +180,10 @@ int main()
|
||||
unique_ptr_pointer_type::test();
|
||||
unique_ptr_deleter_type::test();
|
||||
unique_ptr_element_type::test();
|
||||
|
||||
typedef bml::unique_ptr<int> unique_ptr_t;
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_constructible<unique_ptr_t>::value));
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_assignable<unique_ptr_t>::value));
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_constructible<unique_ptr_t>::value));
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_assignable<unique_ptr_t>::value));
|
||||
#if __cplusplus >= 201103L
|
||||
typedef std::unique_ptr<int> std_unique_ptr_t;
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_constructible<std_unique_ptr_t>::value));
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_assignable<std_unique_ptr_t>::value));
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_constructible<std_unique_ptr_t>::value));
|
||||
BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_assignable<std_unique_ptr_t>::value));
|
||||
#endif
|
||||
unique_ptr_construct_assign_traits::test();
|
||||
|
||||
//Test results
|
||||
return boost::report_errors();
|
||||
|
||||
}
|
||||
|
||||
#include "unique_ptr_test_utils_end.hpp"
|
||||
|
||||
Reference in New Issue
Block a user