diff --git a/test/Jamfile b/test/Jamfile index 1cdb9d53..accf28b0 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -154,6 +154,8 @@ project [ run sequence/tuple_traits.cpp : : : BOOST_FUSION_DISABLE_VARIADIC_VECTOR : tuple_traits__no_variadic ] + [ run sequence/tuple_trivially_copyable.cpp : : + : [ requires cxx11_variadic_templates ] ] [ run sequence/transform_view.cpp ] [ run sequence/vector_comparison.cpp ] [ run sequence/vector_construction.cpp ] @@ -175,6 +177,8 @@ project [ run sequence/vector_traits.cpp : : : BOOST_FUSION_DISABLE_VARIADIC_VECTOR : vector_traits__no_variadic ] + [ run sequence/vector_trivially_copyable.cpp : : + : [ requires cxx11_variadic_templates ] ] [ run sequence/vector_value_at.cpp ] [ run sequence/zip_view.cpp ] [ run sequence/zip_view2.cpp ] diff --git a/test/sequence/trivially_copyable.hpp b/test/sequence/trivially_copyable.hpp new file mode 100644 index 00000000..f702de44 --- /dev/null +++ b/test/sequence/trivially_copyable.hpp @@ -0,0 +1,86 @@ +/*============================================================================= + 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 TRIVIALLY_COPYABLE_HPP +#define TRIVIALLY_COPYABLE_HPP + +#include + +#include +#include "../support/trivial.hpp" + +using namespace boost::fusion; + +#ifdef BOOST_FUSION_DETAIL_IS_TRIVIALLY_COPYABLE_CONFORMING +# define BOOST_FUSION_ASSERT_TC BOOST_MPL_ASSERT +#else +# define BOOST_FUSION_ASSERT_TC BOOST_MPL_ASSERT_NOT +#endif + +BOOST_FUSION_ASSERT_TC((detail::is_trivially_copyable >)); +BOOST_FUSION_ASSERT_TC((detail::is_trivially_copyable >)); +BOOST_FUSION_ASSERT_TC((detail::is_trivially_copyable >)); +BOOST_FUSION_ASSERT_TC((detail::is_trivially_copyable >)); +BOOST_MPL_ASSERT_NOT((detail::is_trivially_copyable >)); +BOOST_MPL_ASSERT_NOT((detail::is_trivially_copyable >)); +BOOST_MPL_ASSERT_NOT((detail::is_trivially_copyable >)); + +BOOST_FUSION_ASSERT_TC((detail::is_trivially_copyable > >)); +BOOST_FUSION_ASSERT_TC((detail::is_trivially_copyable > >)); +BOOST_FUSION_ASSERT_TC((detail::is_trivially_copyable, FUSION_SEQUENCE > >)); +BOOST_FUSION_ASSERT_TC((detail::is_trivially_copyable, FUSION_SEQUENCE, FUSION_SEQUENCE > >)); + +BOOST_FUSION_ASSERT_TC((detail::is_trivially_copyable >)); +BOOST_MPL_ASSERT_NOT((detail::is_trivially_copyable >)); +BOOST_MPL_ASSERT_NOT((detail::is_trivially_copyable >)); +BOOST_MPL_ASSERT_NOT((detail::is_trivially_copyable >)); + +#ifdef BOOST_FUSION_DETAIL_IS_TRIVIALLY_COPYABLE_CONFORMING +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + typedef FUSION_SEQUENCE seq_t; + BOOST_MPL_ASSERT((detail::is_trivially_copyable)); + + typedef boost::aligned_storage::value>::type storage_t; + + storage_t* storage = new storage_t; + + int i = 42; + + const seq_t* src = new seq_t('\t', 3.14159265359, &i); + std::memcpy(static_cast(storage), src, sizeof(seq_t)); + + seq_t* dst = new seq_t; + std::memcpy(dst, static_cast(storage), sizeof(seq_t)); + + BOOST_TEST((*src) == (*dst)); + BOOST_TEST(boost::fusion::at_c<0>(*src) == '\t'); + BOOST_TEST(boost::fusion::at_c<1>(*src) == 3.14159265359); + BOOST_TEST(boost::fusion::at_c<2>(*src) == &i); + BOOST_TEST(*boost::fusion::at_c<2>(*src) == 42); + BOOST_TEST(boost::fusion::at_c<0>(*dst) == '\t'); + BOOST_TEST(boost::fusion::at_c<1>(*dst) == 3.14159265359); + BOOST_TEST(boost::fusion::at_c<2>(*dst) == &i); + BOOST_TEST(*boost::fusion::at_c<2>(*dst) == 42); + + delete dst; + delete src; + delete storage; + + return boost::report_errors(); +} +#else +int main() { } +#endif +#endif diff --git a/test/sequence/tuple_trivially_copyable.cpp b/test/sequence/tuple_trivially_copyable.cpp new file mode 100644 index 00000000..27cfdf51 --- /dev/null +++ b/test/sequence/tuple_trivially_copyable.cpp @@ -0,0 +1,17 @@ +/*============================================================================= + 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 + +#ifndef BOOST_FUSION_HAS_VARIADIC_TUPLE +int main() { } +#else + +#include +#define FUSION_SEQUENCE boost::fusion::tuple +#include "trivially_copyable.hpp" +#endif + diff --git a/test/sequence/vector_trivially_copyable.cpp b/test/sequence/vector_trivially_copyable.cpp new file mode 100644 index 00000000..f36491aa --- /dev/null +++ b/test/sequence/vector_trivially_copyable.cpp @@ -0,0 +1,17 @@ +/*============================================================================= + 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 + +#ifndef BOOST_FUSION_HAS_VARIADIC_VECTOR +int main() { } +#else + +#include +#define FUSION_SEQUENCE boost::fusion::vector +#include "trivially_copyable.hpp" +#endif +