From 3f965e00d30ea050218608c682a51d54db5eb156 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 22 Dec 2013 21:14:31 +0100 Subject: [PATCH 01/37] #9516 BOOST_FUSION_AUTO_ADAPT_STRUCT that does not require specifying the types of the fields. --- .../adapted/struct/auto_adapt_struct.hpp | 28 +++ test/Jamfile | 1 + test/sequence/auto_adapt_struct.cpp | 164 ++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 include/boost/fusion/adapted/struct/auto_adapt_struct.hpp create mode 100644 test/sequence/auto_adapt_struct.cpp diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp new file mode 100644 index 00000000..9029ecbe --- /dev/null +++ b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2001-2007 Joel de Guzman + Copyright (c) 2009-2011 Christopher Schmidt + Copyright (c) 2013-2014 Damien Buhl + + 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_ADAPTED_STRUCT_AUTO_ADAPT_STRUCT_HPP +#define BOOST_FUSION_ADAPTED_STRUCT_AUTO_ADAPT_STRUCT_HPP + +#include + +#include + +#include + +#define BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER(r, data, elem) \ + (BOOST_TYPEOF(data::elem), elem) \ + +#define BOOST_FUSION_AUTO_ADAPT_STRUCT(NAME, ATTRIBUTES) \ + BOOST_FUSION_ADAPT_STRUCT(NAME, \ + BOOST_PP_SEQ_FOR_EACH( \ + BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER, NAME, ATTRIBUTES) \ + ) + +#endif diff --git a/test/Jamfile b/test/Jamfile index 1c84637d..1e58b054 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -141,6 +141,7 @@ project [ run sequence/adapt_assoc_tpl_struct.cpp : : : : ] [ run sequence/adapt_struct_named.cpp : : : : ] [ run sequence/adapt_struct.cpp : : : : ] + [ run sequence/auto_adapt_struct.cpp : : : : ] [ run sequence/adapt_tpl_adt.cpp : : : : ] [ run sequence/adapt_tpl_struct.cpp : : : : ] [ run sequence/adt_attribute_proxy.cpp : : : : ] diff --git a/test/sequence/auto_adapt_struct.cpp b/test/sequence/auto_adapt_struct.cpp new file mode 100644 index 00000000..7007e49c --- /dev/null +++ b/test/sequence/auto_adapt_struct.cpp @@ -0,0 +1,164 @@ +/*============================================================================= + Copyright (c) 2001-2007 Joel de Guzman + Copyright (c) 2013-2014 Damien Buhl + + 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ns +{ + struct point + { + int x; + int y; + }; + +#if !BOOST_WORKAROUND(__GNUC__,<4) + struct point_with_private_attributes + { + friend struct boost::fusion::extension::access; + + private: + int x; + int y; + + public: + point_with_private_attributes(int x, int y):x(x),y(y) + {} + }; +#endif +} + +BOOST_FUSION_AUTO_ADAPT_STRUCT( + ns::point, + (x) + (y) +) + +#if !BOOST_WORKAROUND(__GNUC__,<4) +BOOST_FUSION_AUTO_ADAPT_STRUCT( + ns::point_with_private_attributes, + (x) + (y) +) +#endif + +struct s { int m; }; +BOOST_FUSION_AUTO_ADAPT_STRUCT(s, (m)) + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view)); + ns::point p = {123, 456}; + + std::cout << at_c<0>(p) << std::endl; + std::cout << at_c<1>(p) << std::endl; + std::cout << p << std::endl; + BOOST_TEST(p == make_vector(123, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + fusion::vector v1(4, 2); + ns::point v2 = {5, 3}; + fusion::vector v3(5, 4); + BOOST_TEST(v1 < v2); + BOOST_TEST(v1 <= v2); + BOOST_TEST(v2 > v1); + BOOST_TEST(v2 >= v1); + BOOST_TEST(v2 < v3); + BOOST_TEST(v2 <= v3); + BOOST_TEST(v3 > v2); + BOOST_TEST(v3 >= v2); + } + + { + // conversion from ns::point to vector + ns::point p = {5, 3}; + fusion::vector v(p); + v = p; + } + + { + // conversion from ns::point to list + ns::point p = {5, 3}; + fusion::list l(p); + l = p; + } + + { // begin/end + using namespace boost::fusion; + using boost::is_same; + + typedef boost::fusion::result_of::begin::type b; + typedef boost::fusion::result_of::end::type e; + // this fails + BOOST_MPL_ASSERT((is_same::type, e>)); + } + + { + BOOST_MPL_ASSERT((mpl::is_sequence)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c::type + , mpl::front::type>)); + } + +#if !BOOST_WORKAROUND(__GNUC__,<4) + { + ns::point_with_private_attributes p(123, 456); + + std::cout << at_c<0>(p) << std::endl; + std::cout << at_c<1>(p) << std::endl; + std::cout << p << std::endl; + BOOST_TEST(p == make_vector(123, 456)); + } +#endif + + return boost::report_errors(); +} From 946957d3dccfc8cf5125cc19d2578638309e79f4 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 26 Jan 2014 14:44:15 +0100 Subject: [PATCH 02/37] EDITORIAL: Change parameter names for consistency. --- include/boost/fusion/adapted/struct/auto_adapt_struct.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp index 9029ecbe..d71e39de 100644 --- a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp @@ -16,8 +16,8 @@ #include -#define BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER(r, data, elem) \ - (BOOST_TYPEOF(data::elem), elem) \ +#define BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER(r, NAME, ATTRIBUTE) \ + (BOOST_TYPEOF(NAME::ATTRIBUTE), ATTRIBUTE) \ #define BOOST_FUSION_AUTO_ADAPT_STRUCT(NAME, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT(NAME, \ From 0d7ad9f6e28443ea54a76ea20af8474472345f47 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 26 Jan 2014 17:31:01 +0100 Subject: [PATCH 03/37] FEATURE: BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED that does not require specifying the types of the fields. --- include/boost/fusion/adapted/struct.hpp | 2 + .../struct/auto_adapt_struct_named.hpp | 25 ++++ test/Jamfile | 1 + test/sequence/auto_adapt_struct_named.cpp | 137 ++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp create mode 100644 test/sequence/auto_adapt_struct_named.cpp diff --git a/include/boost/fusion/adapted/struct.hpp b/include/boost/fusion/adapted/struct.hpp index 3f159038..5a45b596 100644 --- a/include/boost/fusion/adapted/struct.hpp +++ b/include/boost/fusion/adapted/struct.hpp @@ -14,7 +14,9 @@ #include #include #include +#include #include +#include #include #include #include diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp new file mode 100644 index 00000000..a09662b7 --- /dev/null +++ b/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp @@ -0,0 +1,25 @@ +/*============================================================================= + Copyright (c) 2001-2007 Joel de Guzman + Copyright (c) 2009-2010 Hartmut Kaiser + Copyright (c) 2010-2011 Christopher Schmidt + Copyright (c) 2013-2014 Damien Buhl + + + 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_ADAPTED_STRUCT_AUTO_ADAPT_STRUCT_NAMED_HPP +#define BOOST_FUSION_ADAPTED_STRUCT_AUTO_ADAPT_STRUCT_NAMED_HPP + +#include +#include + +#define BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED(WRAPPED_TYPE, NAME, ATTRIBUTES) \ + BOOST_FUSION_ADAPT_STRUCT_NAMED( \ + WRAPPED_TYPE,NAME, \ + BOOST_PP_SEQ_FOR_EACH( \ + BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER, WRAPPED_TYPE, ATTRIBUTES) \ + ) + +#endif diff --git a/test/Jamfile b/test/Jamfile index 1e58b054..c5bfdf6a 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -140,6 +140,7 @@ project [ run sequence/adapt_assoc_tpl_adt.cpp : : : : ] [ run sequence/adapt_assoc_tpl_struct.cpp : : : : ] [ run sequence/adapt_struct_named.cpp : : : : ] + [ run sequence/auto_adapt_struct_named.cpp : : : : ] [ run sequence/adapt_struct.cpp : : : : ] [ run sequence/auto_adapt_struct.cpp : : : : ] [ run sequence/adapt_tpl_adt.cpp : : : : ] diff --git a/test/sequence/auto_adapt_struct_named.cpp b/test/sequence/auto_adapt_struct_named.cpp new file mode 100644 index 00000000..dfa10006 --- /dev/null +++ b/test/sequence/auto_adapt_struct_named.cpp @@ -0,0 +1,137 @@ +/*============================================================================= + Copyright (c) 2001-2007 Joel de Guzman + + 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ns +{ + struct point + { + int x; + int y; + }; +} + +// this creates a fusion view: boost::fusion::adapted::point +BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED( + ns::point, point, + (x) + (y) +) + +// this creates a fusion view: ns1::s1 +struct s { int m; }; +BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(s, (ns1), s1, (int, m)) + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT((traits::is_view)); + ns::point basep = {123, 456}; + adapted::point p(basep); + + std::cout << at_c<0>(p) << std::endl; + std::cout << at_c<1>(p) << std::endl; + std::cout << p << std::endl; + BOOST_TEST(p == make_vector(123, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + fusion::vector v1(4, 2); + ns::point p = {5, 3}; + adapted::point v2(p); + + fusion::vector v3(5, 4); + BOOST_TEST(v1 < v2); + BOOST_TEST(v1 <= v2); + BOOST_TEST(v2 > v1); + BOOST_TEST(v2 >= v1); + BOOST_TEST(v2 < v3); + BOOST_TEST(v2 <= v3); + BOOST_TEST(v3 > v2); + BOOST_TEST(v3 >= v2); + } + + { + // conversion from adapted::point to vector + ns::point basep = {5, 3}; + adapted::point p(basep); + fusion::vector v(p); + v = p; + } + + { + // conversion from adapted::point to list + ns::point basep = {5, 3}; + adapted::point p(basep); + fusion::list l(p); + l = p; + } + + { // begin/end + using namespace boost::fusion; + using boost::is_same; + + typedef boost::fusion::result_of::begin::type b; + typedef boost::fusion::result_of::end::type e; + // this fails + BOOST_MPL_ASSERT((is_same::type, e>)); + } + + + { + BOOST_MPL_ASSERT((mpl::is_sequence)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c::type + , mpl::front::type>)); + } + + return boost::report_errors(); +} + From 5aa9a89fb82cd29f8a48d3dba41df9573d81c3cf Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 26 Jan 2014 18:01:44 +0100 Subject: [PATCH 04/37] FEATURE: BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED_NS which allows listing class attributes to adapt without specifying types. --- .../fusion/adapted/struct/auto_adapt_struct_named.hpp | 8 ++++++++ test/sequence/auto_adapt_struct_named.cpp | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp index a09662b7..81b58cf6 100644 --- a/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp +++ b/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp @@ -15,6 +15,14 @@ #include #include +#define BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED_NS( \ + WRAPPED_TYPE, NAMESPACE_SEQ, NAME, ATTRIBUTES) \ + \ + BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( \ + WRAPPED_TYPE, NAMESPACE_SEQ, NAME, \ + BOOST_PP_SEQ_FOR_EACH( \ + BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER, WRAPPED_TYPE, ATTRIBUTES)) \ + #define BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED(WRAPPED_TYPE, NAME, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_NAMED( \ WRAPPED_TYPE,NAME, \ diff --git a/test/sequence/auto_adapt_struct_named.cpp b/test/sequence/auto_adapt_struct_named.cpp index dfa10006..1ada8efe 100644 --- a/test/sequence/auto_adapt_struct_named.cpp +++ b/test/sequence/auto_adapt_struct_named.cpp @@ -49,7 +49,7 @@ BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED( // this creates a fusion view: ns1::s1 struct s { int m; }; -BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(s, (ns1), s1, (int, m)) +BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED_NS(s, (ns1), s1, (m)) int main() From e58bd91f277b6ea38b2a062ddeb7414064c92ed0 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 26 Jan 2014 18:02:00 +0100 Subject: [PATCH 05/37] EDITORIAL: fixed indentation. --- include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp index 81b58cf6..e414304b 100644 --- a/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp +++ b/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp @@ -27,7 +27,7 @@ BOOST_FUSION_ADAPT_STRUCT_NAMED( \ WRAPPED_TYPE,NAME, \ BOOST_PP_SEQ_FOR_EACH( \ - BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER, WRAPPED_TYPE, ATTRIBUTES) \ + BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER, WRAPPED_TYPE, ATTRIBUTES) \ ) #endif From 5ffab5001e54cc50325505445dc7a94ebddc895b Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 26 Jan 2014 18:23:00 +0100 Subject: [PATCH 06/37] REFACTORING: reused the BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED_NS macro in BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED to mimic the non-AUTO versions. --- .../fusion/adapted/struct/auto_adapt_struct_named.hpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp index e414304b..a7fd6923 100644 --- a/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp +++ b/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp @@ -24,10 +24,7 @@ BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER, WRAPPED_TYPE, ATTRIBUTES)) \ #define BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED(WRAPPED_TYPE, NAME, ATTRIBUTES) \ - BOOST_FUSION_ADAPT_STRUCT_NAMED( \ - WRAPPED_TYPE,NAME, \ - BOOST_PP_SEQ_FOR_EACH( \ - BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER, WRAPPED_TYPE, ATTRIBUTES) \ - ) + BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED_NS( \ + WRAPPED_TYPE,(boost)(fusion)(adapted),NAME,ATTRIBUTES) #endif From 8a132ea44a641ba30b3fb29a18f70b2b4f9d707f Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 4 Feb 2014 22:48:34 +0100 Subject: [PATCH 07/37] BUGFIX: Fix include path. --- include/boost/fusion/adapted/struct/auto_adapt_struct.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp index d71e39de..c049de1e 100644 --- a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp @@ -14,7 +14,7 @@ #include -#include +#include #define BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER(r, NAME, ATTRIBUTE) \ (BOOST_TYPEOF(NAME::ATTRIBUTE), ATTRIBUTE) \ From f7b14aee35cbf25a7728eb8b334c2ad8df893c8d Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 11 Feb 2014 23:37:53 +0100 Subject: [PATCH 08/37] FEATURE: BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT now allows defining a Random Access Sequence and an Associative sequence without providing the type. --- .../struct/auto_adapt_assoc_struct.hpp | 44 ++++++ test/Jamfile | 1 + test/sequence/auto_adapt_assoc_struct.cpp | 141 ++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp create mode 100644 test/sequence/auto_adapt_assoc_struct.cpp diff --git a/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp b/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp new file mode 100644 index 00000000..0b069de1 --- /dev/null +++ b/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp @@ -0,0 +1,44 @@ +/*============================================================================= + Copyright (c) 2001-2007 Joel de Guzman + Copyright (c) 2007 Dan Marsden + Copyright (c) 2009-2011 Christopher Schmidt + Copyright (c) 2013-2014 Damien Buhl + + 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_ADAPTED_STRUCT_AUTO_ADAPT_ASSOC_STRUCT_HPP +#define BOOST_FUSION_ADAPTED_STRUCT_AUTO_ADAPT_ASSOC_STRUCT_HPP + +#include +#include + +#include + +#include +#include + +#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_0(A, B) \ + ((A, B)) BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_1 +#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_1(A, B) \ + ((A, B)) BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_0 +#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_0_END +#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_1_END + +#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_TYPE_DEDUCER(r, NAME, ATTRIBUTE) \ + (BOOST_TYPEOF(NAME::BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE)), \ + BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE), \ + BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE)) + +#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT(NAME, ATTRIBUTES) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT(NAME, \ + BOOST_PP_SEQ_FOR_EACH( \ + BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_TYPE_DEDUCER, \ + NAME, \ + BOOST_PP_CAT( \ + BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_0 ATTRIBUTES,_END) \ + ) \ + ) + +#endif diff --git a/test/Jamfile b/test/Jamfile index c5bfdf6a..f21f753d 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -137,6 +137,7 @@ project [ run sequence/adapt_assoc_adt.cpp : : : : ] [ run sequence/adapt_assoc_struct_named.cpp : : : : ] [ run sequence/adapt_assoc_struct.cpp : : : : ] + [ run sequence/auto_adapt_assoc_struct.cpp : : : : ] [ run sequence/adapt_assoc_tpl_adt.cpp : : : : ] [ run sequence/adapt_assoc_tpl_struct.cpp : : : : ] [ run sequence/adapt_struct_named.cpp : : : : ] diff --git a/test/sequence/auto_adapt_assoc_struct.cpp b/test/sequence/auto_adapt_assoc_struct.cpp new file mode 100644 index 00000000..177df20b --- /dev/null +++ b/test/sequence/auto_adapt_assoc_struct.cpp @@ -0,0 +1,141 @@ +/*============================================================================= + Copyright (c) 2001-2007 Joel de Guzman + Copyright (c) 2005-2007 Dan Marsden + + 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ns +{ + struct x_member; + struct y_member; + struct z_member; + + struct point + { + int x; + int y; + }; +} + +BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT( + ns::point, + (x, ns::x_member) + (y, ns::y_member) +) + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view)); + ns::point p = {123, 456}; + + std::cout << at_c<0>(p) << std::endl; + std::cout << at_c<1>(p) << std::endl; + std::cout << p << std::endl; + BOOST_TEST(p == make_vector(123, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + fusion::vector v1(4, 2); + ns::point v2 = {5, 3}; + fusion::vector v3(5, 4); + BOOST_TEST(v1 < v2); + BOOST_TEST(v1 <= v2); + BOOST_TEST(v2 > v1); + BOOST_TEST(v2 >= v1); + BOOST_TEST(v2 < v3); + BOOST_TEST(v2 <= v3); + BOOST_TEST(v3 > v2); + BOOST_TEST(v3 >= v2); + } + + { + // conversion from ns::point to vector + ns::point p = {5, 3}; + fusion::vector v(p); + v = p; + } + + { + // conversion from ns::point to list + ns::point p = {5, 3}; + fusion::list l(p); + l = p; + } + + { + // assoc stuff + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key)); + BOOST_MPL_ASSERT((mpl::not_ >)); + + BOOST_MPL_ASSERT((boost::is_same::type, int>)); + BOOST_MPL_ASSERT((boost::is_same::type, int>)); + + ns::point p = {5, 3}; + + BOOST_TEST(at_key(p) == 5); + BOOST_TEST(at_key(p) == 3); + } + + { + BOOST_MPL_ASSERT((mpl::is_sequence)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c::type + , mpl::front::type>)); + } + + return boost::report_errors(); +} + From 2d37b9c22ce311887210813ec4538fe272014cab Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 11 Feb 2014 23:39:42 +0100 Subject: [PATCH 09/37] EDITORIAL: Fixes typos. --- include/boost/fusion/adapted/struct/auto_adapt_struct.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp index c049de1e..b967be06 100644 --- a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp @@ -17,12 +17,12 @@ #include #define BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER(r, NAME, ATTRIBUTE) \ - (BOOST_TYPEOF(NAME::ATTRIBUTE), ATTRIBUTE) \ + (BOOST_TYPEOF(NAME::ATTRIBUTE), ATTRIBUTE) #define BOOST_FUSION_AUTO_ADAPT_STRUCT(NAME, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT(NAME, \ BOOST_PP_SEQ_FOR_EACH( \ - BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER, NAME, ATTRIBUTES) \ + BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER, NAME, ATTRIBUTES) \ ) #endif From a5f87696f2aef03156aaefffc923afc33f483e3f Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 11 Feb 2014 23:46:38 +0100 Subject: [PATCH 10/37] EDITORIAL: Rename the macro for type deduction to a more expressive and correct name. --- include/boost/fusion/adapted/struct/auto_adapt_struct.hpp | 4 ++-- .../boost/fusion/adapted/struct/auto_adapt_struct_named.hpp | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp index b967be06..08f47157 100644 --- a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp @@ -16,13 +16,13 @@ #include -#define BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER(r, NAME, ATTRIBUTE) \ +#define BOOST_FUSION_AUTO_ADAPT_STRUCT_TYPE_DEDUCER(r, NAME, ATTRIBUTE) \ (BOOST_TYPEOF(NAME::ATTRIBUTE), ATTRIBUTE) #define BOOST_FUSION_AUTO_ADAPT_STRUCT(NAME, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT(NAME, \ BOOST_PP_SEQ_FOR_EACH( \ - BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER, NAME, ATTRIBUTES) \ + BOOST_FUSION_AUTO_ADAPT_STRUCT_TYPE_DEDUCER, NAME, ATTRIBUTES) \ ) #endif diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp index a7fd6923..de81fbcf 100644 --- a/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp +++ b/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp @@ -21,7 +21,9 @@ BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( \ WRAPPED_TYPE, NAMESPACE_SEQ, NAME, \ BOOST_PP_SEQ_FOR_EACH( \ - BOOST_FUSION_AUTO_ADAPT_STRUCT_FILLER, WRAPPED_TYPE, ATTRIBUTES)) \ + BOOST_FUSION_AUTO_ADAPT_STRUCT_TYPE_DEDUCER, \ + WRAPPED_TYPE, \ + ATTRIBUTES)) #define BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED(WRAPPED_TYPE, NAME, ATTRIBUTES) \ BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED_NS( \ From 934463c7b4001b932f8a69f72edbc28f168d58ef Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 18 Feb 2014 22:04:38 +0100 Subject: [PATCH 11/37] FEATURE: BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED now allows defining a Random Access Sequence and an Associative sequence without providing the type. --- .../struct/auto_adapt_assoc_struct_named.hpp | 56 ++++++++ test/Jamfile | 1 + .../auto_adapt_assoc_struct_named.cpp | 121 ++++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 include/boost/fusion/adapted/struct/auto_adapt_assoc_struct_named.hpp create mode 100644 test/sequence/auto_adapt_assoc_struct_named.cpp diff --git a/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct_named.hpp b/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct_named.hpp new file mode 100644 index 00000000..1945c62c --- /dev/null +++ b/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct_named.hpp @@ -0,0 +1,56 @@ +/*============================================================================= + Copyright (c) 2010-2011 Christopher Schmidt + Copyright (c) 2013-2014 Damien Buhl + + 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_ADAPTED_STRUCT_AUTO_ADAPT_ASSOC_STRUCT_NAMED_HPP +#define BOOST_FUSION_ADAPTED_STRUCT_AUTO_ADAPT_ASSOC_STRUCT_NAMED_HPP + +#include +#include +#include + +#include + +#include + +#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_0(A, B) \ + ((A, B)) BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_1 +#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_1(A, B) \ + ((A, B)) BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_0 +#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_0_END +#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_1_END + +#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_TYPE_DEDUCER( \ + r, NAME, ATTRIBUTE) \ + (BOOST_TYPEOF( \ + BOOST_PP_TUPLE_ELEM( \ + 2, \ + 0, \ + NAME) \ + ::BOOST_PP_TUPLE_ELEM( \ + 2, \ + 0, \ + ATTRIBUTE)), \ + BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE), \ + BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE)) + +#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED( \ + WRAPPED_TYPE, NAME, ATTRIBUTES) \ + \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED(WRAPPED_TYPE, \ + NAME, \ + BOOST_PP_SEQ_FOR_EACH( \ + BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_TYPE_DEDUCER, \ + (WRAPPED_TYPE, NAME), \ + BOOST_PP_CAT( \ + BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_0 ATTRIBUTES, \ + _END) \ + ) \ + ) + + +#endif diff --git a/test/Jamfile b/test/Jamfile index f21f753d..5587ab5d 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -136,6 +136,7 @@ project [ run sequence/adapt_assoc_adt_named.cpp : : : : ] [ run sequence/adapt_assoc_adt.cpp : : : : ] [ run sequence/adapt_assoc_struct_named.cpp : : : : ] + [ run sequence/auto_adapt_assoc_struct_named.cpp : : : : ] [ run sequence/adapt_assoc_struct.cpp : : : : ] [ run sequence/auto_adapt_assoc_struct.cpp : : : : ] [ run sequence/adapt_assoc_tpl_adt.cpp : : : : ] diff --git a/test/sequence/auto_adapt_assoc_struct_named.cpp b/test/sequence/auto_adapt_assoc_struct_named.cpp new file mode 100644 index 00000000..b2e85541 --- /dev/null +++ b/test/sequence/auto_adapt_assoc_struct_named.cpp @@ -0,0 +1,121 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ns +{ + struct x_member; + struct y_member; + struct z_member; + + struct point + { + int x; + int y; + }; +} + +BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED( + ns::point, + point, + (x, ns::x_member) + (y, ns::y_member) +) + +int +main() +{ + using namespace boost::fusion; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT((traits::is_view)); + ns::point basep = {123, 456}; + adapted::point p(basep); + + std::cout << at_c<0>(p) << std::endl; + std::cout << at_c<1>(p) << std::endl; + std::cout << p << std::endl; + BOOST_TEST(p == make_vector(123, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + vector v1(4, 2); + ns::point basev2 = {5, 3}; + adapted::point v2(basev2); + + vector v3(5, 4); + BOOST_TEST(v1 < v2); + BOOST_TEST(v1 <= v2); + BOOST_TEST(v2 > v1); + BOOST_TEST(v2 >= v1); + BOOST_TEST(v2 < v3); + BOOST_TEST(v2 <= v3); + BOOST_TEST(v3 > v2); + BOOST_TEST(v3 >= v2); + } + + { + // conversion from adapted::point to vector + ns::point basep = {5, 3}; + adapted::point p(basep); + vector v(p); + v = p; + } + + { + // conversion from adapted::point to list + ns::point basep = {5, 3}; + adapted::point p(basep); + list l(p); + l = p; + } + + { + // assoc stuff + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key)); + BOOST_MPL_ASSERT((boost::mpl::not_ >)); + + BOOST_MPL_ASSERT((boost::is_same::type, int>)); + BOOST_MPL_ASSERT((boost::is_same::type, int>)); + + ns::point basep = {5, 3}; + adapted::point p(basep); + + BOOST_TEST(at_key(p) == 5); + BOOST_TEST(at_key(p) == 3); + } + + return boost::report_errors(); +} + From 435fb5c29fa9093dd37b238a1ccb00cd5b74992d Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 18 Feb 2014 22:04:51 +0100 Subject: [PATCH 12/37] EDITORIAL: Reorganize imports. --- include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp b/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp index 0b069de1..936e1e74 100644 --- a/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp +++ b/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp @@ -13,11 +13,11 @@ #include #include +#include #include #include -#include #define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_0(A, B) \ ((A, B)) BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_1 From 166132789a59debcbad224c6ef014b875ae5da17 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 4 Mar 2014 23:22:23 +0100 Subject: [PATCH 13/37] DOC: Document the BOOST_FUSION_AUTO* macros. This documents the AUTO_ADAPT macros : * BOOST_FUSION_AUTO_ADAPT_STRUCT * BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED * BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT * BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED --- doc/adapted.qbk | 172 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 159 insertions(+), 13 deletions(-) diff --git a/doc/adapted.qbk b/doc/adapted.qbk index f762a049..2f77a0c6 100644 --- a/doc/adapted.qbk +++ b/doc/adapted.qbk @@ -177,7 +177,7 @@ __boost_tuple_library__ [endsect] -[section:adapt_struct BOOST_FUSION_ADAPT_STRUCT] +[section:adapt_struct BOOST_FUSION_ \[AUTO_\] ADAPT_STRUCT] [heading Description] BOOST_FUSION_ADAPT_STRUCT is a macro that can be used to generate all the @@ -192,13 +192,22 @@ __random_access_sequence__. ... ) + BOOST_FUSION_AUTO_ADAPT_STRUCT( + struct_name, + (member_name0) + (member_name1) + ... + ) + [heading Semantics] The above macro generates the necessary code to adapt `struct_name` as a model of __random_access_sequence__. The sequence of `(member_typeN, member_nameN)` pairs declares the type and names of each of the struct members that are -part of the sequence. +part of the sequence. While the auto version of the macro only allows +specifying a sequence of `(member_nameN)` as fields' types are deduced with +[@boost:/libs/typeof/index.html Boost.TypeOf]. The macro should be used at global scope, and `struct_name` should be the fully namespace qualified name of the struct to be adapted. @@ -206,9 +215,10 @@ namespace qualified name of the struct to be adapted. [heading Header] #include + #include #include -[heading Example] +[heading Example: BOOST_FUSION_ADAPT_STRUCT ] namespace demo { struct employee @@ -224,6 +234,23 @@ namespace qualified name of the struct to be adapted. (std::string, name) (int, age)) + +[heading Example: BOOST_FUSION_AUTO_ADAPT_STRUCT ] + namespace demo + { + struct employee + { + std::string name; + int age; + }; + } + + // demo::employee is now a Fusion sequence + BOOST_FUSION_AUTO_ADAPT_STRUCT( + demo::employee, + (name) + (age)) + [endsect] [section:adapt_tpl_struct BOOST_FUSION_ADAPT_TPL_STRUCT] @@ -284,7 +311,7 @@ namespace qualified name of the struct to be adapted. [endsect] -[section:adapt_struct_named BOOST_FUSION_ADAPT_STRUCT_NAMED] +[section:adapt_struct_named BOOST_FUSION_ \[AUTO_\] ADAPT_STRUCT_NAMED] [heading Description] BOOST_FUSION_ADAPT_STRUCT_NAMED and BOOST_FUSION_ADAPT_STRUCT_NAMED_NS are @@ -292,6 +319,7 @@ macros that can be used to generate all the necessary boilerplate to make an arbitrary struct a model of __random_access_sequence__. The given struct is adapted using the given name. + [heading Synopsis] BOOST_FUSION_ADAPT_STRUCT_NAMED( struct_name, adapted_name, @@ -300,6 +328,13 @@ adapted using the given name. ... ) + BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED( + struct_name, adapted_name, + (member_name0) + (member_name1) + ... + ) + BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( struct_name, (namespace0)(namespace1)..., @@ -309,6 +344,17 @@ adapted using the given name. ... ) + BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED_NS( + struct_name, + (namespace0)(namespace1)..., + adapted_name, + (member_name0) + (member_name1) + ... + ) + + + [heading Semantics] The above macros generate the necessary code to adapt `struct_name` @@ -321,9 +367,11 @@ If an empty namespace sequence is given (that is a macro that expands to nothing), the adapted view is placed in the global namespace. If no namespace sequence is given (i.e. `BOOST_FUSION_ADAPT_STRUCT_NAMED`), the adapted view is placed in the namespace `boost::fusion::adapted`. -The sequence of `(member_typeN, member_nameN)` -pairs declares the type and names of each of the struct members that are -part of the sequence. +In the non-auto version of the macro the sequence of +`(member_typeN, member_nameN)` pairs declares the type and names of each of the +struct members that are part of the sequence. +While the auto version of the macro only allows specifying a sequence of +`(member_nameN)` as fields' types are deduced with [@boost:/libs/typeof/index.html Boost.TypeOf]. The macros should be used at global scope, and `struct_name` should be the fully namespace qualified name of the struct to be converted. @@ -331,9 +379,10 @@ namespace qualified name of the struct to be converted. [heading Header] #include + #include #include -[heading Example] +[heading Example: BOOST_FUSION_ADAPT_STRUCT_NAMED] namespace demo { struct employee @@ -350,9 +399,26 @@ namespace qualified name of the struct to be converted. (std::string, name) (int, age)) +[heading Example: BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED] + namespace demo + { + struct employee + { + std::string name; + int age; + }; + } + + // boost::fusion::adapted::adapted_employee is now a Fusion sequence + // referring to demo::employee + BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED( + demo::employee, adapted_employee, + (name) + (age)) + [endsect] -[section:adapt_assoc BOOST_FUSION_ADAPT_ASSOC_STRUCT] +[section:adapt_assoc BOOST_FUSION_ \[AUTO_\] ADAPT_ASSOC_STRUCT] [heading Description] BOOST_FUSION_ADAPT_ASSOC_STRUCT is a macro that can be used to generate all the @@ -367,13 +433,24 @@ __random_access_sequence__ and __associative_sequence__. ... ) + BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT( + struct_name, + (member_name0, key_type0) + (member_name1, key_type1) + ... + ) + [heading Semantics] The above macro generates the necessary code to adapt `struct_name` as a model of __random_access_sequence__ and __associative_sequence__. The sequence of `(member_typeN, member_nameN, key_typeN)` triples declares the type, name and key type of each of the struct members -that are part of the sequence. +that are part of the sequence. + +While BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT only allows specifying a sequence of +`(member_nameN, key_typeN)` as fields' types are deduced with +[@boost:/libs/typeof/index.html Boost.TypeOf]. The macro should be used at global scope, and `struct_name` should be the fully namespace qualified name of the struct to be adapted. @@ -381,9 +458,10 @@ namespace qualified name of the struct to be adapted. [heading Header] #include + #include #include -[heading Example] +[heading Example : BOOST_FUSION_ADAPT_ASSOC_STRUCT] namespace demo { struct employee @@ -407,6 +485,30 @@ namespace qualified name of the struct to be adapted. (std::string, name, keys::name) (int, age, keys::age)) +[heading Example : BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT] + namespace demo + { + struct employee + { + std::string name; + int age; + }; + } + + namespace keys + { + struct name; + struct age; + } + + // demo::employee is now a Fusion sequence. + // It is also an associative sequence with + // keys keys::name and keys::age present. + BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT( + demo::employee, + (name, keys::name) + (age, keys::age)) + [endsect] [section:adapt_assoc_tpl_struct BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT] @@ -475,7 +577,7 @@ namespace qualified name of the struct to be adapted. [endsect] -[section:adapt_assoc_struct_named BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED] +[section:adapt_assoc_struct_named BOOST_FUSION_ \[AUTO_\] ADAPT_ASSOC_STRUCT_NAMED] [heading Description] BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED and BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS are @@ -491,6 +593,13 @@ __associative_sequence__. The given struct is adapted using the given name. ... ) + BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED( + struct_name, adapted_name, + (member_name0, key_type0) + (member_name1, key_type1) + ... + ) + BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS( struct_name, (namespace0)(namespace1)..., @@ -500,6 +609,15 @@ __associative_sequence__. The given struct is adapted using the given name. ... ) + BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_NS( + struct_name, + (namespace0)(namespace1)..., + adapted_name, + (member_name0, key_type0) + (member_name1, key_type1) + ... + ) + [heading Semantics] The above macros generate the necessary code to adapt `struct_name` @@ -516,15 +634,20 @@ The sequence of `(member_typeN, member_nameN, key_typeN)` triples declares the type, name and key type of each of the struct members that are part of the sequence. +While BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED only allows specifying a +sequence of `(member_nameN, key_typeN)` as fields' types are deduced with +[@boost:/libs/typeof/index.html Boost.TypeOf]. + The macros should be used at global scope, and `struct_name` should be the fully namespace qualified name of the struct to be converted. [heading Header] #include + #include #include -[heading Example] +[heading Example : BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED] namespace demo { struct employee @@ -547,6 +670,29 @@ namespace qualified name of the struct to be converted. (std::string, name, keys::name) (int, age, keys::age)) +[heading Example : BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED] + namespace demo + { + struct employee + { + std::string name; + int age; + }; + } + + namespace keys + { + struct name; + struct age; + } + + // boost::fusion::adapted::adapted_employee is now a Fusion sequence + // referring to demo::employee + BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED( + demo::employee, adapted_employee, + (name, keys::name) + (age, keys::age)) + [endsect] [section:adapt_adt BOOST_FUSION_ADAPT_ADT] From c052b4b452f101b9c1aa48acfe45e1aa7f483468 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 18 Mar 2014 23:33:10 +0100 Subject: [PATCH 14/37] FEATURE: Making BOOST_FUSION_AUTO_ADAPT_STRUCT variadic. --- .../adapted/struct/auto_adapt_struct.hpp | 30 ++++++++++++++++++- test/sequence/auto_adapt_struct.cpp | 7 ++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp index 08f47157..96e82999 100644 --- a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp @@ -11,6 +11,9 @@ #define BOOST_FUSION_ADAPTED_STRUCT_AUTO_ADAPT_STRUCT_HPP #include +#include +#include +#include #include @@ -19,10 +22,35 @@ #define BOOST_FUSION_AUTO_ADAPT_STRUCT_TYPE_DEDUCER(r, NAME, ATTRIBUTE) \ (BOOST_TYPEOF(NAME::ATTRIBUTE), ATTRIBUTE) -#define BOOST_FUSION_AUTO_ADAPT_STRUCT(NAME, ATTRIBUTES) \ +#define BOOST_FUSION_AUTO_ADAPT_STRUCT(...) \ + BOOST_FUSION_AUTO_ADAPT_STRUCT_BASE( \ + BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__), \ + BOOST_PP_SEQ_POP_FRONT(BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))) + +#define BOOST_FUSION_AUTO_ADAPT_STRUCT_BASE(NAME, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT(NAME, \ BOOST_PP_SEQ_FOR_EACH( \ BOOST_FUSION_AUTO_ADAPT_STRUCT_TYPE_DEDUCER, NAME, ATTRIBUTES) \ ) + + +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(X, Y) \ + ((X, Y)) BOOST_FUSION_ADAPT_STRUCT_FILLER_1 +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1(X, Y) \ + ((X, Y)) BOOST_FUSION_ADAPT_STRUCT_FILLER_0 +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END + +#define BOOST_FUSION_ADAPT_STRUCT(NAME, ATTRIBUTES) \ + BOOST_FUSION_ADAPT_STRUCT_BASE( \ + (0), \ + (0)(NAME), \ + struct_tag, \ + 0, \ + BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ + BOOST_FUSION_ADAPT_STRUCT_C) + + + #endif diff --git a/test/sequence/auto_adapt_struct.cpp b/test/sequence/auto_adapt_struct.cpp index 7007e49c..e7ce2890 100644 --- a/test/sequence/auto_adapt_struct.cpp +++ b/test/sequence/auto_adapt_struct.cpp @@ -57,10 +57,15 @@ namespace ns #endif } -BOOST_FUSION_AUTO_ADAPT_STRUCT( +/*BOOST_FUSION_AUTO_ADAPT_STRUCT( ns::point, (x) (y) +)*/ + +BOOST_FUSION_AUTO_ADAPT_STRUCT( + ns::point, + x, y ) #if !BOOST_WORKAROUND(__GNUC__,<4) From 3ca94f57626b16123fd0abe4865953a49beb988b Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 7 May 2014 08:57:28 +0200 Subject: [PATCH 15/37] DOC: Add some comments to help me understand the adapt macros. --- .../adapted/struct/detail/adapt_base.hpp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index db702ae1..29c1a288 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -118,7 +118,7 @@ > \ { \ typedef \ - BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) \ + BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) \ //TODO: DAM Typeof can be added here attribute_type; \ BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ TEMPLATE_PARAMS_SEQ) \ @@ -167,6 +167,24 @@ } \ }; +/** + * \brief Creates a Random Access Sequence for the struct/class named NAME_SEQ + * \param TEMPLATE_PARAMS_SEQ + * \param NAME_SEQ Sequence of a boolean telling if the type is a template type + * or not, followed by the name of the type to be adapted. + * + * That is (0)(mystruct) means adaptation of mystruct a + * non-template type. While (1)(my_tpl_struct) means adaptation + * of a template based struct. + * \param TAG The tag of the Random Access Sequence, this enables to select the + * implementation of the sequence. + * \param IS_VIEW Whether if this creates a sequence of a view from a sequence + * \param ATTRIBUTES_SEQ Sequence of struct attributes to add to the list of + * adapted elements + * \param ATTRIBUTES_CALLBACK Macro callback used to register the attributes into + * the sequence. Usually a call to + * BOOST_FUSION_ADAPT_STRUCT_C_BASE. + */ #define BOOST_FUSION_ADAPT_STRUCT_BASE( \ TEMPLATE_PARAMS_SEQ, \ NAME_SEQ, \ From 7e1c6cdf479fa81bc4b39ad79ebda97a04d1d198 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Fri, 9 May 2014 13:25:38 +0200 Subject: [PATCH 16/37] FEATURE: Type deduction for BOOST_FUSION_ADAPT_STRUCT_C_BASE, with preliminary support for providing or deducing the type. --- .../fusion/adapted/struct/adapt_struct.hpp | 41 +++++++++++++++++++ .../adapted/struct/detail/adapt_base.hpp | 18 +++++++- test/sequence/adapt_struct.cpp | 14 +++---- 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index f60ca03e..cb117781 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -6,12 +6,16 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ +#define BOOST_PP_VARIADICS 1 + #ifndef BOOST_FUSION_ADAPTED_STRUCT_ADAPT_STRUCT_HPP #define BOOST_FUSION_ADAPTED_STRUCT_ADAPT_STRUCT_HPP #include #include #include +#include +#include #include #include #include @@ -41,6 +45,15 @@ BOOST_FUSION_ADAPT_STRUCT_C_BASE( \ TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,BOOST_PP_EMPTY,ATTRIBUTE,2) +#define BOOST_FUSION_ADAPT_STRUCT_C_AUTO(TEMPLATE_PARAMS_SEQ, NAME_SEQ, I, ATTRIBUTE) \ + BOOST_FUSION_ADAPT_STRUCT_C_BASE( \ + TEMPLATE_PARAMS_SEQ, \ + NAME_SEQ, \ + I, \ + BOOST_PP_EMPTY, \ + ATTRIBUTE, \ + 1) + #define BOOST_FUSION_ADAPT_TPL_STRUCT(TEMPLATE_PARAMS_SEQ,NAME_SEQ, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ (1)TEMPLATE_PARAMS_SEQ, \ @@ -60,6 +73,34 @@ BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ BOOST_FUSION_ADAPT_STRUCT_C) + + + + + +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0(...) \ + ((__VA_ARGS__)) BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1 +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1(...) \ + ((__VA_ARGS__)) BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0 +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0_END +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1_END + + +#define BOOST_FUSION_ADAPT_STRUCT_NEWAPI(NAME, ATTRIBUTES) \ + BOOST_FUSION_ADAPT_STRUCT_BASE( \ + (0), \ + (0)(NAME), \ + struct_tag, \ + 0, \ + BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0(0,0)ATTRIBUTES,_END), \ + BOOST_FUSION_ADAPT_STRUCT_C_AUTO) + + + + + + + #define BOOST_FUSION_ADAPT_STRUCT_AS_VIEW(NAME, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ (0), \ diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index 29c1a288..344da922 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -31,6 +31,9 @@ #include #include +#include + + #define BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME_TEMPLATE_PARAMS(SEQ) \ BOOST_PP_SEQ_HEAD(SEQ) \ BOOST_PP_EMPTY() @@ -55,6 +58,13 @@ BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS_IMPL, \ BOOST_PP_TUPLE_EAT(1))(SEQ) +#define BOOST_FUSION_ATTRIBUTE_TYPE_DEDUCE(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE)\ + BOOST_TYPEOF(BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)::BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) \ + ) + +#define BOOST_FUSION_GET_GIVEN_TYPE(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ + BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) + #ifdef BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS # define BOOST_FUSION_ADAPT_STRUCT_TAG_OF_SPECIALIZATION( \ MODIFIER, TEMPLATE_PARAMS_SEQ, NAME_SEQ, TAG) \ @@ -118,7 +128,9 @@ > \ { \ typedef \ - BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) \ //TODO: DAM Typeof can be added here + BOOST_PP_IF(BOOST_PP_LESS(/*ATTRIBUTE_TUPEL_SIZE*/1,2), \ + BOOST_FUSION_ATTRIBUTE_TYPE_DEDUCE, BOOST_FUSION_GET_GIVEN_TYPE \ + )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ attribute_type; \ BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ TEMPLATE_PARAMS_SEQ) \ @@ -143,7 +155,9 @@ call(Seq& seq) \ { \ return seq.PREFIX() \ - BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE); \ + BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, \ + BOOST_PP_IF(BOOST_PP_LESS(ATTRIBUTE_TUPEL_SIZE,2), 0, 1),\ + ATTRIBUTE); \ } \ }; \ }; \ diff --git a/test/sequence/adapt_struct.cpp b/test/sequence/adapt_struct.cpp index 68240463..1faa7bc3 100644 --- a/test/sequence/adapt_struct.cpp +++ b/test/sequence/adapt_struct.cpp @@ -56,22 +56,22 @@ namespace ns #endif } -BOOST_FUSION_ADAPT_STRUCT( +BOOST_FUSION_ADAPT_STRUCT_NEWAPI( ns::point, - (int, x) - (int, y) + (x) + (y) ) #if !BOOST_WORKAROUND(__GNUC__,<4) -BOOST_FUSION_ADAPT_STRUCT( +BOOST_FUSION_ADAPT_STRUCT_NEWAPI( ns::point_with_private_attributes, - (int, x) - (int, y) + (x) + (y) ) #endif struct s { int m; }; -BOOST_FUSION_ADAPT_STRUCT(s, (int, m)) +BOOST_FUSION_ADAPT_STRUCT_NEWAPI(s, (m)) int main() From 703bff4ff9e2402d0b0160c8e11115c0e6c055ee Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Fri, 9 May 2014 13:59:49 +0200 Subject: [PATCH 17/37] FEATURE: Types of a struct can freely pe provided or deduced, following the user preferences. --- include/boost/fusion/adapted/struct/adapt_struct.hpp | 8 ++++---- include/boost/fusion/adapted/struct/detail/adapt_base.hpp | 2 +- test/sequence/adapt_struct.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index cb117781..e4cc3d6c 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -51,8 +51,8 @@ NAME_SEQ, \ I, \ BOOST_PP_EMPTY, \ - ATTRIBUTE, \ - 1) + BOOST_PP_TUPLE_ELEM(1, ATTRIBUTE), \ + BOOST_PP_TUPLE_ELEM(0, ATTRIBUTE)) #define BOOST_FUSION_ADAPT_TPL_STRUCT(TEMPLATE_PARAMS_SEQ,NAME_SEQ, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ @@ -79,9 +79,9 @@ #define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0(...) \ - ((__VA_ARGS__)) BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1 + ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1 #define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1(...) \ - ((__VA_ARGS__)) BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0 + ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0 #define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0_END #define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1_END diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index 344da922..700c3dea 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -128,7 +128,7 @@ > \ { \ typedef \ - BOOST_PP_IF(BOOST_PP_LESS(/*ATTRIBUTE_TUPEL_SIZE*/1,2), \ + BOOST_PP_IF(BOOST_PP_LESS(ATTRIBUTE_TUPEL_SIZE,2), \ BOOST_FUSION_ATTRIBUTE_TYPE_DEDUCE, BOOST_FUSION_GET_GIVEN_TYPE \ )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ attribute_type; \ diff --git a/test/sequence/adapt_struct.cpp b/test/sequence/adapt_struct.cpp index 1faa7bc3..65d2c4b2 100644 --- a/test/sequence/adapt_struct.cpp +++ b/test/sequence/adapt_struct.cpp @@ -59,7 +59,7 @@ namespace ns BOOST_FUSION_ADAPT_STRUCT_NEWAPI( ns::point, (x) - (y) + (int, y) ) #if !BOOST_WORKAROUND(__GNUC__,<4) From 04cbf0d4c651a2b8fb6bae5235a04cffc9a93247 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Fri, 9 May 2014 14:06:15 +0200 Subject: [PATCH 18/37] BUGFIX: Presents the correct field name as a string even if type is deduced. --- include/boost/fusion/adapted/struct/detail/adapt_base.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index 700c3dea..ff83da0d 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -177,7 +177,9 @@ call() \ { \ return BOOST_PP_STRINGIZE( \ - BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE,1,ATTRIBUTE)); \ + BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, \ + BOOST_PP_IF(BOOST_PP_LESS(ATTRIBUTE_TUPEL_SIZE,2), 0, 1),\ + ATTRIBUTE)); \ } \ }; From 6f6bfb3a27d0061d1f8180c1b865692ee9f83228 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 14 May 2014 00:02:52 +0200 Subject: [PATCH 19/37] EDITORIAL: Cleaning the ADAPT_STRUCT which can deduce types. --- .../fusion/adapted/struct/adapt_struct.hpp | 52 +++++-------------- test/sequence/adapt_struct.cpp | 10 ++-- 2 files changed, 19 insertions(+), 43 deletions(-) diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index e4cc3d6c..2633350a 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -41,17 +41,21 @@ #define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END #define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END +//TODO: DAM remove need for variadic macros. +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0(...) \ + ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1 +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1(...) \ + ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0 +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0_END +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1_END + #define BOOST_FUSION_ADAPT_STRUCT_C(TEMPLATE_PARAMS_SEQ, NAME_SEQ, I, ATTRIBUTE)\ BOOST_FUSION_ADAPT_STRUCT_C_BASE( \ - TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,BOOST_PP_EMPTY,ATTRIBUTE,2) - -#define BOOST_FUSION_ADAPT_STRUCT_C_AUTO(TEMPLATE_PARAMS_SEQ, NAME_SEQ, I, ATTRIBUTE) \ - BOOST_FUSION_ADAPT_STRUCT_C_BASE( \ - TEMPLATE_PARAMS_SEQ, \ - NAME_SEQ, \ - I, \ - BOOST_PP_EMPTY, \ - BOOST_PP_TUPLE_ELEM(1, ATTRIBUTE), \ + TEMPLATE_PARAMS_SEQ, \ + NAME_SEQ, \ + I, \ + BOOST_PP_EMPTY, \ + BOOST_PP_TUPLE_ELEM(1, ATTRIBUTE), \ BOOST_PP_TUPLE_ELEM(0, ATTRIBUTE)) #define BOOST_FUSION_ADAPT_TPL_STRUCT(TEMPLATE_PARAMS_SEQ,NAME_SEQ, ATTRIBUTES) \ @@ -65,41 +69,13 @@ BOOST_FUSION_ADAPT_STRUCT_C) #define BOOST_FUSION_ADAPT_STRUCT(NAME, ATTRIBUTES) \ - BOOST_FUSION_ADAPT_STRUCT_BASE( \ - (0), \ - (0)(NAME), \ - struct_tag, \ - 0, \ - BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ - BOOST_FUSION_ADAPT_STRUCT_C) - - - - - - -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0(...) \ - ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1 -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1(...) \ - ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0 -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0_END -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1_END - - -#define BOOST_FUSION_ADAPT_STRUCT_NEWAPI(NAME, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ (0), \ (0)(NAME), \ struct_tag, \ 0, \ BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0(0,0)ATTRIBUTES,_END), \ - BOOST_FUSION_ADAPT_STRUCT_C_AUTO) - - - - - - + BOOST_FUSION_ADAPT_STRUCT_C) #define BOOST_FUSION_ADAPT_STRUCT_AS_VIEW(NAME, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ diff --git a/test/sequence/adapt_struct.cpp b/test/sequence/adapt_struct.cpp index 65d2c4b2..f2da12f7 100644 --- a/test/sequence/adapt_struct.cpp +++ b/test/sequence/adapt_struct.cpp @@ -56,22 +56,22 @@ namespace ns #endif } -BOOST_FUSION_ADAPT_STRUCT_NEWAPI( +BOOST_FUSION_ADAPT_STRUCT( ns::point, (x) (int, y) ) #if !BOOST_WORKAROUND(__GNUC__,<4) -BOOST_FUSION_ADAPT_STRUCT_NEWAPI( +BOOST_FUSION_ADAPT_STRUCT( ns::point_with_private_attributes, - (x) - (y) + (int, x) + (int, y) ) #endif struct s { int m; }; -BOOST_FUSION_ADAPT_STRUCT_NEWAPI(s, (m)) +BOOST_FUSION_ADAPT_STRUCT(s, (m)) int main() From 944c363787ff4c6addae07656c47c330962aca03 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 27 May 2014 22:48:19 +0200 Subject: [PATCH 20/37] Remove dependency to variadics macros for the old API not deducing types. --- .../fusion/adapted/struct/adapt_struct.hpp | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index 2633350a..bf5655a9 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -6,16 +6,16 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#define BOOST_PP_VARIADICS 1 +//#define BOOST_PP_VARIADICS #ifndef BOOST_FUSION_ADAPTED_STRUCT_ADAPT_STRUCT_HPP #define BOOST_FUSION_ADAPTED_STRUCT_ADAPT_STRUCT_HPP #include + #include #include -#include -#include +#include #include #include #include @@ -34,20 +34,29 @@ #include #include -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(X, Y) \ - ((X, Y)) BOOST_FUSION_ADAPT_STRUCT_FILLER_1 -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1(X, Y) \ - ((X, Y)) BOOST_FUSION_ADAPT_STRUCT_FILLER_0 +//TODO: Write a variadic version full : with variadic also directly to provide the fields. +#if BOOST_PP_VARIADICS + +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(...) \ + ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) \ + BOOST_FUSION_ADAPT_STRUCT_FILLER_1 +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1(...) \ + ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) \ + BOOST_FUSION_ADAPT_STRUCT_FILLER_0 + #define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END #define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END -//TODO: DAM remove need for variadic macros. -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0(...) \ - ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1 -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1(...) \ - ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0 -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0_END -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__1_END +#else + +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(X, Y) \ + ((2, (X, Y))) BOOST_FUSION_ADAPT_STRUCT_FILLER_1 +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1(X, Y) \ + ((2, (X, Y))) BOOST_FUSION_ADAPT_STRUCT_FILLER_0 +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END + +#endif #define BOOST_FUSION_ADAPT_STRUCT_C(TEMPLATE_PARAMS_SEQ, NAME_SEQ, I, ATTRIBUTE)\ BOOST_FUSION_ADAPT_STRUCT_C_BASE( \ @@ -55,8 +64,8 @@ NAME_SEQ, \ I, \ BOOST_PP_EMPTY, \ - BOOST_PP_TUPLE_ELEM(1, ATTRIBUTE), \ - BOOST_PP_TUPLE_ELEM(0, ATTRIBUTE)) + BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE), \ + BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE)) #define BOOST_FUSION_ADAPT_TPL_STRUCT(TEMPLATE_PARAMS_SEQ,NAME_SEQ, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ @@ -74,7 +83,7 @@ (0)(NAME), \ struct_tag, \ 0, \ - BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_NEWAPI__0(0,0)ATTRIBUTES,_END), \ + BOOST_PP_CAT( BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ BOOST_FUSION_ADAPT_STRUCT_C) #define BOOST_FUSION_ADAPT_STRUCT_AS_VIEW(NAME, ATTRIBUTES) \ From 37fc1443adc247fddec82f2521db37d737f8010f Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Fri, 30 May 2014 17:44:49 +0200 Subject: [PATCH 21/37] Improve the BOOST_FUSION_ADAPT_STRUCT macro to work also when there is no variadic support. This enable the following flexible macro signature when there is no BOOST_PP_VARIADICS support: BOOST_FUSION_ADAPT_STRUCT( struct_name, (member_type0, member_name0) (BOOST_FUSION_ADAPT_AUTO, member_name1) (,member_name2) ... ) If BOOST_PP_VARIADICS is active then there is quite more flexibility as it allows to avoid the type specification: BOOST_FUSION_ADAPT_STRUCT( struct_name, (member_type0, member_name0) (BOOST_FUSION_ADAPT_AUTO, member_name1) (,member_name2) (member_name3) ... ) --- .../fusion/adapted/struct/adapt_struct.hpp | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index bf5655a9..06927e9e 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -6,16 +6,17 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -//#define BOOST_PP_VARIADICS - #ifndef BOOST_FUSION_ADAPTED_STRUCT_ADAPT_STRUCT_HPP #define BOOST_FUSION_ADAPTED_STRUCT_ADAPT_STRUCT_HPP #include - +#include +#include #include #include -#include +#include +#include +#include #include #include #include @@ -34,29 +35,49 @@ #include #include -//TODO: Write a variadic version full : with variadic also directly to provide the fields. #if BOOST_PP_VARIADICS +#define BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(...) \ + BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), 2), \ + BOOST_PP_IF(BOOST_PP_IS_EMPTY(BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__)), \ + ((1, (BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__)) )), \ + ((2, BOOST_PP_VARIADIC_TO_TUPLE(__VA_ARGS__))) \ + ), \ + ((1, (BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__)) )) \ + ) + #define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(...) \ - ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) \ + BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(__VA_ARGS__) \ BOOST_FUSION_ADAPT_STRUCT_FILLER_1 #define BOOST_FUSION_ADAPT_STRUCT_FILLER_1(...) \ - ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) \ + BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(__VA_ARGS__) \ BOOST_FUSION_ADAPT_STRUCT_FILLER_0 #define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END #define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END -#else +#else // BOOST_PP_VARIADICS + +#define BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(X, Y) \ + BOOST_PP_IF(BOOST_PP_IS_EMPTY(X), \ + ((1, (Y))), \ + ((2, (X,Y))) \ + ) #define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(X, Y) \ - ((2, (X, Y))) BOOST_FUSION_ADAPT_STRUCT_FILLER_1 + BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(X,Y) \ + BOOST_FUSION_ADAPT_STRUCT_FILLER_1 + #define BOOST_FUSION_ADAPT_STRUCT_FILLER_1(X, Y) \ - ((2, (X, Y))) BOOST_FUSION_ADAPT_STRUCT_FILLER_0 + BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(X,Y) \ + BOOST_FUSION_ADAPT_STRUCT_FILLER_0 + #define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END #define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END -#endif +#endif // BOOST_PP_VARIADICS + +#define BOOST_FUSION_ADAPT_AUTO BOOST_PP_EMPTY() #define BOOST_FUSION_ADAPT_STRUCT_C(TEMPLATE_PARAMS_SEQ, NAME_SEQ, I, ATTRIBUTE)\ BOOST_FUSION_ADAPT_STRUCT_C_BASE( \ From 02b776360ae1b69eda9745ede2c07e6a7187c6b1 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 4 Jun 2014 01:36:15 +0200 Subject: [PATCH 22/37] FEATURE: BOOST_FUSION_ADAPT_STRUCT can now also be called completely with variadics arguments. The following signature is possible : BOOST_FUSION_ADAPT_STRUCT( struct_name, member_name0, (BOOST_FUSION_ADAPT_AUTO, member_name1) (member_type2, member_name2) member_name3, ... ) --- .../fusion/adapted/struct/adapt_struct.hpp | 30 ++++++++++++++ .../struct/detail/preprocessor/is_seq.hpp | 41 +++++++++++++++++++ test/sequence/adapt_struct.cpp | 30 ++++++++------ 3 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 include/boost/fusion/adapted/struct/detail/preprocessor/is_seq.hpp diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index 06927e9e..bc2c56e4 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -34,6 +37,7 @@ #include #include #include +#include #if BOOST_PP_VARIADICS @@ -98,6 +102,30 @@ BOOST_FUSION_ADAPT_STRUCT_FILLER_0 ATTRIBUTES,_END), \ BOOST_FUSION_ADAPT_STRUCT_C) + +#if BOOST_PP_VARIADICS + +#define BOOST_FUSION_ADAPT_STRUCT_PROCESS_PARAM(r, data, elem) \ + BOOST_PP_IF(BOOST_FUSION_PP_IS_SEQ(elem), \ + BOOST_PP_CAT( BOOST_FUSION_ADAPT_STRUCT_FILLER_0 elem ,_END), \ + BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(elem) \ + ) + +#define BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE_FROM_VARIADICS(...) \ + BOOST_PP_SEQ_PUSH_FRONT( \ + BOOST_PP_SEQ_FOR_EACH(BOOST_FUSION_ADAPT_STRUCT_PROCESS_PARAM, unused, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)), (0,0)) + +#define BOOST_FUSION_ADAPT_STRUCT(NAME, ...) \ + BOOST_FUSION_ADAPT_STRUCT_BASE( \ + (0), \ + (0)(NAME), \ + struct_tag, \ + 0, \ + BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE_FROM_VARIADICS(__VA_ARGS__), \ + BOOST_FUSION_ADAPT_STRUCT_C) + +#else // BOOST_PP_VARIADICS + #define BOOST_FUSION_ADAPT_STRUCT(NAME, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ (0), \ @@ -107,6 +135,8 @@ BOOST_PP_CAT( BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ BOOST_FUSION_ADAPT_STRUCT_C) +#endif // BOOST_PP_VARIADICS + #define BOOST_FUSION_ADAPT_STRUCT_AS_VIEW(NAME, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ (0), \ diff --git a/include/boost/fusion/adapted/struct/detail/preprocessor/is_seq.hpp b/include/boost/fusion/adapted/struct/detail/preprocessor/is_seq.hpp new file mode 100644 index 00000000..95f11050 --- /dev/null +++ b/include/boost/fusion/adapted/struct/detail/preprocessor/is_seq.hpp @@ -0,0 +1,41 @@ +/*============================================================================= + BOOST_PP_VARIADICS version of BOOST_PP_IS_SEQ inspired from + boost/mpl/aux_/preprocessor/is_seq.hpp, original copyrights goes to : + + Copyright Paul Mensonides 2003 + Copyright Aleksey Gurtovoy 2003-2004 + + 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_ADAPTED_STRUCT_DETAIL_PREPROCESSOR_IS_SEQ_HPP +#define BOOST_FUSION_ADAPTED_STRUCT_DETAIL_PREPROCESSOR_IS_SEQ_HPP + +#include +#include +#include +#include +#include + +#if BOOST_PP_VARIADICS + +#define BOOST_FUSION_PP_IS_SEQ(seq) BOOST_PP_CAT(BOOST_FUSION_PP_IS_SEQ_, \ + BOOST_FUSION_PP_IS_SEQ_0 seq BOOST_PP_RPAREN()) + +#define BOOST_FUSION_PP_IS_SEQ_0(...) \ + BOOST_FUSION_PP_IS_SEQ_1(__VA_ARGS__ + +#define BOOST_FUSION_PP_IS_SEQ_ALWAYS_0(...) \ + 0 + +#define BOOST_FUSION_PP_IS_SEQ_BOOST_FUSION_PP_IS_SEQ_0 \ + BOOST_FUSION_PP_IS_SEQ_ALWAYS_0( + +#define BOOST_FUSION_PP_IS_SEQ_BOOST_FUSION_PP_IS_SEQ_1(...) \ + 1 + +#endif // BOOST_PP_VARIADICS + +#endif diff --git a/test/sequence/adapt_struct.cpp b/test/sequence/adapt_struct.cpp index f2da12f7..ca1770a4 100644 --- a/test/sequence/adapt_struct.cpp +++ b/test/sequence/adapt_struct.cpp @@ -4,6 +4,8 @@ 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) ==============================================================================*/ +#define BOOST_PP_VARIADICS 1 + #include #include #include @@ -38,6 +40,7 @@ namespace ns { int x; int y; + int z; }; #if !BOOST_WORKAROUND(__GNUC__,<4) @@ -58,8 +61,9 @@ namespace ns BOOST_FUSION_ADAPT_STRUCT( ns::point, - (x) - (int, y) + (int, x) + (int, y), + z ) #if !BOOST_WORKAROUND(__GNUC__,<4) @@ -71,7 +75,7 @@ BOOST_FUSION_ADAPT_STRUCT( #endif struct s { int m; }; -BOOST_FUSION_ADAPT_STRUCT(s, (m)) +BOOST_FUSION_ADAPT_STRUCT(s, (int, m)) int main() @@ -90,13 +94,13 @@ main() std::cout << at_c<0>(p) << std::endl; std::cout << at_c<1>(p) << std::endl; std::cout << p << std::endl; - BOOST_TEST(p == make_vector(123, 456)); + BOOST_TEST(p == make_vector(123, 456, 4)); at_c<0>(p) = 6; at_c<1>(p) = 9; - BOOST_TEST(p == make_vector(6, 9)); + BOOST_TEST(p == make_vector(6, 9, 12)); - BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 2); + BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 3); BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); BOOST_TEST(front(p) == 6); @@ -104,9 +108,9 @@ main() } { - fusion::vector v1(4, 2); - ns::point v2 = {5, 3}; - fusion::vector v3(5, 4); + fusion::vector v1(4, 2, 3); + ns::point v2 = {5, 3, 2}; + fusion::vector v3(5, 4, 2); BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); @@ -119,15 +123,15 @@ main() { // conversion from ns::point to vector - ns::point p = {5, 3}; - fusion::vector v(p); + ns::point p = {5, 3, 4}; + fusion::vector v(p); v = p; } { // conversion from ns::point to list - ns::point p = {5, 3}; - fusion::list l(p); + ns::point p = {5, 3, 4}; + fusion::list l(p); l = p; } From 7ef202b79430bb2f91f58adb59c585415a3bb66a Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 10 Jun 2014 22:15:08 +0200 Subject: [PATCH 23/37] Moved BOOST_FUSION_ADAPT_STRUCT implementation details to detail/adapt_base.hpp --- .../fusion/adapted/struct/adapt_struct.hpp | 90 ++++--------------- .../adapted/struct/auto_adapt_struct.hpp | 56 ------------ .../adapted/struct/detail/adapt_base.hpp | 72 ++++++++++----- 3 files changed, 71 insertions(+), 147 deletions(-) delete mode 100644 include/boost/fusion/adapted/struct/auto_adapt_struct.hpp diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index bc2c56e4..a5688e0d 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -1,6 +1,7 @@ /*============================================================================= Copyright (c) 2001-2007 Joel de Guzman Copyright (c) 2009-2011 Christopher Schmidt + Copyright (c) 2013-2014 Damien Buhl 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) @@ -17,8 +18,6 @@ #include #include #include -#include -#include #include #include #include @@ -37,49 +36,6 @@ #include #include #include -#include - -#if BOOST_PP_VARIADICS - -#define BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(...) \ - BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), 2), \ - BOOST_PP_IF(BOOST_PP_IS_EMPTY(BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__)), \ - ((1, (BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__)) )), \ - ((2, BOOST_PP_VARIADIC_TO_TUPLE(__VA_ARGS__))) \ - ), \ - ((1, (BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__)) )) \ - ) - -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(...) \ - BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(__VA_ARGS__) \ - BOOST_FUSION_ADAPT_STRUCT_FILLER_1 -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1(...) \ - BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(__VA_ARGS__) \ - BOOST_FUSION_ADAPT_STRUCT_FILLER_0 - -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END - -#else // BOOST_PP_VARIADICS - -#define BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(X, Y) \ - BOOST_PP_IF(BOOST_PP_IS_EMPTY(X), \ - ((1, (Y))), \ - ((2, (X,Y))) \ - ) - -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(X, Y) \ - BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(X,Y) \ - BOOST_FUSION_ADAPT_STRUCT_FILLER_1 - -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1(X, Y) \ - BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(X,Y) \ - BOOST_FUSION_ADAPT_STRUCT_FILLER_0 - -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END - -#endif // BOOST_PP_VARIADICS #define BOOST_FUSION_ADAPT_AUTO BOOST_PP_EMPTY() @@ -105,35 +61,27 @@ #if BOOST_PP_VARIADICS -#define BOOST_FUSION_ADAPT_STRUCT_PROCESS_PARAM(r, data, elem) \ - BOOST_PP_IF(BOOST_FUSION_PP_IS_SEQ(elem), \ - BOOST_PP_CAT( BOOST_FUSION_ADAPT_STRUCT_FILLER_0 elem ,_END), \ - BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE(elem) \ - ) - -#define BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE_FROM_VARIADICS(...) \ - BOOST_PP_SEQ_PUSH_FRONT( \ - BOOST_PP_SEQ_FOR_EACH(BOOST_FUSION_ADAPT_STRUCT_PROCESS_PARAM, unused, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)), (0,0)) - -#define BOOST_FUSION_ADAPT_STRUCT(NAME, ...) \ - BOOST_FUSION_ADAPT_STRUCT_BASE( \ - (0), \ - (0)(NAME), \ - struct_tag, \ - 0, \ - BOOST_FUSION_ADAPT_STRUCT_CREATE_MEMBER_TUPLE_FROM_VARIADICS(__VA_ARGS__), \ - BOOST_FUSION_ADAPT_STRUCT_C) +# define BOOST_FUSION_ADAPT_STRUCT(NAME, ...) \ + BOOST_FUSION_ADAPT_STRUCT_BASE( \ + (0), \ + (0)(NAME), \ + struct_tag, \ + 0, \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER(__VA_ARGS__), \ + BOOST_FUSION_ADAPT_STRUCT_C) #else // BOOST_PP_VARIADICS -#define BOOST_FUSION_ADAPT_STRUCT(NAME, ATTRIBUTES) \ - BOOST_FUSION_ADAPT_STRUCT_BASE( \ - (0), \ - (0)(NAME), \ - struct_tag, \ - 0, \ - BOOST_PP_CAT( BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ - BOOST_FUSION_ADAPT_STRUCT_C) +# define BOOST_FUSION_ADAPT_STRUCT(NAME, ATTRIBUTES) \ + BOOST_FUSION_ADAPT_STRUCT_BASE( \ + (0), \ + (0)(NAME), \ + struct_tag, \ + 0, \ + BOOST_PP_CAT( \ + BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES, \ + _END), \ + BOOST_FUSION_ADAPT_STRUCT_C) #endif // BOOST_PP_VARIADICS diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp deleted file mode 100644 index 96e82999..00000000 --- a/include/boost/fusion/adapted/struct/auto_adapt_struct.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/*============================================================================= - Copyright (c) 2001-2007 Joel de Guzman - Copyright (c) 2009-2011 Christopher Schmidt - Copyright (c) 2013-2014 Damien Buhl - - 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_ADAPTED_STRUCT_AUTO_ADAPT_STRUCT_HPP -#define BOOST_FUSION_ADAPTED_STRUCT_AUTO_ADAPT_STRUCT_HPP - -#include -#include -#include -#include - -#include - -#include - -#define BOOST_FUSION_AUTO_ADAPT_STRUCT_TYPE_DEDUCER(r, NAME, ATTRIBUTE) \ - (BOOST_TYPEOF(NAME::ATTRIBUTE), ATTRIBUTE) - -#define BOOST_FUSION_AUTO_ADAPT_STRUCT(...) \ - BOOST_FUSION_AUTO_ADAPT_STRUCT_BASE( \ - BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__), \ - BOOST_PP_SEQ_POP_FRONT(BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))) - -#define BOOST_FUSION_AUTO_ADAPT_STRUCT_BASE(NAME, ATTRIBUTES) \ - BOOST_FUSION_ADAPT_STRUCT(NAME, \ - BOOST_PP_SEQ_FOR_EACH( \ - BOOST_FUSION_AUTO_ADAPT_STRUCT_TYPE_DEDUCER, NAME, ATTRIBUTES) \ - ) - - - -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(X, Y) \ - ((X, Y)) BOOST_FUSION_ADAPT_STRUCT_FILLER_1 -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1(X, Y) \ - ((X, Y)) BOOST_FUSION_ADAPT_STRUCT_FILLER_0 -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END - -#define BOOST_FUSION_ADAPT_STRUCT(NAME, ATTRIBUTES) \ - BOOST_FUSION_ADAPT_STRUCT_BASE( \ - (0), \ - (0)(NAME), \ - struct_tag, \ - 0, \ - BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ - BOOST_FUSION_ADAPT_STRUCT_C) - - - -#endif diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index ff83da0d..ee3c5ff2 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -2,6 +2,7 @@ Copyright (c) 2001-2009 Joel de Guzman Copyright (c) 2005-2006 Dan Marsden Copyright (c) 2009-2011 Christopher Schmidt + Copyright (c) 2013-2014 Damien Buhl 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) @@ -13,6 +14,7 @@ #include #include #include +#include #include #include @@ -25,14 +27,14 @@ #include #include #include +#include #include #include #include #include #include -#include - +#include #define BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME_TEMPLATE_PARAMS(SEQ) \ BOOST_PP_SEQ_HEAD(SEQ) \ @@ -183,24 +185,54 @@ } \ }; -/** - * \brief Creates a Random Access Sequence for the struct/class named NAME_SEQ - * \param TEMPLATE_PARAMS_SEQ - * \param NAME_SEQ Sequence of a boolean telling if the type is a template type - * or not, followed by the name of the type to be adapted. - * - * That is (0)(mystruct) means adaptation of mystruct a - * non-template type. While (1)(my_tpl_struct) means adaptation - * of a template based struct. - * \param TAG The tag of the Random Access Sequence, this enables to select the - * implementation of the sequence. - * \param IS_VIEW Whether if this creates a sequence of a view from a sequence - * \param ATTRIBUTES_SEQ Sequence of struct attributes to add to the list of - * adapted elements - * \param ATTRIBUTES_CALLBACK Macro callback used to register the attributes into - * the sequence. Usually a call to - * BOOST_FUSION_ADAPT_STRUCT_C_BASE. - */ +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(X, Y) \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(X,Y) \ + BOOST_FUSION_ADAPT_STRUCT_FILLER_1 + +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1(X, Y) \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(X,Y) \ + BOOST_FUSION_ADAPT_STRUCT_FILLER_0 + +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END + +#if BOOST_PP_VARIADICS + +# define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(...) \ + BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), 2), \ + BOOST_PP_IF( \ + BOOST_PP_IS_EMPTY(BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__)), \ + ((1, (BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__)) )), \ + ((2, BOOST_PP_VARIADIC_TO_TUPLE(__VA_ARGS__)))), \ + ((1, (BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__)) ))) + +# define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER_OP(r, data, elem) \ + BOOST_PP_IF(BOOST_FUSION_PP_IS_SEQ(elem), \ + BOOST_PP_CAT( BOOST_FUSION_ADAPT_STRUCT_FILLER_0 elem ,_END), \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(elem) \ + ) + +# define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER(...) \ + BOOST_PP_SEQ_PUSH_FRONT( \ + BOOST_PP_SEQ_FOR_EACH( \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER_OP, \ + unused, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)), \ + (0,0) \ + ) + +#else // BOOST_PP_VARIADICS + +# define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(X, Y) \ + BOOST_PP_IF(BOOST_PP_IS_EMPTY(X), \ + ((1, (Y))), \ + ((2, (X,Y))) \ + ) + + + +#endif // BOOST_PP_VARIADICS + + #define BOOST_FUSION_ADAPT_STRUCT_BASE( \ TEMPLATE_PARAMS_SEQ, \ NAME_SEQ, \ From 557b3d2dc694f73b4d58791af67d8b1c608a2ae2 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 10 Jun 2014 23:45:43 +0200 Subject: [PATCH 24/37] Fix detection of member_type parameter emptiness for BOOST_FUSION_ADAPT_STRUCT. As BOOST_PP_IS_EMPTY is not a general purpose emptiness checker, we limit the ways it can be used. --- .../adapted/struct/detail/adapt_base.hpp | 27 ++++++------------- test/sequence/adapt_struct.cpp | 4 +-- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index ee3c5ff2..7d3f40dd 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -196,20 +196,19 @@ #define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END #define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END -#if BOOST_PP_VARIADICS +#define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(X, Y) \ + BOOST_PP_IF(BOOST_PP_IS_EMPTY(X), \ + ((1, (Y))), \ + ((2, (X,Y))) \ + ) -# define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(...) \ - BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), 2), \ - BOOST_PP_IF( \ - BOOST_PP_IS_EMPTY(BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__)), \ - ((1, (BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__)) )), \ - ((2, BOOST_PP_VARIADIC_TO_TUPLE(__VA_ARGS__)))), \ - ((1, (BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__)) ))) +#if BOOST_PP_VARIADICS # define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER_OP(r, data, elem) \ BOOST_PP_IF(BOOST_FUSION_PP_IS_SEQ(elem), \ BOOST_PP_CAT( BOOST_FUSION_ADAPT_STRUCT_FILLER_0 elem ,_END), \ - BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(elem) \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(BOOST_FUSION_ADAPT_AUTO, \ + elem) \ ) # define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER(...) \ @@ -220,16 +219,6 @@ (0,0) \ ) -#else // BOOST_PP_VARIADICS - -# define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(X, Y) \ - BOOST_PP_IF(BOOST_PP_IS_EMPTY(X), \ - ((1, (Y))), \ - ((2, (X,Y))) \ - ) - - - #endif // BOOST_PP_VARIADICS diff --git a/test/sequence/adapt_struct.cpp b/test/sequence/adapt_struct.cpp index ca1770a4..bb8c7cb3 100644 --- a/test/sequence/adapt_struct.cpp +++ b/test/sequence/adapt_struct.cpp @@ -62,8 +62,8 @@ namespace ns BOOST_FUSION_ADAPT_STRUCT( ns::point, (int, x) - (int, y), - z + (BOOST_FUSION_ADAPT_AUTO, y) + (, z) ) #if !BOOST_WORKAROUND(__GNUC__,<4) From c851252f652a0a794a148f3c7e83cfaf9be741bd Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 11 Jun 2014 00:03:22 +0200 Subject: [PATCH 25/37] Renaming macros for ADAPT_STRUCT to deduce type or take provided attribute types. --- .../fusion/adapted/struct/detail/adapt_base.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index 7d3f40dd..a17c4ef2 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -60,11 +60,15 @@ BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS_IMPL, \ BOOST_PP_TUPLE_EAT(1))(SEQ) -#define BOOST_FUSION_ATTRIBUTE_TYPE_DEDUCE(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE)\ - BOOST_TYPEOF(BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)::BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) \ - ) +#define BOOST_FUSION_ATTRIBUTE_TYPEOF( \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ + BOOST_TYPEOF( \ + BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ + :: \ + BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE)) \ -#define BOOST_FUSION_GET_GIVEN_TYPE(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ +#define BOOST_FUSION_ATTRIBUTE_GIVENTYPE( \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) #ifdef BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS @@ -131,7 +135,7 @@ { \ typedef \ BOOST_PP_IF(BOOST_PP_LESS(ATTRIBUTE_TUPEL_SIZE,2), \ - BOOST_FUSION_ATTRIBUTE_TYPE_DEDUCE, BOOST_FUSION_GET_GIVEN_TYPE \ + BOOST_FUSION_ATTRIBUTE_TYPEOF, BOOST_FUSION_ATTRIBUTE_GIVENTYPE \ )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ attribute_type; \ BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ From 687b2cf097046ed3d40128167e3f719d9b3691c2 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 11 Jun 2014 00:13:14 +0200 Subject: [PATCH 26/37] Factoring out of adapt_struct.hpp all the FILLER_* macros details. As of BOOST_FUSION_ADAPT_STRUCT without type deduction, there were only simple attributes filler. Now this need more complex logic to handle both API: the backward compatible one with type specificiation, the one without type specification and the non-variadic one which enables omitting the type specification by providing BOOST_FUSION_ADAPT_AUTO instead of the type. That's why I extracted the FILLER_* macros details in a separate source file. --- .../fusion/adapted/struct/adapt_struct.hpp | 8 +-- .../adapted/struct/detail/adapt_base.hpp | 40 +------------ .../struct/detail/adapt_base_attr_filler.hpp | 56 +++++++++++++++++++ 3 files changed, 59 insertions(+), 45 deletions(-) create mode 100644 include/boost/fusion/adapted/struct/detail/adapt_base_attr_filler.hpp diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index a5688e0d..58c4c4d6 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -12,10 +12,6 @@ #include #include -#include -#include -#include -#include #include #include #include @@ -37,8 +33,6 @@ #include #include -#define BOOST_FUSION_ADAPT_AUTO BOOST_PP_EMPTY() - #define BOOST_FUSION_ADAPT_STRUCT_C(TEMPLATE_PARAMS_SEQ, NAME_SEQ, I, ATTRIBUTE)\ BOOST_FUSION_ADAPT_STRUCT_C_BASE( \ TEMPLATE_PARAMS_SEQ, \ @@ -59,6 +53,8 @@ BOOST_FUSION_ADAPT_STRUCT_C) +#define BOOST_FUSION_ADAPT_AUTO BOOST_PP_EMPTY() + #if BOOST_PP_VARIADICS # define BOOST_FUSION_ADAPT_STRUCT(NAME, ...) \ diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index a17c4ef2..90bac86c 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -189,43 +188,6 @@ } \ }; -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(X, Y) \ - BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(X,Y) \ - BOOST_FUSION_ADAPT_STRUCT_FILLER_1 - -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1(X, Y) \ - BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(X,Y) \ - BOOST_FUSION_ADAPT_STRUCT_FILLER_0 - -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END - -#define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(X, Y) \ - BOOST_PP_IF(BOOST_PP_IS_EMPTY(X), \ - ((1, (Y))), \ - ((2, (X,Y))) \ - ) - -#if BOOST_PP_VARIADICS - -# define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER_OP(r, data, elem) \ - BOOST_PP_IF(BOOST_FUSION_PP_IS_SEQ(elem), \ - BOOST_PP_CAT( BOOST_FUSION_ADAPT_STRUCT_FILLER_0 elem ,_END), \ - BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(BOOST_FUSION_ADAPT_AUTO, \ - elem) \ - ) - -# define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER(...) \ - BOOST_PP_SEQ_PUSH_FRONT( \ - BOOST_PP_SEQ_FOR_EACH( \ - BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER_OP, \ - unused, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)), \ - (0,0) \ - ) - -#endif // BOOST_PP_VARIADICS - - #define BOOST_FUSION_ADAPT_STRUCT_BASE( \ TEMPLATE_PARAMS_SEQ, \ NAME_SEQ, \ diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base_attr_filler.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base_attr_filler.hpp new file mode 100644 index 00000000..4ad03a26 --- /dev/null +++ b/include/boost/fusion/adapted/struct/detail/adapt_base_attr_filler.hpp @@ -0,0 +1,56 @@ +/*============================================================================= + Copyright (c) 2013-2014 Damien Buhl + + 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_ADAPTED_STRUCT_DETAIL_ADAPT_BASE_ATTR_FILLER_HPP +#define BOOST_FUSION_ADAPTED_STRUCT_DETAIL_ADAPT_BASE_ATTR_FILLER_HPP + +#include +#include + +#include +#include +#include +#include +#include + +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(X, Y) \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(X,Y) \ + BOOST_FUSION_ADAPT_STRUCT_FILLER_1 + +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1(X, Y) \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(X,Y) \ + BOOST_FUSION_ADAPT_STRUCT_FILLER_0 + +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END +#define BOOST_FUSION_ADAPT_STRUCT_FILLER_1_END + +#define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(X, Y) \ + BOOST_PP_IF(BOOST_PP_IS_EMPTY(X), \ + ((1, (Y))), \ + ((2, (X,Y))) \ + ) + +#if BOOST_PP_VARIADICS + +# define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER_OP(r, data, elem) \ + BOOST_PP_IF(BOOST_FUSION_PP_IS_SEQ(elem), \ + BOOST_PP_CAT( BOOST_FUSION_ADAPT_STRUCT_FILLER_0 elem ,_END), \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(BOOST_FUSION_ADAPT_AUTO, \ + elem) \ + ) + +# define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER(...) \ + BOOST_PP_SEQ_PUSH_FRONT( \ + BOOST_PP_SEQ_FOR_EACH( \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER_OP, \ + unused, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)), \ + (0,0) \ + ) + +#endif // BOOST_PP_VARIADICS + +#endif From ce3f2d6020ba490805e0fd030b640e8bf94924b5 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 11 Jun 2014 00:27:22 +0200 Subject: [PATCH 27/37] Added new ADAPT_STRUCT API support for the ADAPT_STRUCT_AS_VIEW macro. --- .../fusion/adapted/struct/adapt_struct.hpp | 31 +++++++++++++------ .../adapted/struct/detail/adapt_base.hpp | 1 - 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index 58c4c4d6..6a70419c 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -65,6 +66,15 @@ 0, \ BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER(__VA_ARGS__), \ BOOST_FUSION_ADAPT_STRUCT_C) + +# define BOOST_FUSION_ADAPT_STRUCT_AS_VIEW(NAME, ...) \ + BOOST_FUSION_ADAPT_STRUCT_BASE( \ + (0), \ + (0)(NAME), \ + struct_tag, \ + 1, \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER(__VA_ARGS__), \ + BOOST_FUSION_ADAPT_STRUCT_C) #else // BOOST_PP_VARIADICS @@ -79,15 +89,18 @@ _END), \ BOOST_FUSION_ADAPT_STRUCT_C) +# define BOOST_FUSION_ADAPT_STRUCT_AS_VIEW(NAME, ATTRIBUTES) \ + BOOST_FUSION_ADAPT_STRUCT_BASE( \ + (0), \ + (0)(NAME), \ + struct_tag, \ + 1, \ + BOOST_PP_CAT( \ + BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES, \ + _END), \ + BOOST_FUSION_ADAPT_STRUCT_C) + + #endif // BOOST_PP_VARIADICS -#define BOOST_FUSION_ADAPT_STRUCT_AS_VIEW(NAME, ATTRIBUTES) \ - BOOST_FUSION_ADAPT_STRUCT_BASE( \ - (0), \ - (0)(NAME), \ - struct_tag, \ - 1, \ - BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ - BOOST_FUSION_ADAPT_STRUCT_C) - #endif diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index 90bac86c..3dafd0cb 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include From 04ce8a788b564e6efcc31885fd63b97f5df13633 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 11 Jun 2014 00:37:35 +0200 Subject: [PATCH 28/37] Enabled new ADAPT_STRUCT_API for ADAPT_TPL_STRUCT. --- .../fusion/adapted/struct/adapt_struct.hpp | 44 ++++++++++++------- test/sequence/adapt_tpl_struct.cpp | 2 +- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index 6a70419c..95df82b0 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -43,29 +43,28 @@ BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE), \ BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE)) -#define BOOST_FUSION_ADAPT_TPL_STRUCT(TEMPLATE_PARAMS_SEQ,NAME_SEQ, ATTRIBUTES) \ - BOOST_FUSION_ADAPT_STRUCT_BASE( \ - (1)TEMPLATE_PARAMS_SEQ, \ - (1)NAME_SEQ, \ - struct_tag, \ - 0, \ - ((0,0)) BOOST_PP_CAT( \ - BOOST_FUSION_ADAPT_STRUCT_FILLER_0 ATTRIBUTES,_END), \ - BOOST_FUSION_ADAPT_STRUCT_C) - #define BOOST_FUSION_ADAPT_AUTO BOOST_PP_EMPTY() #if BOOST_PP_VARIADICS +# define BOOST_FUSION_ADAPT_TPL_STRUCT(TEMPLATE_PARAMS_SEQ,NAME_SEQ, ...) \ + BOOST_FUSION_ADAPT_STRUCT_BASE( \ + (1)TEMPLATE_PARAMS_SEQ, \ + (1)NAME_SEQ, \ + struct_tag, \ + 0, \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER(__VA_ARGS__), \ + BOOST_FUSION_ADAPT_STRUCT_C) + # define BOOST_FUSION_ADAPT_STRUCT(NAME, ...) \ - BOOST_FUSION_ADAPT_STRUCT_BASE( \ - (0), \ - (0)(NAME), \ - struct_tag, \ - 0, \ - BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER(__VA_ARGS__), \ - BOOST_FUSION_ADAPT_STRUCT_C) + BOOST_FUSION_ADAPT_STRUCT_BASE( \ + (0), \ + (0)(NAME), \ + struct_tag, \ + 0, \ + BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER(__VA_ARGS__), \ + BOOST_FUSION_ADAPT_STRUCT_C) # define BOOST_FUSION_ADAPT_STRUCT_AS_VIEW(NAME, ...) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ @@ -78,6 +77,17 @@ #else // BOOST_PP_VARIADICS +# define BOOST_FUSION_ADAPT_TPL_STRUCT( \ + TEMPLATE_PARAMS_SEQ,NAME_SEQ, ATTRIBUTES) \ + BOOST_FUSION_ADAPT_STRUCT_BASE( \ + (1)TEMPLATE_PARAMS_SEQ, \ + (1)NAME_SEQ, \ + struct_tag, \ + 0, \ + ((0,0)) BOOST_PP_CAT( \ + BOOST_FUSION_ADAPT_STRUCT_FILLER_0 ATTRIBUTES,_END), \ + BOOST_FUSION_ADAPT_STRUCT_C) + # define BOOST_FUSION_ADAPT_STRUCT(NAME, ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ (0), \ diff --git a/test/sequence/adapt_tpl_struct.cpp b/test/sequence/adapt_tpl_struct.cpp index 352cf995..1c0ae6d6 100644 --- a/test/sequence/adapt_tpl_struct.cpp +++ b/test/sequence/adapt_tpl_struct.cpp @@ -41,7 +41,7 @@ namespace ns BOOST_FUSION_ADAPT_TPL_STRUCT( (X)(Y), (ns::point)(X)(Y), - (X, x) + (BOOST_FUSION_ADAPT_AUTO, x) (Y, y) ) From 6483cf40582a6b6bb878c56d4911be9803c9006a Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 11 Jun 2014 01:14:13 +0200 Subject: [PATCH 29/37] Adding documentation of the new ADAPT_STRUCT and ADAPT_STRUCT_TPL macros, capable of deducing type. --- doc/adapted.qbk | 81 ++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/doc/adapted.qbk b/doc/adapted.qbk index 2f77a0c6..f3e74367 100644 --- a/doc/adapted.qbk +++ b/doc/adapted.qbk @@ -177,7 +177,7 @@ __boost_tuple_library__ [endsect] -[section:adapt_struct BOOST_FUSION_ \[AUTO_\] ADAPT_STRUCT] +[section:adapt_struct BOOST_FUSION_ADAPT_STRUCT] [heading Description] BOOST_FUSION_ADAPT_STRUCT is a macro that can be used to generate all the @@ -187,15 +187,18 @@ __random_access_sequence__. [heading Synopsis] BOOST_FUSION_ADAPT_STRUCT( struct_name, - (member_type0, member_name0) - (member_type1, member_name1) + member_name0, + member_name1, + member_name2, ... ) + // When Variadic support isn't available or you wish to manually specify the type: BOOST_FUSION_AUTO_ADAPT_STRUCT( struct_name, - (member_name0) - (member_name1) + (member_type0, member_name0) + (member_type1, member_name1) + (BOOST_FUSION_ADAPT_AUTO, member_name2) ... ) @@ -203,11 +206,13 @@ __random_access_sequence__. The above macro generates the necessary code to adapt `struct_name` as a model of __random_access_sequence__. -The sequence of `(member_typeN, member_nameN)` -pairs declares the type and names of each of the struct members that are -part of the sequence. While the auto version of the macro only allows -specifying a sequence of `(member_nameN)` as fields' types are deduced with -[@boost:/libs/typeof/index.html Boost.TypeOf]. + +The sequence of `member_nameN,` arguments or `(member_typeN, member_nameN)` +pairs declares the type and names of each of the struct members that are part of +the sequence. + +Omitting the type or using BOOST_FUSION_ADAPT_AUTO can be used to infer the type, +as with decltype. The macro should be used at global scope, and `struct_name` should be the fully namespace qualified name of the struct to be adapted. @@ -215,7 +220,6 @@ namespace qualified name of the struct to be adapted. [heading Header] #include - #include #include [heading Example: BOOST_FUSION_ADAPT_STRUCT ] @@ -231,25 +235,15 @@ namespace qualified name of the struct to be adapted. // demo::employee is now a Fusion sequence BOOST_FUSION_ADAPT_STRUCT( demo::employee, - (std::string, name) - (int, age)) + name, + age) - -[heading Example: BOOST_FUSION_AUTO_ADAPT_STRUCT ] - namespace demo - { - struct employee - { - std::string name; - int age; - }; - } - - // demo::employee is now a Fusion sequence - BOOST_FUSION_AUTO_ADAPT_STRUCT( + // Or demo::employee is also a Fusion sequence + BOOST_FUSION_ADAPT_STRUCT( demo::employee, - (name) - (age)) + (BOOST_FUSION_ADAPT_AUTO, name) + (BOOST_FUSION_ADAPT_AUTO, age) + ) [endsect] @@ -261,11 +255,21 @@ necessary boilerplate to make an arbitrary template struct a model of __random_access_sequence__. [heading Synopsis] + BOOST_FUSION_ADAPT_TPL_STRUCT( + (template_param0)(template_param1)..., + (struct_name) (specialization_param0)(specialization_param1)..., + member_name0, + member_name1 + ... + ) + + // When Variadic support isn't available or you wish to manually specify the type: BOOST_FUSION_ADAPT_TPL_STRUCT( (template_param0)(template_param1)..., (struct_name) (specialization_param0)(specialization_param1)..., (member_type0, member_name0) (member_type1, member_name1) + (BOOST_FUSION_ADAPT_AUTO, member_name2), ... ) @@ -279,9 +283,12 @@ the template type parameters used. The sequence `(specialization_param0)(specialization_param1)...` declares the template parameters of the actual specialization of `struct_name` that is adapted as a fusion sequence. -The sequence of `(member_typeN, member_nameN)` -pairs declares the type and names of each of the struct members that are -part of the sequence. +The sequence of `member_nameN,` arguments or `(member_typeN, member_nameN)` +pairs declares the type and names of each of the struct members that are part of +the sequence. + +Omitting the type or using BOOST_FUSION_ADAPT_AUTO can be used to infer the type, +as with decltype. The macro should be used at global scope, and `struct_name` should be the fully namespace qualified name of the struct to be adapted. @@ -299,6 +306,7 @@ namespace qualified name of the struct to be adapted. { Name name; Age age; + int employment_timestamp; }; } @@ -307,7 +315,16 @@ namespace qualified name of the struct to be adapted. (Name)(Age), (demo::employee) (Name)(Age), (Name, name) - (Age, age)) + (Age, age) + (BOOST_FUSION_ADAPT_AUTO, employment_timestamp)) + + // Or by infering type completely + BOOST_FUSION_ADAPT_TPL_STRUCT( + (Name)(Age), + (demo::employee) (Name)(Age), + name, + age, + employment_timestamp) [endsect] From 0000ca263b29868f66afe8cd5e3e9bc27e93ec15 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 11 Jun 2014 01:19:00 +0200 Subject: [PATCH 30/37] Removing AUTO_ADAPT_STRUCT_NAMED, AUTO_ADAPT_ASSOC_STRUCT and AUTO_ADAPT_ASSOC_STRUCT_NAMED. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As discussed with Agustín Bergé and Joel de Guzman on https://github.com/boostorg/fusion/pull/3, it's better to remove the separate macro for the type deducting macros, and to instead support a flexible API allowing backward compatibility and type omission. This is what ADAPT_STRUCT and ADAPT_STRUCT_TPL now provides. All other macros will be improved in the same way in the following commits. --- doc/adapted.qbk | 139 ++++-------------------------------------------- 1 file changed, 10 insertions(+), 129 deletions(-) diff --git a/doc/adapted.qbk b/doc/adapted.qbk index f3e74367..10e88c71 100644 --- a/doc/adapted.qbk +++ b/doc/adapted.qbk @@ -328,7 +328,7 @@ namespace qualified name of the struct to be adapted. [endsect] -[section:adapt_struct_named BOOST_FUSION_ \[AUTO_\] ADAPT_STRUCT_NAMED] +[section:adapt_struct_named BOOST_FUSION_ADAPT_STRUCT_NAMED] [heading Description] BOOST_FUSION_ADAPT_STRUCT_NAMED and BOOST_FUSION_ADAPT_STRUCT_NAMED_NS are @@ -336,7 +336,6 @@ macros that can be used to generate all the necessary boilerplate to make an arbitrary struct a model of __random_access_sequence__. The given struct is adapted using the given name. - [heading Synopsis] BOOST_FUSION_ADAPT_STRUCT_NAMED( struct_name, adapted_name, @@ -345,13 +344,6 @@ adapted using the given name. ... ) - BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED( - struct_name, adapted_name, - (member_name0) - (member_name1) - ... - ) - BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( struct_name, (namespace0)(namespace1)..., @@ -361,17 +353,6 @@ adapted using the given name. ... ) - BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED_NS( - struct_name, - (namespace0)(namespace1)..., - adapted_name, - (member_name0) - (member_name1) - ... - ) - - - [heading Semantics] The above macros generate the necessary code to adapt `struct_name` @@ -384,11 +365,9 @@ If an empty namespace sequence is given (that is a macro that expands to nothing), the adapted view is placed in the global namespace. If no namespace sequence is given (i.e. `BOOST_FUSION_ADAPT_STRUCT_NAMED`), the adapted view is placed in the namespace `boost::fusion::adapted`. -In the non-auto version of the macro the sequence of -`(member_typeN, member_nameN)` pairs declares the type and names of each of the -struct members that are part of the sequence. -While the auto version of the macro only allows specifying a sequence of -`(member_nameN)` as fields' types are deduced with [@boost:/libs/typeof/index.html Boost.TypeOf]. +The sequence of `(member_typeN, member_nameN)` +pairs declares the type and names of each of the struct members that are +part of the sequence. The macros should be used at global scope, and `struct_name` should be the fully namespace qualified name of the struct to be converted. @@ -396,10 +375,9 @@ namespace qualified name of the struct to be converted. [heading Header] #include - #include #include -[heading Example: BOOST_FUSION_ADAPT_STRUCT_NAMED] +[heading Example] namespace demo { struct employee @@ -416,26 +394,9 @@ namespace qualified name of the struct to be converted. (std::string, name) (int, age)) -[heading Example: BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED] - namespace demo - { - struct employee - { - std::string name; - int age; - }; - } - - // boost::fusion::adapted::adapted_employee is now a Fusion sequence - // referring to demo::employee - BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED( - demo::employee, adapted_employee, - (name) - (age)) - [endsect] -[section:adapt_assoc BOOST_FUSION_ \[AUTO_\] ADAPT_ASSOC_STRUCT] +[section:adapt_assoc BOOST_FUSION_ADAPT_ASSOC_STRUCT] [heading Description] BOOST_FUSION_ADAPT_ASSOC_STRUCT is a macro that can be used to generate all the @@ -450,24 +411,13 @@ __random_access_sequence__ and __associative_sequence__. ... ) - BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT( - struct_name, - (member_name0, key_type0) - (member_name1, key_type1) - ... - ) - [heading Semantics] The above macro generates the necessary code to adapt `struct_name` as a model of __random_access_sequence__ and __associative_sequence__. The sequence of `(member_typeN, member_nameN, key_typeN)` triples declares the type, name and key type of each of the struct members -that are part of the sequence. - -While BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT only allows specifying a sequence of -`(member_nameN, key_typeN)` as fields' types are deduced with -[@boost:/libs/typeof/index.html Boost.TypeOf]. +that are part of the sequence. The macro should be used at global scope, and `struct_name` should be the fully namespace qualified name of the struct to be adapted. @@ -475,10 +425,9 @@ namespace qualified name of the struct to be adapted. [heading Header] #include - #include #include -[heading Example : BOOST_FUSION_ADAPT_ASSOC_STRUCT] +[heading Example] namespace demo { struct employee @@ -502,30 +451,6 @@ namespace qualified name of the struct to be adapted. (std::string, name, keys::name) (int, age, keys::age)) -[heading Example : BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT] - namespace demo - { - struct employee - { - std::string name; - int age; - }; - } - - namespace keys - { - struct name; - struct age; - } - - // demo::employee is now a Fusion sequence. - // It is also an associative sequence with - // keys keys::name and keys::age present. - BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT( - demo::employee, - (name, keys::name) - (age, keys::age)) - [endsect] [section:adapt_assoc_tpl_struct BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT] @@ -594,7 +519,7 @@ namespace qualified name of the struct to be adapted. [endsect] -[section:adapt_assoc_struct_named BOOST_FUSION_ \[AUTO_\] ADAPT_ASSOC_STRUCT_NAMED] +[section:adapt_assoc_struct_named BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED] [heading Description] BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED and BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS are @@ -610,13 +535,6 @@ __associative_sequence__. The given struct is adapted using the given name. ... ) - BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED( - struct_name, adapted_name, - (member_name0, key_type0) - (member_name1, key_type1) - ... - ) - BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS( struct_name, (namespace0)(namespace1)..., @@ -626,15 +544,6 @@ __associative_sequence__. The given struct is adapted using the given name. ... ) - BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_NS( - struct_name, - (namespace0)(namespace1)..., - adapted_name, - (member_name0, key_type0) - (member_name1, key_type1) - ... - ) - [heading Semantics] The above macros generate the necessary code to adapt `struct_name` @@ -651,20 +560,15 @@ The sequence of `(member_typeN, member_nameN, key_typeN)` triples declares the type, name and key type of each of the struct members that are part of the sequence. -While BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED only allows specifying a -sequence of `(member_nameN, key_typeN)` as fields' types are deduced with -[@boost:/libs/typeof/index.html Boost.TypeOf]. - The macros should be used at global scope, and `struct_name` should be the fully namespace qualified name of the struct to be converted. [heading Header] #include - #include #include -[heading Example : BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED] +[heading Example] namespace demo { struct employee @@ -687,29 +591,6 @@ namespace qualified name of the struct to be converted. (std::string, name, keys::name) (int, age, keys::age)) -[heading Example : BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED] - namespace demo - { - struct employee - { - std::string name; - int age; - }; - } - - namespace keys - { - struct name; - struct age; - } - - // boost::fusion::adapted::adapted_employee is now a Fusion sequence - // referring to demo::employee - BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED( - demo::employee, adapted_employee, - (name, keys::name) - (age, keys::age)) - [endsect] [section:adapt_adt BOOST_FUSION_ADAPT_ADT] From 4cf96e14f3d3c9336789dafef210716881f186ef Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 11 Jun 2014 01:43:57 +0200 Subject: [PATCH 31/37] Added test for the new ADAPT_STRUCT API capable to deduce member types. --- test/sequence/adapt_struct.cpp | 98 ++++++---- test/sequence/adapt_tpl_struct.cpp | 63 ++++--- test/sequence/auto_adapt_assoc_struct.cpp | 141 --------------- .../auto_adapt_assoc_struct_named.cpp | 121 ------------- test/sequence/auto_adapt_struct.cpp | 169 ------------------ test/sequence/auto_adapt_struct_named.cpp | 137 -------------- 6 files changed, 106 insertions(+), 623 deletions(-) delete mode 100644 test/sequence/auto_adapt_assoc_struct.cpp delete mode 100644 test/sequence/auto_adapt_assoc_struct_named.cpp delete mode 100644 test/sequence/auto_adapt_struct.cpp delete mode 100644 test/sequence/auto_adapt_struct_named.cpp diff --git a/test/sequence/adapt_struct.cpp b/test/sequence/adapt_struct.cpp index bb8c7cb3..819ec009 100644 --- a/test/sequence/adapt_struct.cpp +++ b/test/sequence/adapt_struct.cpp @@ -4,8 +4,6 @@ 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) ==============================================================================*/ -#define BOOST_PP_VARIADICS 1 - #include #include #include @@ -51,32 +49,59 @@ namespace ns private: int x; int y; + int z; public: - point_with_private_attributes(int x, int y):x(x),y(y) + point_with_private_attributes(int x, int y, int z):x(x),y(y),z(z) {} }; #endif } -BOOST_FUSION_ADAPT_STRUCT( - ns::point, - (int, x) - (BOOST_FUSION_ADAPT_AUTO, y) - (, z) -) +#if BOOST_PP_VARIADICS + + BOOST_FUSION_ADAPT_STRUCT( + ns::point, + x, + y, + z + ) + +# if !BOOST_WORKAROUND(__GNUC__,<4) + BOOST_FUSION_ADAPT_STRUCT( + ns::point_with_private_attributes, + x, + y, + z + ) +# endif + + struct s { int m; }; + BOOST_FUSION_ADAPT_STRUCT(s, m) + +#else // BOOST_PP_VARIADICS + + BOOST_FUSION_ADAPT_STRUCT( + ns::point, + (int, x) + (int, y) + (BOOST_FUSION_ADAPT_AUTO, z) + ) + +# if !BOOST_WORKAROUND(__GNUC__,<4) + BOOST_FUSION_ADAPT_STRUCT( + ns::point_with_private_attributes, + (int, x) + (int, y) + (BOOST_FUSION_ADAPT_AUTO, z) + ) +# endif + + struct s { int m; }; + BOOST_FUSION_ADAPT_STRUCT(s, (BOOST_FUSION_ADAPT_AUTO, m)) -#if !BOOST_WORKAROUND(__GNUC__,<4) -BOOST_FUSION_ADAPT_STRUCT( - ns::point_with_private_attributes, - (int, x) - (int, y) -) #endif -struct s { int m; }; -BOOST_FUSION_ADAPT_STRUCT(s, (int, m)) - int main() { @@ -88,29 +113,31 @@ main() std::cout << tuple_delimiter(", "); { - BOOST_MPL_ASSERT_NOT((traits::is_view)); - ns::point p = {123, 456}; + BOOST_MPL_ASSERT_NOT((traits::is_view)); + point p = {123, 456, 789}; std::cout << at_c<0>(p) << std::endl; std::cout << at_c<1>(p) << std::endl; + std::cout << at_c<2>(p) << std::endl; std::cout << p << std::endl; - BOOST_TEST(p == make_vector(123, 456, 4)); + BOOST_TEST(p == make_vector(123, 456, 789)); at_c<0>(p) = 6; at_c<1>(p) = 9; + at_c<2>(p) = 12; BOOST_TEST(p == make_vector(6, 9, 12)); - BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 3); - BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); + BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 3); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); BOOST_TEST(front(p) == 6); - BOOST_TEST(back(p) == 9); + BOOST_TEST(back(p) == 12); } { - fusion::vector v1(4, 2, 3); - ns::point v2 = {5, 3, 2}; - fusion::vector v3(5, 4, 2); + vector v1(4, 2, 2); + point v2 = {5, 3, 3}; + vector v3(5, 4, 4); BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); @@ -122,16 +149,16 @@ main() } { - // conversion from ns::point to vector - ns::point p = {5, 3, 4}; - fusion::vector v(p); + // conversion from point to vector + point p = {5, 3, 3}; + vector v(p); v = p; } { - // conversion from ns::point to list - ns::point p = {5, 3, 4}; - fusion::list l(p); + // conversion from point to list + point p = {5, 3, 3}; + list l(p); l = p; } @@ -154,12 +181,13 @@ main() #if !BOOST_WORKAROUND(__GNUC__,<4) { - ns::point_with_private_attributes p(123, 456); + ns::point_with_private_attributes p(123, 456, 789); std::cout << at_c<0>(p) << std::endl; std::cout << at_c<1>(p) << std::endl; + std::cout << at_c<2>(p) << std::endl; std::cout << p << std::endl; - BOOST_TEST(p == make_vector(123, 456)); + BOOST_TEST(p == make_vector(123, 456, 789)); } #endif diff --git a/test/sequence/adapt_tpl_struct.cpp b/test/sequence/adapt_tpl_struct.cpp index 1c0ae6d6..86face6d 100644 --- a/test/sequence/adapt_tpl_struct.cpp +++ b/test/sequence/adapt_tpl_struct.cpp @@ -35,19 +35,40 @@ namespace ns { X x; Y y; + int z; }; } -BOOST_FUSION_ADAPT_TPL_STRUCT( - (X)(Y), - (ns::point)(X)(Y), - (BOOST_FUSION_ADAPT_AUTO, x) - (Y, y) -) +#if BOOST_PP_VARIADICS + + BOOST_FUSION_ADAPT_TPL_STRUCT( + (X)(Y), + (ns::point)(X)(Y), + x, + (BOOST_FUSION_ADAPT_AUTO, y) + (int, z) + ) + + template + struct s { M m; }; + BOOST_FUSION_ADAPT_TPL_STRUCT((M), (s)(M), m) + +#else // BOOST_PP_VARIADICS + + BOOST_FUSION_ADAPT_TPL_STRUCT( + (X)(Y), + (ns::point)(X)(Y), + (X, x) + (Y, y) + (BOOST_FUSION_ADAPT_AUTO, z) + ) + + template + struct s { M m; }; + BOOST_FUSION_ADAPT_TPL_STRUCT((M), (s)(M), (BOOST_FUSION_ADAPT_AUTO, m)) + +#endif -template -struct s { M m; }; -BOOST_FUSION_ADAPT_TPL_STRUCT((M), (s)(M), (M, m)) int main() @@ -62,28 +83,30 @@ main() { BOOST_MPL_ASSERT_NOT((traits::is_view)); - point p = {123, 456}; + point p = {123, 456, 789}; std::cout << at_c<0>(p) << std::endl; std::cout << at_c<1>(p) << std::endl; + std::cout << at_c<2>(p) << std::endl; std::cout << p << std::endl; - BOOST_TEST(p == make_vector(123, 456)); + BOOST_TEST(p == make_vector(123, 456, 789)); at_c<0>(p) = 6; at_c<1>(p) = 9; - BOOST_TEST(p == make_vector(6, 9)); + at_c<2>(p) = 12; + BOOST_TEST(p == make_vector(6, 9, 12)); - BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 2); + BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 3); BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); BOOST_TEST(front(p) == 6); - BOOST_TEST(back(p) == 9); + BOOST_TEST(back(p) == 12); } { - vector v1(4, 2); - point v2 = {5, 3}; - vector v3(5, 4); + vector v1(4, 2, 2); + point v2 = {5, 3, 3}; + vector v3(5, 4, 4); BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); @@ -96,14 +119,14 @@ main() { // conversion from point to vector - point p = {5, 3}; - vector v(p); + point p = {5, 3, 3}; + vector v(p); v = p; } { // conversion from point to list - point p = {5, 3}; + point p = {5, 3, 3}; list l(p); l = p; } diff --git a/test/sequence/auto_adapt_assoc_struct.cpp b/test/sequence/auto_adapt_assoc_struct.cpp deleted file mode 100644 index 177df20b..00000000 --- a/test/sequence/auto_adapt_assoc_struct.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/*============================================================================= - Copyright (c) 2001-2007 Joel de Guzman - Copyright (c) 2005-2007 Dan Marsden - - 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ns -{ - struct x_member; - struct y_member; - struct z_member; - - struct point - { - int x; - int y; - }; -} - -BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT( - ns::point, - (x, ns::x_member) - (y, ns::y_member) -) - -int -main() -{ - using namespace boost::fusion; - using namespace boost; - - std::cout << tuple_open('['); - std::cout << tuple_close(']'); - std::cout << tuple_delimiter(", "); - - { - BOOST_MPL_ASSERT_NOT((traits::is_view)); - ns::point p = {123, 456}; - - std::cout << at_c<0>(p) << std::endl; - std::cout << at_c<1>(p) << std::endl; - std::cout << p << std::endl; - BOOST_TEST(p == make_vector(123, 456)); - - at_c<0>(p) = 6; - at_c<1>(p) = 9; - BOOST_TEST(p == make_vector(6, 9)); - - BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 2); - BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); - - BOOST_TEST(front(p) == 6); - BOOST_TEST(back(p) == 9); - } - - { - fusion::vector v1(4, 2); - ns::point v2 = {5, 3}; - fusion::vector v3(5, 4); - BOOST_TEST(v1 < v2); - BOOST_TEST(v1 <= v2); - BOOST_TEST(v2 > v1); - BOOST_TEST(v2 >= v1); - BOOST_TEST(v2 < v3); - BOOST_TEST(v2 <= v3); - BOOST_TEST(v3 > v2); - BOOST_TEST(v3 >= v2); - } - - { - // conversion from ns::point to vector - ns::point p = {5, 3}; - fusion::vector v(p); - v = p; - } - - { - // conversion from ns::point to list - ns::point p = {5, 3}; - fusion::list l(p); - l = p; - } - - { - // assoc stuff - BOOST_MPL_ASSERT((boost::fusion::result_of::has_key)); - BOOST_MPL_ASSERT((boost::fusion::result_of::has_key)); - BOOST_MPL_ASSERT((mpl::not_ >)); - - BOOST_MPL_ASSERT((boost::is_same::type, int>)); - BOOST_MPL_ASSERT((boost::is_same::type, int>)); - - ns::point p = {5, 3}; - - BOOST_TEST(at_key(p) == 5); - BOOST_TEST(at_key(p) == 3); - } - - { - BOOST_MPL_ASSERT((mpl::is_sequence)); - BOOST_MPL_ASSERT((boost::is_same< - boost::fusion::result_of::value_at_c::type - , mpl::front::type>)); - } - - return boost::report_errors(); -} - diff --git a/test/sequence/auto_adapt_assoc_struct_named.cpp b/test/sequence/auto_adapt_assoc_struct_named.cpp deleted file mode 100644 index b2e85541..00000000 --- a/test/sequence/auto_adapt_assoc_struct_named.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/*============================================================================= - Copyright (c) 2010 Christopher Schmidt - - 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ns -{ - struct x_member; - struct y_member; - struct z_member; - - struct point - { - int x; - int y; - }; -} - -BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED( - ns::point, - point, - (x, ns::x_member) - (y, ns::y_member) -) - -int -main() -{ - using namespace boost::fusion; - - std::cout << tuple_open('['); - std::cout << tuple_close(']'); - std::cout << tuple_delimiter(", "); - - { - BOOST_MPL_ASSERT((traits::is_view)); - ns::point basep = {123, 456}; - adapted::point p(basep); - - std::cout << at_c<0>(p) << std::endl; - std::cout << at_c<1>(p) << std::endl; - std::cout << p << std::endl; - BOOST_TEST(p == make_vector(123, 456)); - - at_c<0>(p) = 6; - at_c<1>(p) = 9; - BOOST_TEST(p == make_vector(6, 9)); - - BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 2); - BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); - - BOOST_TEST(front(p) == 6); - BOOST_TEST(back(p) == 9); - } - - { - vector v1(4, 2); - ns::point basev2 = {5, 3}; - adapted::point v2(basev2); - - vector v3(5, 4); - BOOST_TEST(v1 < v2); - BOOST_TEST(v1 <= v2); - BOOST_TEST(v2 > v1); - BOOST_TEST(v2 >= v1); - BOOST_TEST(v2 < v3); - BOOST_TEST(v2 <= v3); - BOOST_TEST(v3 > v2); - BOOST_TEST(v3 >= v2); - } - - { - // conversion from adapted::point to vector - ns::point basep = {5, 3}; - adapted::point p(basep); - vector v(p); - v = p; - } - - { - // conversion from adapted::point to list - ns::point basep = {5, 3}; - adapted::point p(basep); - list l(p); - l = p; - } - - { - // assoc stuff - BOOST_MPL_ASSERT((boost::fusion::result_of::has_key)); - BOOST_MPL_ASSERT((boost::fusion::result_of::has_key)); - BOOST_MPL_ASSERT((boost::mpl::not_ >)); - - BOOST_MPL_ASSERT((boost::is_same::type, int>)); - BOOST_MPL_ASSERT((boost::is_same::type, int>)); - - ns::point basep = {5, 3}; - adapted::point p(basep); - - BOOST_TEST(at_key(p) == 5); - BOOST_TEST(at_key(p) == 3); - } - - return boost::report_errors(); -} - diff --git a/test/sequence/auto_adapt_struct.cpp b/test/sequence/auto_adapt_struct.cpp deleted file mode 100644 index e7ce2890..00000000 --- a/test/sequence/auto_adapt_struct.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/*============================================================================= - Copyright (c) 2001-2007 Joel de Guzman - Copyright (c) 2013-2014 Damien Buhl - - 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ns -{ - struct point - { - int x; - int y; - }; - -#if !BOOST_WORKAROUND(__GNUC__,<4) - struct point_with_private_attributes - { - friend struct boost::fusion::extension::access; - - private: - int x; - int y; - - public: - point_with_private_attributes(int x, int y):x(x),y(y) - {} - }; -#endif -} - -/*BOOST_FUSION_AUTO_ADAPT_STRUCT( - ns::point, - (x) - (y) -)*/ - -BOOST_FUSION_AUTO_ADAPT_STRUCT( - ns::point, - x, y -) - -#if !BOOST_WORKAROUND(__GNUC__,<4) -BOOST_FUSION_AUTO_ADAPT_STRUCT( - ns::point_with_private_attributes, - (x) - (y) -) -#endif - -struct s { int m; }; -BOOST_FUSION_AUTO_ADAPT_STRUCT(s, (m)) - -int -main() -{ - using namespace boost::fusion; - using namespace boost; - - std::cout << tuple_open('['); - std::cout << tuple_close(']'); - std::cout << tuple_delimiter(", "); - - { - BOOST_MPL_ASSERT_NOT((traits::is_view)); - ns::point p = {123, 456}; - - std::cout << at_c<0>(p) << std::endl; - std::cout << at_c<1>(p) << std::endl; - std::cout << p << std::endl; - BOOST_TEST(p == make_vector(123, 456)); - - at_c<0>(p) = 6; - at_c<1>(p) = 9; - BOOST_TEST(p == make_vector(6, 9)); - - BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 2); - BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); - - BOOST_TEST(front(p) == 6); - BOOST_TEST(back(p) == 9); - } - - { - fusion::vector v1(4, 2); - ns::point v2 = {5, 3}; - fusion::vector v3(5, 4); - BOOST_TEST(v1 < v2); - BOOST_TEST(v1 <= v2); - BOOST_TEST(v2 > v1); - BOOST_TEST(v2 >= v1); - BOOST_TEST(v2 < v3); - BOOST_TEST(v2 <= v3); - BOOST_TEST(v3 > v2); - BOOST_TEST(v3 >= v2); - } - - { - // conversion from ns::point to vector - ns::point p = {5, 3}; - fusion::vector v(p); - v = p; - } - - { - // conversion from ns::point to list - ns::point p = {5, 3}; - fusion::list l(p); - l = p; - } - - { // begin/end - using namespace boost::fusion; - using boost::is_same; - - typedef boost::fusion::result_of::begin::type b; - typedef boost::fusion::result_of::end::type e; - // this fails - BOOST_MPL_ASSERT((is_same::type, e>)); - } - - { - BOOST_MPL_ASSERT((mpl::is_sequence)); - BOOST_MPL_ASSERT((boost::is_same< - boost::fusion::result_of::value_at_c::type - , mpl::front::type>)); - } - -#if !BOOST_WORKAROUND(__GNUC__,<4) - { - ns::point_with_private_attributes p(123, 456); - - std::cout << at_c<0>(p) << std::endl; - std::cout << at_c<1>(p) << std::endl; - std::cout << p << std::endl; - BOOST_TEST(p == make_vector(123, 456)); - } -#endif - - return boost::report_errors(); -} diff --git a/test/sequence/auto_adapt_struct_named.cpp b/test/sequence/auto_adapt_struct_named.cpp deleted file mode 100644 index 1ada8efe..00000000 --- a/test/sequence/auto_adapt_struct_named.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/*============================================================================= - Copyright (c) 2001-2007 Joel de Guzman - - 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ns -{ - struct point - { - int x; - int y; - }; -} - -// this creates a fusion view: boost::fusion::adapted::point -BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED( - ns::point, point, - (x) - (y) -) - -// this creates a fusion view: ns1::s1 -struct s { int m; }; -BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED_NS(s, (ns1), s1, (m)) - -int -main() -{ - using namespace boost::fusion; - using namespace boost; - - std::cout << tuple_open('['); - std::cout << tuple_close(']'); - std::cout << tuple_delimiter(", "); - - { - BOOST_MPL_ASSERT((traits::is_view)); - ns::point basep = {123, 456}; - adapted::point p(basep); - - std::cout << at_c<0>(p) << std::endl; - std::cout << at_c<1>(p) << std::endl; - std::cout << p << std::endl; - BOOST_TEST(p == make_vector(123, 456)); - - at_c<0>(p) = 6; - at_c<1>(p) = 9; - BOOST_TEST(p == make_vector(6, 9)); - - BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 2); - BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); - - BOOST_TEST(front(p) == 6); - BOOST_TEST(back(p) == 9); - } - - { - fusion::vector v1(4, 2); - ns::point p = {5, 3}; - adapted::point v2(p); - - fusion::vector v3(5, 4); - BOOST_TEST(v1 < v2); - BOOST_TEST(v1 <= v2); - BOOST_TEST(v2 > v1); - BOOST_TEST(v2 >= v1); - BOOST_TEST(v2 < v3); - BOOST_TEST(v2 <= v3); - BOOST_TEST(v3 > v2); - BOOST_TEST(v3 >= v2); - } - - { - // conversion from adapted::point to vector - ns::point basep = {5, 3}; - adapted::point p(basep); - fusion::vector v(p); - v = p; - } - - { - // conversion from adapted::point to list - ns::point basep = {5, 3}; - adapted::point p(basep); - fusion::list l(p); - l = p; - } - - { // begin/end - using namespace boost::fusion; - using boost::is_same; - - typedef boost::fusion::result_of::begin::type b; - typedef boost::fusion::result_of::end::type e; - // this fails - BOOST_MPL_ASSERT((is_same::type, e>)); - } - - - { - BOOST_MPL_ASSERT((mpl::is_sequence)); - BOOST_MPL_ASSERT((boost::is_same< - boost::fusion::result_of::value_at_c::type - , mpl::front::type>)); - } - - return boost::report_errors(); -} - From 2e60ba6f29765884cefcde58d2e8694bbe973771 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 11 Jun 2014 02:35:31 +0200 Subject: [PATCH 32/37] Fixed typos and inconsistencies in ADAPT_STRUCT documentation. --- doc/adapted.qbk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/adapted.qbk b/doc/adapted.qbk index 10e88c71..e6adfd29 100644 --- a/doc/adapted.qbk +++ b/doc/adapted.qbk @@ -193,8 +193,8 @@ __random_access_sequence__. ... ) - // When Variadic support isn't available or you wish to manually specify the type: - BOOST_FUSION_AUTO_ADAPT_STRUCT( + // When BOOST_PP_VARIADICS is missing : + BOOST_FUSION_ADAPT_STRUCT( struct_name, (member_type0, member_name0) (member_type1, member_name1) @@ -238,7 +238,7 @@ namespace qualified name of the struct to be adapted. name, age) - // Or demo::employee is also a Fusion sequence + // When BOOST_PP_VARIADICS is missing : BOOST_FUSION_ADAPT_STRUCT( demo::employee, (BOOST_FUSION_ADAPT_AUTO, name) @@ -263,7 +263,7 @@ __random_access_sequence__. ... ) - // When Variadic support isn't available or you wish to manually specify the type: + // When BOOST_PP_VARIADICS is missing : BOOST_FUSION_ADAPT_TPL_STRUCT( (template_param0)(template_param1)..., (struct_name) (specialization_param0)(specialization_param1)..., From 0e50a02fbc696c0597349e1576d1ac304b0888c2 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 11 Jun 2014 02:36:08 +0200 Subject: [PATCH 33/37] Remove deleted unit tests from Jamfile. --- test/Jamfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/Jamfile b/test/Jamfile index 5587ab5d..1c84637d 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -136,15 +136,11 @@ project [ run sequence/adapt_assoc_adt_named.cpp : : : : ] [ run sequence/adapt_assoc_adt.cpp : : : : ] [ run sequence/adapt_assoc_struct_named.cpp : : : : ] - [ run sequence/auto_adapt_assoc_struct_named.cpp : : : : ] [ run sequence/adapt_assoc_struct.cpp : : : : ] - [ run sequence/auto_adapt_assoc_struct.cpp : : : : ] [ run sequence/adapt_assoc_tpl_adt.cpp : : : : ] [ run sequence/adapt_assoc_tpl_struct.cpp : : : : ] [ run sequence/adapt_struct_named.cpp : : : : ] - [ run sequence/auto_adapt_struct_named.cpp : : : : ] [ run sequence/adapt_struct.cpp : : : : ] - [ run sequence/auto_adapt_struct.cpp : : : : ] [ run sequence/adapt_tpl_adt.cpp : : : : ] [ run sequence/adapt_tpl_struct.cpp : : : : ] [ run sequence/adt_attribute_proxy.cpp : : : : ] From 9a501785e65b298e72ce44a9beffdc2e832011ad Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 11 Jun 2014 02:53:36 +0200 Subject: [PATCH 34/37] Removed the old auto_* headers. --- include/boost/fusion/adapted/struct.hpp | 2 - .../struct/auto_adapt_assoc_struct.hpp | 44 --------------- .../struct/auto_adapt_assoc_struct_named.hpp | 56 ------------------- .../struct/auto_adapt_struct_named.hpp | 32 ----------- 4 files changed, 134 deletions(-) delete mode 100644 include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp delete mode 100644 include/boost/fusion/adapted/struct/auto_adapt_assoc_struct_named.hpp delete mode 100644 include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp diff --git a/include/boost/fusion/adapted/struct.hpp b/include/boost/fusion/adapted/struct.hpp index 5a45b596..3f159038 100644 --- a/include/boost/fusion/adapted/struct.hpp +++ b/include/boost/fusion/adapted/struct.hpp @@ -14,9 +14,7 @@ #include #include #include -#include #include -#include #include #include #include diff --git a/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp b/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp deleted file mode 100644 index 936e1e74..00000000 --- a/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/*============================================================================= - Copyright (c) 2001-2007 Joel de Guzman - Copyright (c) 2007 Dan Marsden - Copyright (c) 2009-2011 Christopher Schmidt - Copyright (c) 2013-2014 Damien Buhl - - 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_ADAPTED_STRUCT_AUTO_ADAPT_ASSOC_STRUCT_HPP -#define BOOST_FUSION_ADAPTED_STRUCT_AUTO_ADAPT_ASSOC_STRUCT_HPP - -#include -#include -#include - -#include - -#include - -#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_0(A, B) \ - ((A, B)) BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_1 -#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_1(A, B) \ - ((A, B)) BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_0 -#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_0_END -#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_1_END - -#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_TYPE_DEDUCER(r, NAME, ATTRIBUTE) \ - (BOOST_TYPEOF(NAME::BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE)), \ - BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE), \ - BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE)) - -#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT(NAME, ATTRIBUTES) \ - BOOST_FUSION_ADAPT_ASSOC_STRUCT(NAME, \ - BOOST_PP_SEQ_FOR_EACH( \ - BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_TYPE_DEDUCER, \ - NAME, \ - BOOST_PP_CAT( \ - BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_FILLER_0 ATTRIBUTES,_END) \ - ) \ - ) - -#endif diff --git a/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct_named.hpp b/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct_named.hpp deleted file mode 100644 index 1945c62c..00000000 --- a/include/boost/fusion/adapted/struct/auto_adapt_assoc_struct_named.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/*============================================================================= - Copyright (c) 2010-2011 Christopher Schmidt - Copyright (c) 2013-2014 Damien Buhl - - 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_ADAPTED_STRUCT_AUTO_ADAPT_ASSOC_STRUCT_NAMED_HPP -#define BOOST_FUSION_ADAPTED_STRUCT_AUTO_ADAPT_ASSOC_STRUCT_NAMED_HPP - -#include -#include -#include - -#include - -#include - -#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_0(A, B) \ - ((A, B)) BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_1 -#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_1(A, B) \ - ((A, B)) BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_0 -#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_0_END -#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_1_END - -#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_TYPE_DEDUCER( \ - r, NAME, ATTRIBUTE) \ - (BOOST_TYPEOF( \ - BOOST_PP_TUPLE_ELEM( \ - 2, \ - 0, \ - NAME) \ - ::BOOST_PP_TUPLE_ELEM( \ - 2, \ - 0, \ - ATTRIBUTE)), \ - BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE), \ - BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE)) - -#define BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED( \ - WRAPPED_TYPE, NAME, ATTRIBUTES) \ - \ - BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED(WRAPPED_TYPE, \ - NAME, \ - BOOST_PP_SEQ_FOR_EACH( \ - BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_TYPE_DEDUCER, \ - (WRAPPED_TYPE, NAME), \ - BOOST_PP_CAT( \ - BOOST_FUSION_AUTO_ADAPT_ASSOC_STRUCT_NAMED_FILLER_0 ATTRIBUTES, \ - _END) \ - ) \ - ) - - -#endif diff --git a/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp b/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp deleted file mode 100644 index de81fbcf..00000000 --- a/include/boost/fusion/adapted/struct/auto_adapt_struct_named.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/*============================================================================= - Copyright (c) 2001-2007 Joel de Guzman - Copyright (c) 2009-2010 Hartmut Kaiser - Copyright (c) 2010-2011 Christopher Schmidt - Copyright (c) 2013-2014 Damien Buhl - - - 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_ADAPTED_STRUCT_AUTO_ADAPT_STRUCT_NAMED_HPP -#define BOOST_FUSION_ADAPTED_STRUCT_AUTO_ADAPT_STRUCT_NAMED_HPP - -#include -#include - -#define BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED_NS( \ - WRAPPED_TYPE, NAMESPACE_SEQ, NAME, ATTRIBUTES) \ - \ - BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( \ - WRAPPED_TYPE, NAMESPACE_SEQ, NAME, \ - BOOST_PP_SEQ_FOR_EACH( \ - BOOST_FUSION_AUTO_ADAPT_STRUCT_TYPE_DEDUCER, \ - WRAPPED_TYPE, \ - ATTRIBUTES)) - -#define BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED(WRAPPED_TYPE, NAME, ATTRIBUTES) \ - BOOST_FUSION_AUTO_ADAPT_STRUCT_NAMED_NS( \ - WRAPPED_TYPE,(boost)(fusion)(adapted),NAME,ATTRIBUTES) - -#endif From f0eab528e9c34349acb56cf82e507740718b3304 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sat, 14 Jun 2014 11:40:51 +0200 Subject: [PATCH 35/37] Fix adapt_struct test which was missing an using keyword. --- test/sequence/adapt_struct.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/sequence/adapt_struct.cpp b/test/sequence/adapt_struct.cpp index 819ec009..406030dd 100644 --- a/test/sequence/adapt_struct.cpp +++ b/test/sequence/adapt_struct.cpp @@ -107,6 +107,7 @@ main() { using namespace boost::fusion; using namespace boost; + using ns::point; std::cout << tuple_open('['); std::cout << tuple_close(']'); From af812e6207561bc8e092b0332c802554f4f696cb Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sat, 14 Jun 2014 12:09:04 +0200 Subject: [PATCH 36/37] Fixed ADAPT_STRUCT_FILLER macro call for consistency. --- include/boost/fusion/adapted/struct/adapt_struct.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index 95df82b0..4c798518 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -84,8 +84,8 @@ (1)NAME_SEQ, \ struct_tag, \ 0, \ - ((0,0)) BOOST_PP_CAT( \ - BOOST_FUSION_ADAPT_STRUCT_FILLER_0 ATTRIBUTES,_END), \ + BOOST_PP_CAT( \ + BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ BOOST_FUSION_ADAPT_STRUCT_C) # define BOOST_FUSION_ADAPT_STRUCT(NAME, ATTRIBUTES) \ From ae0c97692683c2f84ab8c18b02ac54f8a2c158d1 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sat, 14 Jun 2014 12:11:44 +0200 Subject: [PATCH 37/37] Fixes missing inclusion of BOOST_PP_LESS. This was bringing the std::pair adapt test to fail, because it wasn't including BOOST_PP_LESS like the other tests. --- include/boost/fusion/adapted/struct/detail/adapt_base.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index 3dafd0cb..c5721224 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include