From 265de03026b3336c260df0fed75ae30ce5993425 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 26 Apr 2015 21:14:17 +0200 Subject: [PATCH 1/3] Add test cases for non-constexpr compatible types. --- test/sequence/adapt_struct.cpp | 33 ++++++++++++++++++++++++++ test/sequence/define_struct.cpp | 16 +++++++++++++ test/sequence/define_struct_inline.cpp | 18 ++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/test/sequence/adapt_struct.cpp b/test/sequence/adapt_struct.cpp index c0cd3049..b7e4e117 100644 --- a/test/sequence/adapt_struct.cpp +++ b/test/sequence/adapt_struct.cpp @@ -67,6 +67,17 @@ namespace ns foo foo_; int y; }; + + + // Testing non-constexpr compatible types + struct employee { + std::string name; + std::string nickname; + + employee(std::string name, std::string nickname) + : name(name), nickname(nickname) + {} + }; } #if BOOST_PP_VARIADICS @@ -96,6 +107,13 @@ namespace ns y ) + BOOST_FUSION_ADAPT_STRUCT( + ns::employee, + name, + nickname + ) + + #else // BOOST_PP_VARIADICS BOOST_FUSION_ADAPT_STRUCT( @@ -123,6 +141,12 @@ namespace ns (BOOST_FUSION_ADAPT_AUTO, y) ) + BOOST_FUSION_ADAPT_STRUCT( + ns::employee, + (std::string, name), + (BOOST_FUSION_ADAPT_AUTO, nickname) + ) + #endif int @@ -224,6 +248,15 @@ main() BOOST_TEST(v2 >= v1); } + { + ns::employee emp("John Doe", "jdoe"); + std::cout << at_c<0>(emp) << std::endl; + std::cout << at_c<1>(emp) << std::endl; + + fusion::vector v1("John Doe", "jdoe"); + BOOST_TEST(emp == v1); + } + return boost::report_errors(); } diff --git a/test/sequence/define_struct.cpp b/test/sequence/define_struct.cpp index 795fdf6e..63b5a19d 100644 --- a/test/sequence/define_struct.cpp +++ b/test/sequence/define_struct.cpp @@ -26,6 +26,14 @@ BOOST_FUSION_DEFINE_STRUCT( BOOST_FUSION_DEFINE_STRUCT(BOOST_PP_EMPTY(), s, (int, m)) +// Testing non-constexpr compatible types +BOOST_FUSION_DEFINE_STRUCT( + (ns), + employee, + (std::string, name) + (std::string, nickname) +) + int main() { @@ -100,6 +108,14 @@ main() BOOST_TEST(p == make_vector(3,5)); } + { + ns::employee emp = make_list("John Doe", "jdoe"); + std::cout << at_c<0>(emp) << std::endl; + std::cout << at_c<1>(emp) << std::endl; + + BOOST_TEST(emp == make_vector("John Doe", "jdoe")); + } + return boost::report_errors(); } diff --git a/test/sequence/define_struct_inline.cpp b/test/sequence/define_struct_inline.cpp index e849ce9b..d34a142b 100644 --- a/test/sequence/define_struct_inline.cpp +++ b/test/sequence/define_struct_inline.cpp @@ -41,6 +41,13 @@ namespace ns BOOST_FUSION_DEFINE_STRUCT_INLINE(s, (int, m)) BOOST_FUSION_DEFINE_STRUCT_INLINE(empty_struct, ) + + // Testing non-constexpr compatible types + BOOST_FUSION_DEFINE_STRUCT_INLINE( + employee, + (std::string, name) + (std::string, nickname) + ) } template @@ -128,6 +135,17 @@ main() { run_test(); // test with non-template enclosing class run_test::point>(); // test with template enclosing class + + { + using namespace boost::fusion; + + ns::employee emp = make_list("John Doe", "jdoe"); + std::cout << at_c<0>(emp) << std::endl; + std::cout << at_c<1>(emp) << std::endl; + + BOOST_TEST(emp == make_vector("John Doe", "jdoe")); + } + return boost::report_errors(); } From ce62bb49f331a06c18f6b4f0dc92346c6aa353bb Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 26 Apr 2015 22:10:00 +0200 Subject: [PATCH 2/3] fix constructors of DEFINE_STRUCT_INLINE to allow construction with non-constexpr compatible. --- .../fusion/adapted/struct/detail/define_struct_inline.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/fusion/adapted/struct/detail/define_struct_inline.hpp b/include/boost/fusion/adapted/struct/detail/define_struct_inline.hpp index a5a3ae06..a037ffe5 100644 --- a/include/boost/fusion/adapted/struct/detail/define_struct_inline.hpp +++ b/include/boost/fusion/adapted/struct/detail/define_struct_inline.hpp @@ -66,7 +66,7 @@ #define BOOST_FUSION_IGNORE_2(ARG1, ARG2) #define BOOST_FUSION_MAKE_COPY_CONSTRUCTOR(NAME, ATTRIBUTES_SEQ) \ - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED \ + BOOST_FUSION_GPU_ENABLED \ NAME(BOOST_PP_SEQ_FOR_EACH_I( \ BOOST_FUSION_MAKE_CONST_REF_PARAM, \ ~, \ @@ -337,7 +337,7 @@ typedef boost::mpl::int_ index; \ typedef boost_fusion_detail_Seq sequence_type; \ \ - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED \ + BOOST_FUSION_GPU_ENABLED \ BOOST_FUSION_ITERATOR_NAME(NAME)(boost_fusion_detail_Seq& seq) \ : seq_(seq) \ BOOST_FUSION_DEFINE_ITERATOR_WKND_INIT_LIST_ENTRIES( \ From b902afa5a06903ac85d7f5f0b7b742a8c8f6b3bf Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 29 Apr 2015 15:58:41 +0200 Subject: [PATCH 3/3] fix testcase when BOOST_PP_VARIADICS is disabled. --- test/sequence/adapt_struct.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sequence/adapt_struct.cpp b/test/sequence/adapt_struct.cpp index b7e4e117..121827f5 100644 --- a/test/sequence/adapt_struct.cpp +++ b/test/sequence/adapt_struct.cpp @@ -143,7 +143,7 @@ namespace ns BOOST_FUSION_ADAPT_STRUCT( ns::employee, - (std::string, name), + (std::string, name) (BOOST_FUSION_ADAPT_AUTO, nickname) )