mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-29 12:07:36 +02:00
Added is_trivially_copyable traits
This commit is contained in:
@ -0,0 +1,95 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2018 Kohei Takahashi
|
||||
|
||||
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)
|
||||
==============================================================================*/
|
||||
#ifndef BOOST_FUSION_SUPPORT_DETAIL_IS_TRIVIALLY_COPYABLE
|
||||
#define BOOST_FUSION_SUPPORT_DETAIL_IS_TRIVIALLY_COPYABLE
|
||||
|
||||
#include <boost/fusion/support/config.hpp>
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_GCC, BOOST_TESTED_AT(90000))
|
||||
// GCC treats volatile qualified scalar type as non trivially copyable,
|
||||
// so to be fail safe, we also treat it as non trivially copyable type.
|
||||
// http://wg21.link/cwg2094
|
||||
// https://gcc.gnu.org/PR85679
|
||||
# define BOOST_FUSION_DETAIL_VOLATILE_SCALAR_IS_NON_TRIVIALLY_COPYABLE
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
|
||||
# include <type_traits>
|
||||
#else
|
||||
# include <boost/config/workaround.hpp>
|
||||
# include <boost/mpl/bool.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/type_traits/remove_cv.hpp>
|
||||
# include <boost/type_traits/remove_all_extents.hpp>
|
||||
# include <boost/type_traits/is_scalar.hpp>
|
||||
# include <boost/type_traits/is_constructible.hpp>
|
||||
# include <boost/type_traits/is_assignable.hpp>
|
||||
# include <boost/type_traits/is_copy_constructible.hpp>
|
||||
# include <boost/type_traits/is_copy_assignable.hpp>
|
||||
# include <boost/type_traits/has_trivial_assign.hpp>
|
||||
# include <boost/type_traits/has_trivial_copy.hpp>
|
||||
# include <boost/type_traits/has_trivial_destructor.hpp>
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
# include <boost/type_traits/has_trivial_move_assign.hpp>
|
||||
# include <boost/type_traits/has_trivial_move_constructor.hpp>
|
||||
#endif
|
||||
#ifdef BOOST_FUSION_DETAIL_VOLATILE_SCALAR_IS_NON_TRIVIALLY_COPYABLE
|
||||
# include <boost/mpl/not.hpp>
|
||||
# include <boost/type_traits/is_volatile.hpp>
|
||||
#endif
|
||||
#endif // <type_traits>
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
|
||||
# define BOOST_FUSION_DETAIL_IS_TRIVIALLY_COPYABLE_CONFORMING 2
|
||||
#elif defined(BOOST_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_DECLTYPE) && \
|
||||
defined(BOOST_HAS_TRIVIAL_ASSIGN) && defined(BOOST_HAS_TRIVIAL_COPY) && \
|
||||
defined(BOOST_HAS_TRIVIAL_MOVE_ASSIGN) && defined(BOOST_HAS_TRIVIAL_MOVE_CONSTRUCTOR) && \
|
||||
defined(BOOST_HAS_TRIVIAL_DESTRUCTOR) && defined(BOOST_TT_IS_CONSTRUCTIBLE_CONFORMING)
|
||||
# define BOOST_FUSION_DETAIL_IS_TRIVIALLY_COPYABLE_CONFORMING 1
|
||||
#endif
|
||||
|
||||
namespace boost { namespace fusion { namespace detail
|
||||
{
|
||||
|
||||
#ifdef BOOST_NO_CXX11_HDR_TYPE_TRAITS
|
||||
template <typename T>
|
||||
struct is_trivially_copyable_class
|
||||
: mpl::bool_<
|
||||
(has_trivial_copy<T>::value || !is_copy_constructible<T>::value) &&
|
||||
(has_trivial_assign<T>::value || !is_copy_assignable<T>::value) &&
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
(has_trivial_move_constructor<T>::value || !is_constructible<T, T&&>::value) &&
|
||||
(has_trivial_move_assign<T>::value || !is_assignable<T, T&&>::value) &&
|
||||
#endif // rv-ref
|
||||
(is_constructible<T, T>::value || is_assignable<T, T>::value) &&
|
||||
has_trivial_destructor<T>::value
|
||||
> { };
|
||||
|
||||
template <typename T>
|
||||
struct is_trivially_copyable_impl
|
||||
: mpl::if_c<is_scalar<T>::value
|
||||
#ifdef BOOST_FUSION_DETAIL_VOLATILE_SCALAR_IS_NON_TRIVIALLY_COPYABLE
|
||||
, mpl::not_<is_volatile<T> >
|
||||
#else
|
||||
, mpl::true_
|
||||
#endif
|
||||
, is_trivially_copyable_class<typename remove_cv<T>::type> >::type { };
|
||||
#endif // <type_traits>
|
||||
|
||||
template <typename T>
|
||||
struct is_trivially_copyable
|
||||
#ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
|
||||
: std::is_trivially_copyable<T>
|
||||
#else
|
||||
: is_trivially_copyable_impl<typename remove_all_extents<T>::type>
|
||||
#endif // <type_traits>
|
||||
{ };
|
||||
|
||||
}}} // namespace boost::fusion::detail
|
||||
|
||||
#endif
|
||||
|
@ -268,6 +268,7 @@ project
|
||||
: [ requires cxx11_variadic_templates ] ]
|
||||
[ compile support/tag_of.cpp ]
|
||||
[ compile support/unused.cpp ]
|
||||
[ compile support/is_trivially_copyable.cpp ]
|
||||
|
||||
# [ compile-fail xxx.cpp ]
|
||||
|
||||
|
219
test/support/is_trivially_copyable.cpp
Normal file
219
test/support/is_trivially_copyable.cpp
Normal file
@ -0,0 +1,219 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2018 Kohei Takahashi
|
||||
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)
|
||||
==============================================================================*/
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <boost/fusion/support/detail/is_trivially_copyable.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
|
||||
#ifndef BOOST_FUSION_DETAIL_VOLATILE_SCALAR_IS_NON_TRIVIALLY_COPYABLE
|
||||
# define BOOST_FUSION_ASSERT_WA BOOST_MPL_ASSERT
|
||||
#else
|
||||
# define BOOST_FUSION_ASSERT_WA BOOST_MPL_ASSERT_NOT
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_FUSION_DETAIL_IS_TRIVIALLY_COPYABLE_CONFORMING
|
||||
# define BOOST_FUSION_ASSERT_FALLBACK BOOST_MPL_ASSERT
|
||||
#else
|
||||
# define BOOST_FUSION_ASSERT_FALLBACK(cond) BOOST_MPL_ASSERT((mpl::true_))
|
||||
#endif
|
||||
|
||||
using namespace boost;
|
||||
using namespace boost::fusion::detail;
|
||||
|
||||
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<void>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<void const>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<void volatile>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<void const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<int>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<int const>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<int volatile>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<int const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<int*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<int const*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<int volatile*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<int const volatile*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<int* const>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<int* volatile>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<int* const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<int&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<int const&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<int volatile&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<int const volatile&>));
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<int&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<int const&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<int volatile&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<int const volatile&&>));
|
||||
#endif
|
||||
|
||||
typedef int function_type();
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<function_type>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<function_type const>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<function_type volatile>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<function_type const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<function_type*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<function_type const*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<function_type volatile*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<function_type const volatile*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<function_type* const>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<function_type* volatile>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<function_type* const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<function_type&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<function_type const&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<function_type volatile&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<function_type const volatile&>));
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<function_type&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<function_type const&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<function_type volatile&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<function_type const volatile&&>));
|
||||
#endif
|
||||
|
||||
struct S;
|
||||
typedef int (S::*member_type);
|
||||
typedef int (S::*member_function_type)();
|
||||
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<member_type>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<member_type const>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<member_type volatile>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<member_type const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<member_function_type>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<member_function_type const>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<member_function_type volatile>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<member_function_type const volatile>));
|
||||
|
||||
|
||||
struct trivial { };
|
||||
|
||||
BOOST_FUSION_ASSERT_FALLBACK((is_trivially_copyable<trivial>));
|
||||
BOOST_FUSION_ASSERT_FALLBACK((is_trivially_copyable<trivial const>));
|
||||
BOOST_FUSION_ASSERT_FALLBACK((is_trivially_copyable<trivial volatile>));
|
||||
BOOST_FUSION_ASSERT_FALLBACK((is_trivially_copyable<trivial const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<trivial*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<trivial const*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<trivial volatile*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<trivial const volatile*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<trivial* const>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<trivial* volatile>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<trivial* const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<trivial&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<trivial const&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<trivial volatile&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<trivial const volatile&>));
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<trivial&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<trivial const&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<trivial volatile&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<trivial const volatile&&>));
|
||||
#endif
|
||||
|
||||
|
||||
struct user_provided_copy
|
||||
{
|
||||
user_provided_copy(user_provided_copy const&);
|
||||
user_provided_copy& operator=(user_provided_copy const&);
|
||||
};
|
||||
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_copy>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_copy const>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_copy volatile>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_copy const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_copy*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_copy const*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_copy volatile*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_copy const volatile*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_copy* const>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<user_provided_copy* volatile>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<user_provided_copy* const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_copy&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_copy const&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_copy volatile&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_copy const volatile&>));
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_copy&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_copy const&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_copy volatile&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_copy const volatile&&>));
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
struct user_provided_move
|
||||
{
|
||||
user_provided_move(user_provided_move const&);
|
||||
user_provided_move& operator=(user_provided_move const&);
|
||||
};
|
||||
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_move>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_move const>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_move volatile>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_move const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_move*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_move const*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_move volatile*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_move const volatile*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_move* const>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<user_provided_move* volatile>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<user_provided_move* const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_move&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_move const&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_move volatile&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_move const volatile&>));
|
||||
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_move&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_move const&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_move volatile&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_move const volatile&&>));
|
||||
#endif
|
||||
|
||||
|
||||
struct user_provided_dtor
|
||||
{
|
||||
~user_provided_dtor();
|
||||
};
|
||||
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_dtor>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_dtor const>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_dtor volatile>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_dtor const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_dtor*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_dtor const*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_dtor volatile*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_dtor const volatile*>));
|
||||
BOOST_MPL_ASSERT((is_trivially_copyable<user_provided_dtor* const>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<user_provided_dtor* volatile>));
|
||||
BOOST_FUSION_ASSERT_WA((is_trivially_copyable<user_provided_dtor* const volatile>));
|
||||
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_dtor&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_dtor const&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_dtor volatile&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_dtor const volatile&>));
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_dtor&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_dtor const&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_dtor volatile&&>));
|
||||
BOOST_MPL_ASSERT_NOT((is_trivially_copyable<user_provided_dtor const volatile&&>));
|
||||
#endif
|
Reference in New Issue
Block a user