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/99] #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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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/99] 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 From c008b0dc3afeaa50959bc1ac402e77d9db72d28b Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 17 Jun 2014 22:35:10 +0200 Subject: [PATCH 38/99] Fixes the BOOST_FUSION_DEFINE_STRUCT* macros with an appropriate attributes FILLER macro. As the BOOST_FUSION_ADAPT_STRUCT_FILLER* macros were changed to handle type deduction, this breaks the usage that BOOST_FUSION_DEFINE_STRUCT makes from them. That is BOOST_FUSION_DEFINE_STRUCT_IMPL expects a simple tuple, while we now provide a tuple containing the size of a nested tuple which either has or not the type provided. But in the case of the DEFINE* macros it would be a non-sense to support this kind of API as a field being defined cannot be deduced. :) --- include/boost/fusion/adapted/struct/define_struct.hpp | 4 ++-- .../boost/fusion/adapted/struct/detail/define_struct.hpp | 7 +++++++ .../fusion/adapted/struct/detail/define_struct_inline.hpp | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/boost/fusion/adapted/struct/define_struct.hpp b/include/boost/fusion/adapted/struct/define_struct.hpp index fa1f549f..29785436 100644 --- a/include/boost/fusion/adapted/struct/define_struct.hpp +++ b/include/boost/fusion/adapted/struct/define_struct.hpp @@ -19,7 +19,7 @@ TEMPLATE_PARAMS_SEQ, \ (0)NAMESPACE_SEQ, \ NAME, \ - BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ + BOOST_PP_CAT(BOOST_FUSION_DEFINE_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ 2) \ \ BOOST_FUSION_ADAPT_TPL_STRUCT( \ @@ -32,7 +32,7 @@ BOOST_FUSION_DEFINE_STRUCT_IMPL( \ (0)NAMESPACE_SEQ, \ NAME, \ - BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ + BOOST_PP_CAT(BOOST_FUSION_DEFINE_STRUCT_FILLER_0(0,0)ATTRIBUTES,_END), \ 2) \ \ BOOST_FUSION_ADAPT_STRUCT( \ diff --git a/include/boost/fusion/adapted/struct/detail/define_struct.hpp b/include/boost/fusion/adapted/struct/detail/define_struct.hpp index 44d99f06..a39a18f1 100644 --- a/include/boost/fusion/adapted/struct/detail/define_struct.hpp +++ b/include/boost/fusion/adapted/struct/detail/define_struct.hpp @@ -34,6 +34,13 @@ #include #include +#define BOOST_FUSION_DEFINE_STRUCT_FILLER_0(X, Y) \ + ((X, Y)) BOOST_FUSION_DEFINE_STRUCT_FILLER_1 +#define BOOST_FUSION_DEFINE_STRUCT_FILLER_1(X, Y) \ + ((X, Y)) BOOST_FUSION_DEFINE_STRUCT_FILLER_0 +#define BOOST_FUSION_DEFINE_STRUCT_FILLER_0_END +#define BOOST_FUSION_DEFINE_STRUCT_FILLER_1_END + #define BOOST_FUSION_DEFINE_STRUCT_COPY_CTOR_FILLER_I( \ R, ATTRIBUTE_TUPEL_SIZE, I, ATTRIBUTE) \ \ diff --git a/include/boost/fusion/adapted/struct/detail/define_struct_inline.hpp b/include/boost/fusion/adapted/struct/detail/define_struct_inline.hpp index 87ab09fa..5ddec309 100644 --- a/include/boost/fusion/adapted/struct/detail/define_struct_inline.hpp +++ b/include/boost/fusion/adapted/struct/detail/define_struct_inline.hpp @@ -301,7 +301,7 @@ #define BOOST_FUSION_DEFINE_STRUCT_INLINE_MEMBERS(NAME, ATTRIBUTES) \ BOOST_FUSION_DEFINE_STRUCT_MEMBERS_IMPL( \ NAME, \ - BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_0 ATTRIBUTES,_END)) + BOOST_PP_CAT(BOOST_FUSION_DEFINE_STRUCT_FILLER_0 ATTRIBUTES,_END)) // Note: can't compute BOOST_PP_SEQ_SIZE(ATTRIBUTES_SEQ) directly because // ATTRIBUTES_SEQ may be empty and calling BOOST_PP_SEQ_SIZE on an empty @@ -315,7 +315,7 @@ #define BOOST_FUSION_DEFINE_STRUCT_INLINE_ITERATOR(NAME, ATTRIBUTES) \ BOOST_FUSION_DEFINE_STRUCT_ITERATOR_IMPL( \ NAME, \ - BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_0 ATTRIBUTES,_END)) + BOOST_PP_CAT(BOOST_FUSION_DEFINE_STRUCT_FILLER_0 ATTRIBUTES,_END)) #define BOOST_FUSION_DEFINE_STRUCT_ITERATOR_IMPL(NAME, ATTRIBUTES_SEQ) \ BOOST_FUSION_DEFINE_STRUCT_INLINE_ITERATOR_IMPL_IMPL( \ From abff92ab657333252c9a7a9e00274de99d294d5c Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 25 Jun 2014 00:11:40 +0200 Subject: [PATCH 39/99] Add support for members types deduction to the ADAPT_STRUCT_NAMED macro. --- .../fusion/adapted/struct/adapt_struct.hpp | 18 +++--- .../adapted/struct/adapt_struct_named.hpp | 49 +++++++++----- .../adapted/struct/detail/adapt_base.hpp | 28 ++++---- .../adapted/struct/detail/proxy_type.hpp | 2 + test/sequence/adapt_struct_named.cpp | 64 +++++++++++++------ 5 files changed, 102 insertions(+), 59 deletions(-) diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index 4c798518..9c1d19f1 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -34,14 +34,16 @@ #include #include -#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, \ - BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE), \ - BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE)) +#define BOOST_FUSION_ADAPT_STRUCT_C( \ + TEMPLATE_PARAMS_SEQ, NAME_SEQ, IS_VIEW, I, ATTRIBUTE) \ + BOOST_FUSION_ADAPT_STRUCT_C_BASE( \ + TEMPLATE_PARAMS_SEQ, \ + NAME_SEQ, \ + IS_VIEW, \ + I, \ + BOOST_PP_IF(IS_VIEW, BOOST_FUSION_PROXY_PREFIX, BOOST_PP_EMPTY), \ + BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE), \ + BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE)) #define BOOST_FUSION_ADAPT_AUTO BOOST_PP_EMPTY() diff --git a/include/boost/fusion/adapted/struct/adapt_struct_named.hpp b/include/boost/fusion/adapted/struct/adapt_struct_named.hpp index 3f29f3a3..791fb5b0 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct_named.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct_named.hpp @@ -15,26 +15,41 @@ #include #include -#define BOOST_FUSION_ADAPT_STRUCT_NAMED_FILLER_0(X, Y) \ - (X, obj.Y) BOOST_FUSION_ADAPT_STRUCT_NAMED_FILLER_1 -#define BOOST_FUSION_ADAPT_STRUCT_NAMED_FILLER_1(X, Y) \ - (X, obj.Y) BOOST_FUSION_ADAPT_STRUCT_NAMED_FILLER_0 -#define BOOST_FUSION_ADAPT_STRUCT_NAMED_FILLER_0_END -#define BOOST_FUSION_ADAPT_STRUCT_NAMED_FILLER_1_END +#ifdef BOOST_PP_VARIADICS -#define BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( \ - WRAPPED_TYPE, NAMESPACE_SEQ, NAME, ATTRIBUTES) \ +# define BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( \ + WRAPPED_TYPE, NAMESPACE_SEQ, NAME, ...) \ \ - BOOST_FUSION_ADAPT_STRUCT_DEFINE_PROXY_TYPE_IMPL( \ - WRAPPED_TYPE,(0)NAMESPACE_SEQ,NAME) \ + BOOST_FUSION_ADAPT_STRUCT_DEFINE_PROXY_TYPE_IMPL( \ + WRAPPED_TYPE,(0)NAMESPACE_SEQ,NAME) \ \ - BOOST_FUSION_ADAPT_STRUCT_AS_VIEW( \ - BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION((0)NAMESPACE_SEQ)NAME, \ - BOOST_PP_CAT( \ - BOOST_FUSION_ADAPT_STRUCT_NAMED_FILLER_0 ATTRIBUTES,_END)) + BOOST_FUSION_ADAPT_STRUCT_AS_VIEW( \ + BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION( \ + (0)NAMESPACE_SEQ)NAME, \ + __VA_ARGS__) -#define BOOST_FUSION_ADAPT_STRUCT_NAMED(WRAPPED_TYPE, NAME, ATTRIBUTES) \ - BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( \ - WRAPPED_TYPE,(boost)(fusion)(adapted),NAME,ATTRIBUTES) +# define BOOST_FUSION_ADAPT_STRUCT_NAMED(WRAPPED_TYPE, NAME, ...) \ + BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( \ + WRAPPED_TYPE,(boost)(fusion)(adapted),NAME,__VA_ARGS__) + + +#else // BOOST_PP_VARIADICS + +# define BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( \ + WRAPPED_TYPE, NAMESPACE_SEQ, NAME, ATTRIBUTES) \ + \ + BOOST_FUSION_ADAPT_STRUCT_DEFINE_PROXY_TYPE_IMPL( \ + WRAPPED_TYPE,(0)NAMESPACE_SEQ,NAME) \ + \ + BOOST_FUSION_ADAPT_STRUCT_AS_VIEW( \ + BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION( \ + (0)NAMESPACE_SEQ)NAME, \ + ATTRIBUTES) + +# define BOOST_FUSION_ADAPT_STRUCT_NAMED(WRAPPED_TYPE, NAME, ATTRIBUTES) \ + BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( \ + WRAPPED_TYPE,(boost)(fusion)(adapted),NAME,ATTRIBUTES) + +#endif #endif diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index c5721224..26051395 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -59,16 +59,16 @@ BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS_IMPL, \ BOOST_PP_TUPLE_EAT(1))(SEQ) + #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)) \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ + BOOST_TYPEOF( \ + BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)::PREFIX() \ + BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE)) #define BOOST_FUSION_ATTRIBUTE_GIVENTYPE( \ - NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ - BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, unused) \ + 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( \ @@ -98,9 +98,10 @@ #endif #define BOOST_FUSION_ADAPT_STRUCT_BASE_UNPACK_AND_CALL(R,DATA,I,ATTRIBUTE) \ - BOOST_PP_TUPLE_ELEM(3,0,DATA)( \ - BOOST_PP_TUPLE_ELEM(3,1,DATA), \ - BOOST_PP_TUPLE_ELEM(3,2,DATA), \ + BOOST_PP_TUPLE_ELEM(4,0,DATA)( \ + BOOST_PP_TUPLE_ELEM(4,1,DATA), \ + BOOST_PP_TUPLE_ELEM(4,2,DATA), \ + BOOST_PP_TUPLE_ELEM(4,3,DATA), \ I, \ ATTRIBUTE) @@ -122,7 +123,8 @@ #endif #define BOOST_FUSION_ADAPT_STRUCT_C_BASE( \ - TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,PREFIX,ATTRIBUTE,ATTRIBUTE_TUPEL_SIZE) \ + TEMPLATE_PARAMS_SEQ,NAME_SEQ,IS_VIEW, \ + I,PREFIX,ATTRIBUTE,ATTRIBUTE_TUPEL_SIZE) \ \ template< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \ @@ -135,7 +137,7 @@ typedef \ BOOST_PP_IF(BOOST_PP_LESS(ATTRIBUTE_TUPEL_SIZE,2), \ BOOST_FUSION_ATTRIBUTE_TYPEOF, BOOST_FUSION_ATTRIBUTE_GIVENTYPE \ - )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ + )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ attribute_type; \ BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ TEMPLATE_PARAMS_SEQ) \ @@ -216,7 +218,7 @@ namespace boost BOOST_PP_TUPLE_EAT(4))( \ 1, \ BOOST_FUSION_ADAPT_STRUCT_BASE_UNPACK_AND_CALL, \ - (ATTRIBUTES_CALLBACK,TEMPLATE_PARAMS_SEQ,NAME_SEQ), \ + (ATTRIBUTES_CALLBACK,TEMPLATE_PARAMS_SEQ,NAME_SEQ, IS_VIEW),\ BOOST_PP_SEQ_TAIL(ATTRIBUTES_SEQ)) \ \ template< \ diff --git a/include/boost/fusion/adapted/struct/detail/proxy_type.hpp b/include/boost/fusion/adapted/struct/detail/proxy_type.hpp index 350137a4..f673a37c 100644 --- a/include/boost/fusion/adapted/struct/detail/proxy_type.hpp +++ b/include/boost/fusion/adapted/struct/detail/proxy_type.hpp @@ -12,6 +12,8 @@ #include #include +#define BOOST_FUSION_PROXY_PREFIX() obj. + #define BOOST_FUSION_ADAPT_STRUCT_DEFINE_PROXY_TYPE_IMPL( \ WRAPPED_TYPE,NAMESPACE_SEQ,NAME) \ \ diff --git a/test/sequence/adapt_struct_named.cpp b/test/sequence/adapt_struct_named.cpp index ef859655..aab11d2d 100644 --- a/test/sequence/adapt_struct_named.cpp +++ b/test/sequence/adapt_struct_named.cpp @@ -37,19 +37,39 @@ namespace ns { int x; int y; + int z; }; } -// this creates a fusion view: boost::fusion::adapted::point -BOOST_FUSION_ADAPT_STRUCT_NAMED( - ns::point, point, - (int, x) - (int, y) -) +#if BOOST_PP_VARIADICS -// this creates a fusion view: ns1::s1 -struct s { int m; }; -BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(s, (ns1), s1, (int, m)) + // this creates a fusion view: boost::fusion::adapted::point + BOOST_FUSION_ADAPT_STRUCT_NAMED( + ns::point, point, + x, + y, + z + ) + + // this creates a fusion view: ns1::s1 + struct s { int m; }; + BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(s, (ns1), s1, m) + +#else // BOOST_PP_VARIADICS + + // this creates a fusion view: boost::fusion::adapted::point + BOOST_FUSION_ADAPT_STRUCT_NAMED( + ns::point, point, + (int, x) + (int, y) + (BOOST_FUSION_ADAPT_AUTO, z) + ) + + // this creates a fusion view: ns1::s1 + struct s { int m; }; + BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(s, (ns1), s1, (BOOST_FUSION_ADAPT_AUTO, m)) + +#endif int main() @@ -63,31 +83,33 @@ main() { BOOST_MPL_ASSERT((traits::is_view)); - ns::point basep = {123, 456}; + ns::point basep = {123, 456, 789}; adapted::point p(basep); 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); } { - fusion::vector v1(4, 2); - ns::point p = {5, 3}; + fusion::vector v1(4, 2, 2); + ns::point p = {5, 3, 3}; adapted::point v2(p); - fusion::vector v3(5, 4); + fusion::vector v3(5, 4, 4); BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); @@ -100,17 +122,17 @@ main() { // conversion from adapted::point to vector - ns::point basep = {5, 3}; + ns::point basep = {5, 3, 3}; adapted::point p(basep); - fusion::vector v(p); + fusion::vector v(p); v = p; } { // conversion from adapted::point to list - ns::point basep = {5, 3}; + ns::point basep = {5, 3, 3}; adapted::point p(basep); - fusion::list l(p); + fusion::list l(p); l = p; } From dd0cee1721275b17e85c234eb3b7e06319cc8e22 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 25 Jun 2014 00:24:26 +0200 Subject: [PATCH 40/99] Documented type deduction for ADAPT_STRUCT_NAMED. --- doc/adapted.qbk | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/doc/adapted.qbk b/doc/adapted.qbk index e6adfd29..1b5c97c0 100644 --- a/doc/adapted.qbk +++ b/doc/adapted.qbk @@ -337,10 +337,31 @@ 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, + member_name0, + member_name1, + member_name2, + ... + ) + + BOOST_FUSION_ADAPT_STRUCT_NAMED_NS( + struct_name, + (namespace0)(namespace1)..., + adapted_name, + member_name0, + member_name1, + member_name2, + ... + ) + + // When BOOST_PP_VARIADICS is missing : + BOOST_FUSION_ADAPT_STRUCT_NAMED( struct_name, adapted_name, (member_type0, member_name0) (member_type1, member_name1) + (BOOST_FUSION_ADAPT_AUTO, member_name2), ... ) @@ -350,9 +371,12 @@ adapted using the given name. adapted_name, (member_type0, member_name0) (member_type1, member_name1) + (BOOST_FUSION_ADAPT_AUTO, member_name2), ... ) + + [heading Semantics] The above macros generate the necessary code to adapt `struct_name` @@ -365,9 +389,12 @@ 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. +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 macros should be used at global scope, and `struct_name` should be the fully namespace qualified name of the struct to be converted. @@ -391,8 +418,14 @@ namespace qualified name of the struct to be converted. // referring to demo::employee BOOST_FUSION_ADAPT_STRUCT_NAMED( demo::employee, adapted_employee, - (std::string, name) - (int, age)) + name, + age) + + // When BOOST_PP_VARIADICS is missing : + BOOST_FUSION_ADAPT_STRUCT_NAMED( + demo::employee, adapted_employee, + (BOOST_FUSION_ADAPT_AUTO, name), + (BOOST_FUSION_ADAPT_AUTO, age)) [endsect] From bf66c12cdecc431af80fb2b2c073983d7c2f395a Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 25 Jun 2014 00:25:14 +0200 Subject: [PATCH 41/99] Fix the unit test of adapt_struct for consistency with other tests of the same kind. --- test/sequence/adapt_struct.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sequence/adapt_struct.cpp b/test/sequence/adapt_struct.cpp index 406030dd..76019644 100644 --- a/test/sequence/adapt_struct.cpp +++ b/test/sequence/adapt_struct.cpp @@ -159,7 +159,7 @@ main() { // conversion from point to list point p = {5, 3, 3}; - list l(p); + list l(p); l = p; } From 34fac0c4491b6be9763f95ce6786cc4373c95028 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 25 Jun 2014 00:45:38 +0200 Subject: [PATCH 42/99] Fix ADAPT_*_C / ADAPT_*_C_BASE macros responsible. These macros are used to handle generation of boilerplate code or each member to add to the adapted sequence. And in the commit abff92ab657333252c9a7a9e00274de99d294d5c we changed the signature of these macros to handle generation of proxied object field type deduction, this change simply fix the related macros. --- include/boost/fusion/adapted/adt/adapt_adt.hpp | 7 ++++--- include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp | 2 +- .../boost/fusion/adapted/struct/adapt_assoc_struct.hpp | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/boost/fusion/adapted/adt/adapt_adt.hpp b/include/boost/fusion/adapted/adt/adapt_adt.hpp index 3be25b1e..88ab177c 100644 --- a/include/boost/fusion/adapted/adt/adapt_adt.hpp +++ b/include/boost/fusion/adapted/adt/adapt_adt.hpp @@ -40,9 +40,10 @@ #define BOOST_FUSION_ADAPT_ADT_FILLER_0_END #define BOOST_FUSION_ADAPT_ADT_FILLER_1_END -#define BOOST_FUSION_ADAPT_ADT_C(TEMPLATE_PARAMS_SEQ, NAME_SEQ, I, ATTRIBUTE) \ - BOOST_FUSION_ADAPT_ADT_C_BASE( \ - TEMPLATE_PARAMS_SEQ, NAME_SEQ, I, ATTRIBUTE, 4) +#define BOOST_FUSION_ADAPT_ADT_C( \ + TEMPLATE_PARAMS_SEQ, NAME_SEQ, IS_VIEW, I, ATTRIBUTE) \ + BOOST_FUSION_ADAPT_ADT_C_BASE( \ + TEMPLATE_PARAMS_SEQ, NAME_SEQ, I, ATTRIBUTE, 4) #define BOOST_FUSION_ADAPT_TPL_ADT(TEMPLATE_PARAMS_SEQ, NAME_SEQ , ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ diff --git a/include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp b/include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp index 12bf6aa2..ff33ac59 100644 --- a/include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp +++ b/include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp @@ -44,7 +44,7 @@ #define BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_1_END #define BOOST_FUSION_ADAPT_ASSOC_ADT_C( \ - TEMPLATE_PARAMS_SEQ, NAME_SEQ, I, ATTRIBUTE) \ + TEMPLATE_PARAMS_SEQ, NAME_SEQ, IS_VIEW, I, ATTRIBUTE) \ \ BOOST_FUSION_ADAPT_ADT_C_BASE(TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,ATTRIBUTE,5) \ \ diff --git a/include/boost/fusion/adapted/struct/adapt_assoc_struct.hpp b/include/boost/fusion/adapted/struct/adapt_assoc_struct.hpp index eca77d61..c0665ae6 100644 --- a/include/boost/fusion/adapted/struct/adapt_assoc_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_assoc_struct.hpp @@ -43,10 +43,10 @@ #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1_END #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_C_BASE( \ - TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,PREFIX,ATTRIBUTE) \ + TEMPLATE_PARAMS_SEQ,NAME_SEQ,IS_VIEW,I,PREFIX,ATTRIBUTE) \ \ BOOST_FUSION_ADAPT_STRUCT_C_BASE( \ - TEMPLATE_PARAMS_SEQ, NAME_SEQ, I, PREFIX, ATTRIBUTE, 3) \ + TEMPLATE_PARAMS_SEQ, NAME_SEQ, IS_VIEW, I, PREFIX, ATTRIBUTE, 3) \ \ template< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \ @@ -57,10 +57,10 @@ }; #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_C( \ - TEMPLATE_PARAMS_SEQ,NAME_SEQ, I, ATTRIBUTE) \ + TEMPLATE_PARAMS_SEQ,NAME_SEQ,IS_VIEW, I, ATTRIBUTE) \ \ BOOST_FUSION_ADAPT_ASSOC_STRUCT_C_BASE( \ - TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,BOOST_PP_EMPTY,ATTRIBUTE) + TEMPLATE_PARAMS_SEQ,NAME_SEQ,IS_VIEW,I,BOOST_PP_EMPTY,ATTRIBUTE) #define BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( \ TEMPLATE_PARAMS_SEQ, NAME_SEQ, ATTRIBUTES) \ From 17e49ba4488eb82e5f647e115785a2ddc9de7071 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 23 Jul 2014 00:36:07 +0200 Subject: [PATCH 43/99] Adds accessors for the wrapped attributes and provide preliminary support for type deduction to ADAPT_ASSOC* macros. --- .../adapted/struct/adapt_assoc_struct.hpp | 21 +++++++------ .../fusion/adapted/struct/adapt_struct.hpp | 5 +-- .../adapted/struct/detail/adapt_base.hpp | 12 ++++--- .../struct/detail/adapt_base_attr_filler.hpp | 31 +++++++++++++++++++ 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/include/boost/fusion/adapted/struct/adapt_assoc_struct.hpp b/include/boost/fusion/adapted/struct/adapt_assoc_struct.hpp index c0665ae6..1de7efe3 100644 --- a/include/boost/fusion/adapted/struct/adapt_assoc_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_assoc_struct.hpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -35,25 +36,27 @@ #include #include -#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0(X, Y, Z) \ - ((X, Y, Z)) BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1 -#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1(X, Y, Z) \ - ((X, Y, Z)) BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0 -#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0_END -#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1_END - #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_C_BASE( \ TEMPLATE_PARAMS_SEQ,NAME_SEQ,IS_VIEW,I,PREFIX,ATTRIBUTE) \ \ BOOST_FUSION_ADAPT_STRUCT_C_BASE( \ - TEMPLATE_PARAMS_SEQ, NAME_SEQ, IS_VIEW, I, PREFIX, ATTRIBUTE, 3) \ + TEMPLATE_PARAMS_SEQ, \ + NAME_SEQ, \ + IS_VIEW, \ + I, \ + PREFIX, \ + BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR(ATTRIBUTE), \ + BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE), \ + BOOST_PP_IF(BOOST_PP_LESS( \ + BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE),3), 1, 0)) \ \ template< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \ > \ struct struct_assoc_key \ { \ - typedef BOOST_PP_TUPLE_ELEM(3, 2, ATTRIBUTE) type; \ + typedef \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_WRAPPEDATTR_GET_KEY(ATTRIBUTE) type; \ }; #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_C( \ diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index 9c1d19f1..09c9015a 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -43,10 +43,11 @@ I, \ BOOST_PP_IF(IS_VIEW, BOOST_FUSION_PROXY_PREFIX, BOOST_PP_EMPTY), \ BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE), \ - BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE)) + BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE), \ + BOOST_PP_IF( \ + BOOST_PP_LESS(BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE),2), 1, 0)) -#define BOOST_FUSION_ADAPT_AUTO BOOST_PP_EMPTY() #if BOOST_PP_VARIADICS diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index 26051395..ce92db05 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -35,6 +35,8 @@ #include +#define BOOST_FUSION_ADAPT_AUTO BOOST_PP_EMPTY() + #define BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME_TEMPLATE_PARAMS(SEQ) \ BOOST_PP_SEQ_HEAD(SEQ) \ BOOST_PP_EMPTY() @@ -124,7 +126,8 @@ #define BOOST_FUSION_ADAPT_STRUCT_C_BASE( \ TEMPLATE_PARAMS_SEQ,NAME_SEQ,IS_VIEW, \ - I,PREFIX,ATTRIBUTE,ATTRIBUTE_TUPEL_SIZE) \ + I,PREFIX,ATTRIBUTE,ATTRIBUTE_TUPEL_SIZE, \ + DEDUCE_TYPE) \ \ template< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \ @@ -135,7 +138,7 @@ > \ { \ typedef \ - BOOST_PP_IF(BOOST_PP_LESS(ATTRIBUTE_TUPEL_SIZE,2), \ + BOOST_PP_IF(DEDUCE_TYPE, \ BOOST_FUSION_ATTRIBUTE_TYPEOF, BOOST_FUSION_ATTRIBUTE_GIVENTYPE \ )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ attribute_type; \ @@ -163,8 +166,7 @@ { \ return seq.PREFIX() \ BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, \ - BOOST_PP_IF(BOOST_PP_LESS(ATTRIBUTE_TUPEL_SIZE,2), 0, 1),\ - ATTRIBUTE); \ + BOOST_PP_IF(DEDUCE_TYPE, 0, 1), ATTRIBUTE); \ } \ }; \ }; \ @@ -185,7 +187,7 @@ { \ return BOOST_PP_STRINGIZE( \ BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, \ - BOOST_PP_IF(BOOST_PP_LESS(ATTRIBUTE_TUPEL_SIZE,2), 0, 1),\ + BOOST_PP_IF(DEDUCE_TYPE, 0, 1), \ ATTRIBUTE)); \ } \ }; 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 index 4ad03a26..4214d9ac 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base_attr_filler.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base_attr_filler.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -34,6 +35,36 @@ ((2, (X,Y))) \ ) +#define BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE) \ + BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE) + +#define BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR(ATTRIBUTE) \ + BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE) + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0(X, Y, Z) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(X, Y, Z) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1 + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1(X, Y, Z) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(X, Y, Z) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0 + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0_END +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1_END + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(X, Y, Z) \ + BOOST_PP_IF(BOOST_PP_IS_EMPTY(X), \ + ((2, (Y,Z))), \ + ((3, (X,Y,Z))) \ + ) + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_WRAPPEDATTR_GET_KEY(ATTRIBUTE) \ + BOOST_PP_TUPLE_ELEM( \ + BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE), \ + BOOST_PP_SUB(BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE), 1), \ + BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR(ATTRIBUTE)) + + #if BOOST_PP_VARIADICS # define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER_OP(r, data, elem) \ From 5422ba7f8f9a450001513f84035cfd83d39992a1 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 23 Jul 2014 02:42:30 +0200 Subject: [PATCH 44/99] Adds the possibility to omit the member type in ADAPT_ASSOC* macros usage. This feature is enabled when BOOST_PP_VARIADICS also is, as it rely on it. A placeholder for the type can be used when BOOST_PP_VARIADICS isn't active. --- .../adapted/struct/adapt_assoc_struct.hpp | 3 +- .../detail/adapt_base_assoc_attr_filler.hpp | 62 +++++++++++++++++++ .../struct/detail/adapt_base_attr_filler.hpp | 34 ++-------- test/sequence/adapt_assoc_struct.cpp | 20 ++++-- 4 files changed, 84 insertions(+), 35 deletions(-) create mode 100644 include/boost/fusion/adapted/struct/detail/adapt_base_assoc_attr_filler.hpp diff --git a/include/boost/fusion/adapted/struct/adapt_assoc_struct.hpp b/include/boost/fusion/adapted/struct/adapt_assoc_struct.hpp index 1de7efe3..eab4e1bb 100644 --- a/include/boost/fusion/adapted/struct/adapt_assoc_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_assoc_struct.hpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include @@ -65,6 +65,7 @@ BOOST_FUSION_ADAPT_ASSOC_STRUCT_C_BASE( \ TEMPLATE_PARAMS_SEQ,NAME_SEQ,IS_VIEW,I,BOOST_PP_EMPTY,ATTRIBUTE) + #define BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( \ TEMPLATE_PARAMS_SEQ, NAME_SEQ, ATTRIBUTES) \ \ diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base_assoc_attr_filler.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base_assoc_attr_filler.hpp new file mode 100644 index 00000000..494bc064 --- /dev/null +++ b/include/boost/fusion/adapted/struct/detail/adapt_base_assoc_attr_filler.hpp @@ -0,0 +1,62 @@ +/*============================================================================= + 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_ASSOC_ATTR_FILLER_HPP +#define BOOST_FUSION_ADAPTED_STRUCT_DETAIL_ADAPT_BASE_ASSOC_ATTR_FILLER_HPP + +#include + +#include + +#include +#include +#include +#include +#include + +#if BOOST_PP_VARIADICS + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0(...) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(__VA_ARGS__) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1 + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1(...) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(__VA_ARGS__) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0 + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(...) \ + ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) + +#else + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0(X, Y, Z) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(X, Y, Z) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1 + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1(X, Y, Z) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(X, Y, Z) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0 + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(X, Y, Z) \ + BOOST_PP_IF(BOOST_PP_IS_EMPTY(X), \ + ((2, (Y,Z))), \ + ((3, (X,Y,Z))) \ + ) + +#endif + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0_END +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1_END + + +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_WRAPPEDATTR_GET_KEY(ATTRIBUTE) \ + BOOST_PP_TUPLE_ELEM( \ + BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE), \ + BOOST_PP_SUB(BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE), 1), \ + BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR(ATTRIBUTE)) + +#endif 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 index 4214d9ac..096cc1b9 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base_attr_filler.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base_attr_filler.hpp @@ -12,12 +12,13 @@ #include #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 @@ -41,46 +42,21 @@ #define BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR(ATTRIBUTE) \ BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE) -#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0(X, Y, Z) \ - BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(X, Y, Z) \ - BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1 - -#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1(X, Y, Z) \ - BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(X, Y, Z) \ - BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0 - -#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0_END -#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1_END - -#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(X, Y, Z) \ - BOOST_PP_IF(BOOST_PP_IS_EMPTY(X), \ - ((2, (Y,Z))), \ - ((3, (X,Y,Z))) \ - ) - -#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_WRAPPEDATTR_GET_KEY(ATTRIBUTE) \ - BOOST_PP_TUPLE_ELEM( \ - BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE), \ - BOOST_PP_SUB(BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE), 1), \ - BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR(ATTRIBUTE)) - #if BOOST_PP_VARIADICS -# define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER_OP(r, data, elem) \ +# define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER_OP(r, unused, 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) \ - ) + 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) \ - ) + (0,0)) #endif // BOOST_PP_VARIADICS diff --git a/test/sequence/adapt_assoc_struct.cpp b/test/sequence/adapt_assoc_struct.cpp index 62574a7e..e114f377 100644 --- a/test/sequence/adapt_assoc_struct.cpp +++ b/test/sequence/adapt_assoc_struct.cpp @@ -50,11 +50,21 @@ namespace ns }; } -BOOST_FUSION_ADAPT_ASSOC_STRUCT( - ns::point, - (int, x, ns::x_member) - (int, y, ns::y_member) -) +#if BOOST_PP_VARIADICS + BOOST_FUSION_ADAPT_ASSOC_STRUCT( + ns::point, + (x, ns::x_member) + (int, y, ns::y_member) + ) + +#else // BOOST_PP_VARIADICS + BOOST_FUSION_ADAPT_ASSOC_STRUCT( + ns::point, + (BOOST_FUSION_ADAPT_AUTO, x, ns::x_member) + (int, y, ns::y_member) + ) + +#endif int main() From a5d6fd0800766a18805ae336ca9529ac451ee122 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 23 Jul 2014 02:49:28 +0200 Subject: [PATCH 45/99] Test adapt_assoc_tpl_struct checking support for type deduction. --- test/sequence/adapt_assoc_tpl_struct.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/test/sequence/adapt_assoc_tpl_struct.cpp b/test/sequence/adapt_assoc_tpl_struct.cpp index a327f9e8..ad4c19f4 100644 --- a/test/sequence/adapt_assoc_tpl_struct.cpp +++ b/test/sequence/adapt_assoc_tpl_struct.cpp @@ -47,12 +47,22 @@ namespace ns }; } -BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( - (X)(Y), - (ns::point)(X)(Y), - (int, x, ns::x_member) - (int, y, ns::y_member) -) +#if BOOST_PP_VARIADICS + BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( + (X)(Y), + (ns::point)(X)(Y), + (x, ns::x_member) + (y, ns::y_member) + ) + +#else // BOOST_PP_VARIADICS + BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( + (X)(Y), + (ns::point)(X)(Y), + (int, x, ns::x_member) + (BOOST_FUSION_ADAPT_AUTO, y, ns::y_member) + ) +#endif int main() From a13d1346f6aae0bb994fe299496ada62067bb63d Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 27 Jul 2014 15:51:12 +0200 Subject: [PATCH 46/99] Adapted tests of assoc_struct to the type-deducing version of the ADAPT* macros. --- test/sequence/adapt_assoc_struct.cpp | 45 ++++++++++++++++++---------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/test/sequence/adapt_assoc_struct.cpp b/test/sequence/adapt_assoc_struct.cpp index e114f377..4cdabb87 100644 --- a/test/sequence/adapt_assoc_struct.cpp +++ b/test/sequence/adapt_assoc_struct.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -42,11 +43,13 @@ namespace ns struct x_member; struct y_member; struct z_member; + struct non_member; struct point { int x; int y; + int z; }; } @@ -54,14 +57,16 @@ namespace ns BOOST_FUSION_ADAPT_ASSOC_STRUCT( ns::point, (x, ns::x_member) - (int, y, ns::y_member) + (y, ns::y_member) + (int, z, ns::z_member) ) #else // BOOST_PP_VARIADICS BOOST_FUSION_ADAPT_ASSOC_STRUCT( ns::point, (BOOST_FUSION_ADAPT_AUTO, x, ns::x_member) - (int, y, ns::y_member) + (BOOST_FUSION_ADAPT_AUTO, y, ns::y_member) + (int, z, ns::z_member) ) #endif @@ -78,28 +83,30 @@ main() { BOOST_MPL_ASSERT_NOT((traits::is_view)); - ns::point p = {123, 456}; + ns::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); } { - fusion::vector v1(4, 2); - ns::point v2 = {5, 3}; - fusion::vector v3(5, 4); + fusion::vector v1(4, 2, 2); + ns::point v2 = {5, 3, 3}; + fusion::vector v3(5, 4, 4); BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); @@ -112,15 +119,15 @@ main() { // conversion from ns::point to vector - ns::point p = {5, 3}; - fusion::vector v(p); + ns::point p = {5, 3, 3}; + 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, 3}; + fusion::list l(p); l = p; } @@ -128,15 +135,18 @@ main() // 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::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>)); + BOOST_MPL_ASSERT((boost::is_same::type, int>)); - ns::point p = {5, 3}; + ns::point p = {5, 3, 9}; BOOST_TEST(at_key(p) == 5); BOOST_TEST(at_key(p) == 3); + BOOST_TEST(at_key(p) == 9); } { @@ -144,6 +154,9 @@ main() BOOST_MPL_ASSERT((boost::is_same< boost::fusion::result_of::value_at_c::type , mpl::front::type>)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c::type + , mpl::back::type>)); } return boost::report_errors(); From 4b0bed40f7bf0359cf5f4c50a8e1cff81ebb2ead Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 27 Jul 2014 16:07:47 +0200 Subject: [PATCH 47/99] Renamed macro wrapping attribute to a more descriptive name. --- .../struct/detail/adapt_base_assoc_attr_filler.hpp | 12 ++++++------ .../adapted/struct/detail/adapt_base_attr_filler.hpp | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base_assoc_attr_filler.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base_assoc_attr_filler.hpp index 494bc064..725af756 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base_assoc_attr_filler.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base_assoc_attr_filler.hpp @@ -21,27 +21,27 @@ #if BOOST_PP_VARIADICS #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0(...) \ - BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(__VA_ARGS__) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_WRAP_ATTR(__VA_ARGS__) \ BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1 #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1(...) \ - BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(__VA_ARGS__) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_WRAP_ATTR(__VA_ARGS__) \ BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0 -#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(...) \ +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_WRAP_ATTR(...) \ ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) #else #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0(X, Y, Z) \ - BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(X, Y, Z) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_WRAP_ATTR(X, Y, Z) \ BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1 #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1(X, Y, Z) \ - BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(X, Y, Z) \ + BOOST_FUSION_ADAPT_ASSOC_STRUCT_WRAP_ATTR(X, Y, Z) \ BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0 -#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_ATTRIBUTE_FILLER(X, Y, Z) \ +#define BOOST_FUSION_ADAPT_ASSOC_STRUCT_WRAP_ATTR(X, Y, Z) \ BOOST_PP_IF(BOOST_PP_IS_EMPTY(X), \ ((2, (Y,Z))), \ ((3, (X,Y,Z))) \ 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 index 096cc1b9..ac3d90ad 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base_attr_filler.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base_attr_filler.hpp @@ -20,17 +20,17 @@ #define BOOST_FUSION_ADAPT_STRUCT_FILLER_0(X, Y) \ - BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTE_FILLER(X,Y) \ + BOOST_FUSION_ADAPT_STRUCT_WRAP_ATTR(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_WRAP_ATTR(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) \ +#define BOOST_FUSION_ADAPT_STRUCT_WRAP_ATTR(X, Y) \ BOOST_PP_IF(BOOST_PP_IS_EMPTY(X), \ ((1, (Y))), \ ((2, (X,Y))) \ @@ -48,7 +48,7 @@ # define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER_OP(r, unused, 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, \ + BOOST_FUSION_ADAPT_STRUCT_WRAP_ATTR(BOOST_FUSION_ADAPT_AUTO, \ elem)) # define BOOST_FUSION_ADAPT_STRUCT_ATTRIBUTES_FILLER(...) \ From a54c543dd7aa96686a58b467bacb4b43735afeab Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 27 Jul 2014 16:31:15 +0200 Subject: [PATCH 48/99] Adapted test cases for adapt_assoc_tpl_struct with type deduction. --- test/sequence/adapt_assoc_tpl_struct.cpp | 56 ++++++++++++++---------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/test/sequence/adapt_assoc_tpl_struct.cpp b/test/sequence/adapt_assoc_tpl_struct.cpp index ad4c19f4..6adcc931 100644 --- a/test/sequence/adapt_assoc_tpl_struct.cpp +++ b/test/sequence/adapt_assoc_tpl_struct.cpp @@ -39,28 +39,33 @@ namespace ns struct y_member; struct z_member; - template + struct non_member; + + template struct point { X x; Y y; + Z z; }; } #if BOOST_PP_VARIADICS BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( - (X)(Y), - (ns::point)(X)(Y), - (x, ns::x_member) - (y, ns::y_member) + (X)(Y)(Z), + (ns::point)(X)(Y)(Z), + (int, x, ns::x_member) + (Y, y, ns::y_member) + (z, ns::z_member) ) #else // BOOST_PP_VARIADICS BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( - (X)(Y), - (ns::point)(X)(Y), + (X)(Y)(Z), + (ns::point)(X)(Y)(Z), (int, x, ns::x_member) - (BOOST_FUSION_ADAPT_AUTO, y, ns::y_member) + (Y, y, ns::y_member) + (BOOST_FUSION_ADAPT_AUTO, z, ns::z_member) ) #endif @@ -69,7 +74,7 @@ main() { using namespace boost::fusion; - typedef ns::point point; + typedef ns::point point; std::cout << tuple_open('['); std::cout << tuple_close(']'); @@ -77,28 +82,30 @@ main() { BOOST_MPL_ASSERT_NOT((traits::is_view)); - point p = {123, 456}; + point p = {123, 456, 789.43f}; 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.43f)); 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.13f); BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); @@ -111,15 +118,15 @@ 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}; - list l(p); + point p = {5, 3, 3}; + list l(p); l = p; } @@ -127,15 +134,18 @@ main() // 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::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>)); + BOOST_MPL_ASSERT((boost::is_same::type, float>)); - point p = {5, 3}; + point p = {5, 3, 9}; BOOST_TEST(at_key(p) == 5); BOOST_TEST(at_key(p) == 3); + BOOST_TEST(at_key(p) == 9); } return boost::report_errors(); From fcb579f208dc69b9811ae64ab80181478a508191 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 27 Jul 2014 17:19:15 +0200 Subject: [PATCH 49/99] Documented BOOST_FUSION_ADAT_ASSOC* macros with type inference. --- doc/adapted.qbk | 82 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 27 deletions(-) diff --git a/doc/adapted.qbk b/doc/adapted.qbk index 1b5c97c0..c11d733e 100644 --- a/doc/adapted.qbk +++ b/doc/adapted.qbk @@ -193,7 +193,7 @@ __random_access_sequence__. ... ) - // When BOOST_PP_VARIADICS is missing : + // Without BOOST_PP_VARIADICS support : BOOST_FUSION_ADAPT_STRUCT( struct_name, (member_type0, member_name0) @@ -211,8 +211,8 @@ 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. +When member_typeN is omitted or set to BOOST_FUSION_ADAPT_AUTO, the type is +infered with 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. @@ -238,7 +238,7 @@ namespace qualified name of the struct to be adapted. name, age) - // When BOOST_PP_VARIADICS is missing : + // Without BOOST_PP_VARIADICS support : BOOST_FUSION_ADAPT_STRUCT( demo::employee, (BOOST_FUSION_ADAPT_AUTO, name) @@ -263,7 +263,7 @@ __random_access_sequence__. ... ) - // When BOOST_PP_VARIADICS is missing : + // Without BOOST_PP_VARIADICS support : BOOST_FUSION_ADAPT_TPL_STRUCT( (template_param0)(template_param1)..., (struct_name) (specialization_param0)(specialization_param1)..., @@ -287,8 +287,8 @@ 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. +When member_typeN is omitted or set to BOOST_FUSION_ADAPT_AUTO, the type is +infered with 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. @@ -355,7 +355,7 @@ adapted using the given name. ... ) - // When BOOST_PP_VARIADICS is missing : + // Without BOOST_PP_VARIADICS support : BOOST_FUSION_ADAPT_STRUCT_NAMED( struct_name, adapted_name, @@ -393,8 +393,8 @@ 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. +When member_typeN is omitted or set to BOOST_FUSION_ADAPT_AUTO, the type is +infered with 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. @@ -421,7 +421,7 @@ namespace qualified name of the struct to be converted. name, age) - // When BOOST_PP_VARIADICS is missing : + // Without BOOST_PP_VARIADICS support : BOOST_FUSION_ADAPT_STRUCT_NAMED( demo::employee, adapted_employee, (BOOST_FUSION_ADAPT_AUTO, name), @@ -439,8 +439,8 @@ __random_access_sequence__ and __associative_sequence__. [heading Synopsis] BOOST_FUSION_ADAPT_ASSOC_STRUCT( struct_name, - (member_type0, member_name0, key_type0) - (member_type1, member_name1, key_type1) + ([member_type0,] member_name0, key_type0) + ([member_type1,] member_name1, key_type1) ... ) @@ -448,10 +448,13 @@ __random_access_sequence__ and __associative_sequence__. 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 +The sequence of `([member_typeN,] member_nameN, key_typeN)` tuples +declares the type, name and key type of each of the struct members that are part of the sequence. +When member_typeN is omitted or set to BOOST_FUSION_ADAPT_AUTO, the type is +infered with 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. @@ -481,8 +484,14 @@ namespace qualified name of the struct to be adapted. // keys keys::name and keys::age present. BOOST_FUSION_ADAPT_ASSOC_STRUCT( demo::employee, - (std::string, name, keys::name) - (int, age, keys::age)) + (name, keys::name) + (age, keys::age)) + + // Without BOOST_PP_VARIADICS support : + BOOST_FUSION_ADAPT_ASSOC_STRUCT( + demo::employee, + (BOOST_FUSION_ADAPT_AUTO, name, keys::name), + (BOOST_FUSION_ADAPT_AUTO, age, keys::name)) [endsect] @@ -497,8 +506,8 @@ __random_access_sequence__ and __associative_sequence__. BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( (template_param0)(template_param1)..., (struct_name) (specialization_param0)(specialization_param1)..., - (member_type0, member_name0, key_type0) - (member_type1, member_name1, key_type1) + ([member_type0,] member_name0, key_type0) + ([member_type1,] member_name1, key_type1) ... ) @@ -512,10 +521,13 @@ 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, key_typeN)` -triples declares the type, name and key type of each of the struct members +The sequence of `([member_typeN,] member_nameN, key_typeN)` +tuples declares the type, name and key type of each of the struct members that are part of the sequence. +When member_typeN is omitted or set to BOOST_FUSION_ADAPT_AUTO, the type is +infered with 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. @@ -544,6 +556,13 @@ namespace qualified name of the struct to be adapted. // Any instantiated demo::employee is now a Fusion sequence. // It is also an associative sequence with // keys keys::name and keys::age present. + BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( + (Name)(Age), + (demo::employee) (Name)(Age), + (name, keys::name) + (age, keys::age)) + + // Without BOOST_PP_VARIADICS support : BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( (Name)(Age), (demo::employee) (Name)(Age), @@ -563,8 +582,8 @@ __associative_sequence__. The given struct is adapted using the given name. [heading Synopsis] BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED( struct_name, adapted_name, - (member_type0, member_name0, key_type0) - (member_type1, member_name1, key_type1) + ([member_type0,] member_name0, key_type0) + ([member_type1,] member_name1, key_type1) ... ) @@ -572,8 +591,8 @@ __associative_sequence__. The given struct is adapted using the given name. struct_name, (namespace0)(namespace1)..., adapted_name, - (member_type0, member_name0, key_type0) - (member_type1, member_name1, key_type1) + ([member_type0,] member_name0, key_type0) + ([member_type1,] member_name1, key_type1) ... ) @@ -593,6 +612,9 @@ 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. +When member_typeN is omitted or set to BOOST_FUSION_ADAPT_AUTO, the type is +infered with 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. @@ -621,8 +643,14 @@ namespace qualified name of the struct to be converted. // referring to demo::employee BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED( demo::employee, adapted_employee, - (std::string, name, keys::name) - (int, age, keys::age)) + (name, keys::name) + (age, keys::age)) + + // Without BOOST_PP_VARIADICS support : + BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED( + demo::employee, adapted_employee, + (BOOST_FUSION_ADAPT_AUTO, name, keys::name) + (BOOST_FUSION_ADAPT_AUTO, age, keys::age)) [endsect] From 047b0525480dc611e0ce27e279ba99197fceb649 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 29 Jul 2014 22:22:54 +0200 Subject: [PATCH 50/99] Add missing include. --- .../fusion/adapted/struct/detail/adapt_base_attr_filler.hpp | 1 + 1 file changed, 1 insertion(+) 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 index ac3d90ad..69d5b204 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base_attr_filler.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base_attr_filler.hpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include From 0715e996e27d2d1a6547a83c1cde122330db9c6a Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 29 Jul 2014 22:24:23 +0200 Subject: [PATCH 51/99] Fix the DEFINE_ASSOC_STRUCT macros to use specific FILLER macros, because they cannot need type deduction. --- .../fusion/adapted/struct/define_assoc_struct.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/boost/fusion/adapted/struct/define_assoc_struct.hpp b/include/boost/fusion/adapted/struct/define_assoc_struct.hpp index 1f5ce8dc..f4a3679d 100644 --- a/include/boost/fusion/adapted/struct/define_assoc_struct.hpp +++ b/include/boost/fusion/adapted/struct/define_assoc_struct.hpp @@ -12,6 +12,13 @@ #include #include +#define BOOST_FUSION_DEFINE_ASSOC_STRUCT_FILLER_0(X, Y, Z) \ + ((X, Y, Z)) BOOST_FUSION_DEFINE_ASSOC_STRUCT_FILLER_1 +#define BOOST_FUSION_DEFINE_ASSOC_STRUCT_FILLER_1(X, Y, Z) \ + ((X, Y, Z)) BOOST_FUSION_DEFINE_ASSOC_STRUCT_FILLER_0 +#define BOOST_FUSION_DEFINE_ASSOC_STRUCT_FILLER_0_END +#define BOOST_FUSION_DEFINE_ASSOC_STRUCT_FILLER_1_END + #define BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT( \ TEMPLATE_PARAMS_SEQ, NAMESPACE_SEQ, NAME, ATTRIBUTES) \ \ @@ -20,7 +27,7 @@ (0)NAMESPACE_SEQ, \ NAME, \ BOOST_PP_CAT( \ - BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0(0,0,0)ATTRIBUTES,_END), \ + BOOST_FUSION_DEFINE_ASSOC_STRUCT_FILLER_0(0,0,0)ATTRIBUTES,_END), \ 3) \ \ BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( \ @@ -34,7 +41,7 @@ (0)NAMESPACE_SEQ, \ NAME, \ BOOST_PP_CAT( \ - BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0(0,0,0)ATTRIBUTES,_END), \ + BOOST_FUSION_DEFINE_ASSOC_STRUCT_FILLER_0(0,0,0)ATTRIBUTES,_END), \ 3) \ \ BOOST_FUSION_ADAPT_ASSOC_STRUCT( \ From c8e4172021f1a65b44738e8025df0a4af7a56d09 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 10 Aug 2014 15:11:34 +0200 Subject: [PATCH 52/99] Fix indentation. --- include/boost/fusion/adapted/struct/detail/adapt_base.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index ce92db05..1d054c46 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -64,13 +64,13 @@ #define BOOST_FUSION_ATTRIBUTE_TYPEOF( \ NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ - BOOST_TYPEOF( \ - BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)::PREFIX() \ - BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE)) + BOOST_TYPEOF( \ + BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)::PREFIX() \ + BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE)) #define BOOST_FUSION_ATTRIBUTE_GIVENTYPE( \ NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, unused) \ - BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) + 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( \ From fe3682ac0202faef7b4cede7fa15dc6195a640e5 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 10 Aug 2014 15:15:31 +0200 Subject: [PATCH 53/99] add type deduction support to BOOST_FUSION_ADAPT_ADT_C_BASE. --- .../boost/fusion/adapted/adt/adapt_adt.hpp | 8 ++- .../fusion/adapted/adt/detail/adapt_base.hpp | 51 ++++++++++++++++--- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/include/boost/fusion/adapted/adt/adapt_adt.hpp b/include/boost/fusion/adapted/adt/adapt_adt.hpp index 88ab177c..fd91541a 100644 --- a/include/boost/fusion/adapted/adt/adapt_adt.hpp +++ b/include/boost/fusion/adapted/adt/adapt_adt.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,12 @@ #define BOOST_FUSION_ADAPT_ADT_C( \ TEMPLATE_PARAMS_SEQ, NAME_SEQ, IS_VIEW, I, ATTRIBUTE) \ BOOST_FUSION_ADAPT_ADT_C_BASE( \ - TEMPLATE_PARAMS_SEQ, NAME_SEQ, I, ATTRIBUTE, 4) + TEMPLATE_PARAMS_SEQ, \ + NAME_SEQ, \ + I, \ + ATTRIBUTE, \ + 4, \ + BOOST_PP_BOOL(0)) #define BOOST_FUSION_ADAPT_TPL_ADT(TEMPLATE_PARAMS_SEQ, NAME_SEQ , ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index 3de396dd..b155fc3c 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -16,6 +16,8 @@ #include #include #include +#include +#include #define BOOST_FUSION_ADAPT_ADT_GET_IDENTITY_TEMPLATE_IMPL(TEMPLATE_PARAMS_SEQ) \ typename detail::get_identity< \ @@ -28,8 +30,27 @@ \ boost::remove_const::type>::type +#define BOOST_FUSION_ADT_ATTRIBUTE_TYPEOF( \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ + \ + struct deduced_attr_type { \ + const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ + typedef BOOST_TYPEOF( \ + BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 2, ATTRIBUTE)) type; \ + }; \ + \ + typedef remove_const::type type; \ + typedef add_const::type const_type; + +#define BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE( \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ + \ + typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) type; \ + typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE) const_type; + + #define BOOST_FUSION_ADAPT_ADT_C_BASE( \ - TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,ATTRIBUTE,ATTRIBUTE_TUPEL_SIZE) \ + TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,ATTRIBUTE,ATTRIBUTE_TUPEL_SIZE, DEDUCE_TYPE) \ \ template< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \ @@ -39,6 +60,12 @@ , I \ > \ { \ + \ + BOOST_PP_IF(DEDUCE_TYPE, \ + BOOST_FUSION_ADT_ATTRIBUTE_TYPEOF, \ + BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE \ + )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) /* XXX: Check PREFIX */\ + \ template \ BOOST_FUSION_GPU_ENABLED \ static void \ @@ -50,7 +77,7 @@ } \ \ BOOST_FUSION_GPU_ENABLED \ - static BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) \ + static type /* TODO: Check Type here */ \ boost_fusion_adapt_adt_impl_get( \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj) \ { \ @@ -58,7 +85,7 @@ } \ \ BOOST_FUSION_GPU_ENABLED \ - static BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE) \ + static const_type /* TODO: check Const Type here */ \ boost_fusion_adapt_adt_impl_get( \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) const& obj) \ { \ @@ -75,7 +102,10 @@ , true \ > \ { \ - typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE) type; \ + typedef access::adt_attribute_access< \ + BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ + , I \ + >::const_type type; /* TODO: check const Type here */ \ \ BOOST_FUSION_GPU_ENABLED \ explicit \ @@ -111,7 +141,10 @@ , false \ > \ { \ - typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) type; \ + typedef access::adt_attribute_access< \ + BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ + , I \ + >::type type; /* TODO: check Type here */ \ \ BOOST_FUSION_GPU_ENABLED \ explicit \ @@ -158,7 +191,13 @@ , I \ > \ { \ - typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) lvalue; \ + typedef \ + adt_attribute_proxy< \ + BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ + , I \ + , false \ + > lvalue; \ + \ BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ TEMPLATE_PARAMS_SEQ) \ \ From 52d280983b318cbddcc565d2dde120f0f31f10d1 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 10 Aug 2014 15:27:55 +0200 Subject: [PATCH 54/99] Fix some includes for consistency and use correct accessors macros. Since we have accessors macros for wrapped attributes we better use them, to improve readability of the macros. --- include/boost/fusion/adapted/struct/adapt_struct.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index 09c9015a..e9d14b74 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include #include @@ -42,10 +44,12 @@ IS_VIEW, \ I, \ BOOST_PP_IF(IS_VIEW, BOOST_FUSION_PROXY_PREFIX, BOOST_PP_EMPTY), \ - BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE), \ - BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE), \ + BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR(ATTRIBUTE), \ + BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE), \ BOOST_PP_IF( \ - BOOST_PP_LESS(BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE),2), 1, 0)) + BOOST_PP_LESS( \ + BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE),2) \ + , 1, 0)) From 7b089aa589fe47fac5b02b12e6a11f9b53f95594 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 10 Aug 2014 17:09:57 +0200 Subject: [PATCH 55/99] Add support for BOOST_FUSION_ADAPT_ADT to either deduce types or use specified ones. --- .../boost/fusion/adapted/adt/adapt_adt.hpp | 22 +++++++-------- .../fusion/adapted/adt/detail/adapt_base.hpp | 28 +++++++++++++++---- .../fusion/adapted/struct/adapt_struct.hpp | 2 +- .../adapted/struct/detail/adapt_auto.hpp | 15 ++++++++++ .../adapted/struct/detail/adapt_base.hpp | 2 +- test/sequence/adapt_adt.cpp | 4 +-- 6 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 include/boost/fusion/adapted/struct/detail/adapt_auto.hpp diff --git a/include/boost/fusion/adapted/adt/adapt_adt.hpp b/include/boost/fusion/adapted/adt/adapt_adt.hpp index fd91541a..37781765 100644 --- a/include/boost/fusion/adapted/adt/adapt_adt.hpp +++ b/include/boost/fusion/adapted/adt/adapt_adt.hpp @@ -2,6 +2,7 @@ Copyright (c) 2001-2009 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) @@ -13,7 +14,9 @@ #include #include #include -#include +#include +#include +#include #include #include #include @@ -33,13 +36,7 @@ #include #include #include - -#define BOOST_FUSION_ADAPT_ADT_FILLER_0(A, B, C, D)\ - ((A, B, C, D)) BOOST_FUSION_ADAPT_ADT_FILLER_1 -#define BOOST_FUSION_ADAPT_ADT_FILLER_1(A, B, C, D)\ - ((A, B, C, D)) BOOST_FUSION_ADAPT_ADT_FILLER_0 -#define BOOST_FUSION_ADAPT_ADT_FILLER_0_END -#define BOOST_FUSION_ADAPT_ADT_FILLER_1_END +#include #define BOOST_FUSION_ADAPT_ADT_C( \ TEMPLATE_PARAMS_SEQ, NAME_SEQ, IS_VIEW, I, ATTRIBUTE) \ @@ -47,9 +44,12 @@ TEMPLATE_PARAMS_SEQ, \ NAME_SEQ, \ I, \ - ATTRIBUTE, \ - 4, \ - BOOST_PP_BOOL(0)) + BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR(ATTRIBUTE), \ + BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR_SIZE(ATTRIBUTE), \ + BOOST_PP_IF( \ + BOOST_PP_LESS( \ + BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR_SIZE(ATTRIBUTE), 4) \ + , 1, 0)) #define BOOST_FUSION_ADAPT_TPL_ADT(TEMPLATE_PARAMS_SEQ, NAME_SEQ , ATTRIBUTES) \ BOOST_FUSION_ADAPT_STRUCT_BASE( \ diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index b155fc3c..9979c608 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -11,6 +11,8 @@ #define BOOST_FUSION_ADAPTED_ADT_DETAIL_ADAPT_BASE_HPP #include +#include + #include #include #include @@ -19,6 +21,8 @@ #include #include +#include + #define BOOST_FUSION_ADAPT_ADT_GET_IDENTITY_TEMPLATE_IMPL(TEMPLATE_PARAMS_SEQ) \ typename detail::get_identity< \ lvalue \ @@ -30,13 +34,24 @@ \ boost::remove_const::type>::type +#define BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR(ATTRIBUTE, \ + ATTRIBUTE_TUPEL_SIZE, DEDUCE_TYPE) \ + BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, \ + BOOST_PP_IF(DEDUCE_TYPE, 0, 2), ATTRIBUTE) + +#define BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_SETEXPR(ATTRIBUTE, \ + ATTRIBUTE_TUPEL_SIZE, DEDUCE_TYPE) \ + BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, \ + BOOST_PP_IF(DEDUCE_TYPE, 1, 3), ATTRIBUTE) + #define BOOST_FUSION_ADT_ATTRIBUTE_TYPEOF( \ NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ \ struct deduced_attr_type { \ const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ typedef BOOST_TYPEOF( \ - BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 2, ATTRIBUTE)) type; \ + BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR( \ + ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ }; \ \ typedef remove_const::type type; \ @@ -64,7 +79,7 @@ BOOST_PP_IF(DEDUCE_TYPE, \ BOOST_FUSION_ADT_ATTRIBUTE_TYPEOF, \ BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE \ - )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) /* XXX: Check PREFIX */\ + )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) /* XXX: Check PROXY PREFIX */\ \ template \ BOOST_FUSION_GPU_ENABLED \ @@ -73,7 +88,8 @@ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj, \ Val const& val) \ { \ - BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 3, ATTRIBUTE); \ + BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_SETEXPR(ATTRIBUTE, \ + ATTRIBUTE_TUPEL_SIZE, DEDUCE_TYPE); \ } \ \ BOOST_FUSION_GPU_ENABLED \ @@ -81,7 +97,8 @@ boost_fusion_adapt_adt_impl_get( \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj) \ { \ - return BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 2, ATTRIBUTE); \ + return BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR(ATTRIBUTE, \ + ATTRIBUTE_TUPEL_SIZE, DEDUCE_TYPE); \ } \ \ BOOST_FUSION_GPU_ENABLED \ @@ -89,7 +106,8 @@ boost_fusion_adapt_adt_impl_get( \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) const& obj) \ { \ - return BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 2, ATTRIBUTE); \ + return BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR(ATTRIBUTE, \ + ATTRIBUTE_TUPEL_SIZE, DEDUCE_TYPE); \ } \ }; \ \ diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index e9d14b74..e96e7c76 100644 --- a/include/boost/fusion/adapted/struct/adapt_struct.hpp +++ b/include/boost/fusion/adapted/struct/adapt_struct.hpp @@ -48,7 +48,7 @@ BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE), \ BOOST_PP_IF( \ BOOST_PP_LESS( \ - BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE),2) \ + BOOST_FUSION_ADAPT_STRUCT_WRAPPEDATTR_SIZE(ATTRIBUTE), 2) \ , 1, 0)) diff --git a/include/boost/fusion/adapted/struct/detail/adapt_auto.hpp b/include/boost/fusion/adapted/struct/detail/adapt_auto.hpp new file mode 100644 index 00000000..5178150b --- /dev/null +++ b/include/boost/fusion/adapted/struct/detail/adapt_auto.hpp @@ -0,0 +1,15 @@ +/*============================================================================= + 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_AUTO_HPP +#define BOOST_FUSION_ADAPTED_STRUCT_DETAIL_ADAPT_AUTO_HPP + +#include + +#define BOOST_FUSION_ADAPT_AUTO BOOST_PP_EMPTY() + +#endif diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index 1d054c46..dc6ec3ce 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -35,7 +36,6 @@ #include -#define BOOST_FUSION_ADAPT_AUTO BOOST_PP_EMPTY() #define BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME_TEMPLATE_PARAMS(SEQ) \ BOOST_PP_SEQ_HEAD(SEQ) \ diff --git a/test/sequence/adapt_adt.cpp b/test/sequence/adapt_adt.cpp index d4f4a8c2..5055ce04 100644 --- a/test/sequence/adapt_adt.cpp +++ b/test/sequence/adapt_adt.cpp @@ -93,8 +93,8 @@ namespace ns BOOST_FUSION_ADAPT_ADT( ns::point, - (int, int, obj.get_x(), obj.set_x(val)) - (int, int, obj.get_y(), obj.set_y(val)) + (obj.get_x(), obj.set_x(val)) + (obj.get_y(), obj.set_y(val)) ) #if !BOOST_WORKAROUND(__GNUC__,<4) From 727f49b49ed1aa6b5b544e40e09a18f55951eaf5 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 26 Aug 2014 22:00:16 +0200 Subject: [PATCH 56/99] Improve adapt_adt test to check more case with type deduction. --- test/sequence/adapt_adt.cpp | 124 ++++++++++++++++++++++++------------ 1 file changed, 83 insertions(+), 41 deletions(-) diff --git a/test/sequence/adapt_adt.cpp b/test/sequence/adapt_adt.cpp index 5055ce04..f2b15b1f 100644 --- a/test/sequence/adapt_adt.cpp +++ b/test/sequence/adapt_adt.cpp @@ -38,18 +38,21 @@ namespace ns { public: - point() : x(0), y(0) {} - point(int in_x, int in_y) : x(in_x), y(in_y) {} + point() : x(0), y(0), z(0) {} + point(int in_x, int in_y, int in_z) : x(in_x), y(in_y), z(in_z) {} int get_x() const { return x; } int get_y() const { return y; } + int get_z() const { return z; } void set_x(int x_) { x = x_; } void set_y(int y_) { y = y_; } + void set_z(int z_) { z = z_; } private: int x; int y; + int z; }; #if !BOOST_WORKAROUND(__GNUC__,<4) @@ -58,17 +61,22 @@ namespace ns friend struct boost::fusion::extension::access; public: - point_with_private_members() : x(0), y(0) {} - point_with_private_members(int x, int y) : x(x), y(y) {} - - private: + point_with_private_members() : x(0), y(0), z(0) {} + point_with_private_members(int in_x, int in_y, int in_z) + : x(in_x), y(in_y), z(in_z) {} + int get_x() const { return x; } int get_y() const { return y; } + int get_z() const { return z; } void set_x(int x_) { x = x_; } void set_y(int y_) { y = y_; } - + void set_z(int z_) { z = z_; } + + private: + int x; int y; + int z; }; #endif @@ -91,26 +99,56 @@ namespace ns }; } -BOOST_FUSION_ADAPT_ADT( - ns::point, - (obj.get_x(), obj.set_x(val)) - (obj.get_y(), obj.set_y(val)) -) +#if BOOST_PP_VARIADICS + BOOST_FUSION_ADAPT_ADT( + ns::point, + (int, int, obj.get_x(), obj.set_x(val)) + (obj.get_y(), obj.set_y(val)) + (obj.get_z(), obj.set_z(val)) + ) + +# if !BOOST_WORKAROUND(__GNUC__,<4) + BOOST_FUSION_ADAPT_ADT( + ns::point_with_private_members, + (obj.get_x(), obj.set_x(val)) + (obj.get_y(), obj.set_y(val)) + (obj.get_z(), obj.set_z(val)) + ) +# endif + + + BOOST_FUSION_ADAPT_ADT( + ns::name, + (obj.get_last(), obj.set_last(val)) + (obj.get_first(), obj.set_first(val)) + ) + + +#else // BOOST_PP_VARIADICS + BOOST_FUSION_ADAPT_ADT( + ns::point, + (int, int, obj.get_x(), obj.set_x(val)) + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_y(), obj.set_y(val)) + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_z(), obj.set_z(val)) + ) + +# if !BOOST_WORKAROUND(__GNUC__,<4) + BOOST_FUSION_ADAPT_ADT( + ns::point_with_private_members, + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_x(), obj.set_x(val)) + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_y(), obj.set_y(val)) + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_z(), obj.set_z(val)) + ) +# endif + + BOOST_FUSION_ADAPT_ADT( + ns::name, + (const std::string&, const std::string&, obj.get_last(), obj.set_last(val)) + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_first(), obj.set_first(val)) + ) -#if !BOOST_WORKAROUND(__GNUC__,<4) -BOOST_FUSION_ADAPT_ADT( - ns::point_with_private_members, - (int, int, obj.get_x(), obj.set_x(val)) - (int, int, obj.get_y(), obj.set_y(val)) -) #endif -BOOST_FUSION_ADAPT_ADT( - ns::name, - (const std::string&, const std::string&, obj.get_last(), obj.set_last(val)) - (const std::string&, const std::string&, obj.get_first(), obj.set_first(val)) -) - int main() { @@ -123,28 +161,30 @@ main() { BOOST_MPL_ASSERT_NOT((traits::is_view)); - ns::point p(123, 456); + ns::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); } { - fusion::vector v1(4, 2); - ns::point v2(5, 3); - fusion::vector v3(5, 4); + fusion::vector v1(4, 2, 2); + ns::point v2(5, 3, 3); + fusion::vector v3(5, 4, 4); BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); @@ -171,15 +211,15 @@ main() { // conversion from ns::point to vector - ns::point p(5, 3); - fusion::vector v(p); + ns::point p(5, 3, 3); + 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, 3); + fusion::list l(p); l = p; } @@ -193,22 +233,24 @@ main() #if !BOOST_WORKAROUND(__GNUC__,<4) { BOOST_MPL_ASSERT_NOT((traits::is_view)); - ns::point_with_private_members p(123, 456); + ns::point_with_private_members 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); } #endif From f0bc2a2ac17ef4f9511931fb53b303a0f1a2a12d Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 26 Aug 2014 23:32:26 +0200 Subject: [PATCH 57/99] Fix dependents scopes and typedefs with typename keywords. --- .../fusion/adapted/adt/detail/adapt_base.hpp | 13 ++-- test/sequence/adapt_tpl_adt.cpp | 66 ++++++++++++------- 2 files changed, 52 insertions(+), 27 deletions(-) diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index 9979c608..8512d04a 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -54,8 +54,13 @@ ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ }; \ \ - typedef remove_const::type type; \ - typedef add_const::type const_type; + typedef typename boost::remove_const< \ + typename deduced_attr_type::type \ + >::type type; \ + \ + typedef typename boost::add_const< \ + typename deduced_attr_type::type \ + >::type const_type; #define BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE( \ NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ @@ -120,7 +125,7 @@ , true \ > \ { \ - typedef access::adt_attribute_access< \ + typedef typename access::adt_attribute_access< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ >::const_type type; /* TODO: check const Type here */ \ @@ -159,7 +164,7 @@ , false \ > \ { \ - typedef access::adt_attribute_access< \ + typedef typename access::adt_attribute_access< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ >::type type; /* TODO: check Type here */ \ diff --git a/test/sequence/adapt_tpl_adt.cpp b/test/sequence/adapt_tpl_adt.cpp index aeb0f721..bbd1d07f 100644 --- a/test/sequence/adapt_tpl_adt.cpp +++ b/test/sequence/adapt_tpl_adt.cpp @@ -39,27 +39,45 @@ namespace ns { public: - point() : x(0), y(0) {} - point(X x_, Y y_) : x(x_), y(y_) {} + point() : x(0), y(0), z(0) {} + point(X x_, Y y_, int z_) : x(x_), y(y_), z(z_) {} X get_x() const { return x; } Y get_y() const { return y; } + int get_z() const { return z; } void set_x(X x_) { x = x_; } void set_y(Y y_) { y = y_; } + void set_z(int z_) { z = z_; } private: X x; Y y; + int z; }; } -BOOST_FUSION_ADAPT_TPL_ADT( - (X)(Y), - (ns::point)(X)(Y), - (X, X, obj.get_x(), obj.set_x(val)) - (Y, Y, obj.get_y(), obj.set_y(val)) -) + +#if BOOST_PP_VARIADICS + + BOOST_FUSION_ADAPT_TPL_ADT( + (X)(Y), + (ns::point)(X)(Y), + (X, X, obj.get_x(), obj.set_x(val)) + (Y, Y, obj.get_y(), obj.set_y(val)) + (obj.get_z(), obj.set_z(val)) + ) + +#else // BOOST_PP_VARIADICS + + BOOST_FUSION_ADAPT_TPL_ADT( + (X)(Y), + (ns::point)(X)(Y), + (X, X, obj.get_x(), obj.set_x(val)) + (Y, Y, obj.get_y(), obj.set_y(val)) + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_z(), obj.set_z(val)) + ) +#endif int main() @@ -75,28 +93,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); } { - boost::fusion::vector v1(4, 2); - point v2(5, 3); - boost::fusion::vector v3(5, 4); + boost::fusion::vector v1(4, 2, 2); + point v2(5, 3, 3); + boost::fusion::vector v3(5, 4, 4); BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); @@ -108,9 +128,9 @@ main() } { - boost::fusion::vector v1("Lincoln", "Abraham"); - name v2("Roosevelt", "Franklin"); - name v3("Roosevelt", "Theodore"); + boost::fusion::vector v1("Lincoln", "Abraham", 3); + name v2("Roosevelt", "Franklin", 3); + name v3("Roosevelt", "Theodore", 3); BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); @@ -123,15 +143,15 @@ main() { // conversion from point to vector - point p(5, 3); - boost::fusion::vector v(p); + point p(5, 3, 3); + boost::fusion::vector v(p); v = p; } { // conversion from point to list - point p(5, 3); - boost::fusion::list l(p); + point p(5, 3, 3); + boost::fusion::list l(p); l = p; } From 69e67cd1adddc1e36e2a3f6a2b7b261ed3571454 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 17 Sep 2014 00:47:52 +0200 Subject: [PATCH 58/99] BUGFIX: When VARIADICS are active supporting any of the input combination. That is : BOOST_FUSION_ADAPT_AUTO, omitting type or specifying type. --- .../adt/detail/adapt_base_attr_filler.hpp | 84 +++++++++++++++++++ test/sequence/adapt_adt.cpp | 4 +- 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 include/boost/fusion/adapted/adt/detail/adapt_base_attr_filler.hpp diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base_attr_filler.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base_attr_filler.hpp new file mode 100644 index 00000000..e88d7f1e --- /dev/null +++ b/include/boost/fusion/adapted/adt/detail/adapt_base_attr_filler.hpp @@ -0,0 +1,84 @@ +/*============================================================================= + 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_ADT_DETAIL_ADAPT_BASE_ATTR_FILLER_HPP +#define BOOST_FUSION_ADAPTED_ADT_DETAIL_ADAPT_BASE_ATTR_FILLER_HPP + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +#define BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR_SIZE(ATTRIBUTE) \ + BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE) + +#define BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR(ATTRIBUTE) \ + BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE) + +#if BOOST_PP_VARIADICS + +# define BOOST_FUSION_ADAPT_ADT_FILLER_0(...) \ + BOOST_FUSION_ADAPT_ADT_FILLER(__VA_ARGS__) \ + BOOST_FUSION_ADAPT_ADT_FILLER_1 + +# define BOOST_FUSION_ADAPT_ADT_FILLER_1(...) \ + BOOST_FUSION_ADAPT_ADT_FILLER(__VA_ARGS__) \ + BOOST_FUSION_ADAPT_ADT_FILLER_0 + +# define BOOST_FUSION_ADAPT_ADT_FILLER_0_END +# define BOOST_FUSION_ADAPT_ADT_FILLER_1_END + +# define BOOST_FUSION_ADAPT_ADT_FILLER(...) \ + BOOST_PP_IF( \ + BOOST_PP_OR( \ + BOOST_PP_IS_EMPTY(BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__)), \ + BOOST_PP_IS_EMPTY(BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__))), \ + BOOST_FUSION_ADAPT_ADT_WRAP_ATTR( \ + BOOST_PP_VARIADIC_ELEM(2, __VA_ARGS__), \ + BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_REST_N(3, \ + BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))) ), \ + BOOST_FUSION_ADAPT_ADT_WRAP_ATTR(__VA_ARGS__)) + +# define BOOST_FUSION_ADAPT_ADT_WRAP_ATTR(...) \ + ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) + +#else // BOOST_PP_VARIADICS + +# define BOOST_FUSION_ADAPT_ADT_FILLER_0(A, B, C, D) \ + BOOST_FUSION_ADAPT_ADT_WRAP_ATTR(A,B,C,D) \ + BOOST_FUSION_ADAPT_ADT_FILLER_1 + +# define BOOST_FUSION_ADAPT_ADT_FILLER_1(A, B, C, D) \ + BOOST_FUSION_ADAPT_ADT_WRAP_ATTR(A,B,C,D) \ + BOOST_FUSION_ADAPT_ADT_FILLER_0 + +# define BOOST_FUSION_ADAPT_ADT_FILLER_0_END +# define BOOST_FUSION_ADAPT_ADT_FILLER_1_END + +# define BOOST_FUSION_ADAPT_ADT_WRAP_ATTR(A, B, C, D) \ + BOOST_PP_IF(BOOST_PP_IS_EMPTY(A), \ + ((2, (C,D))), \ + ((4, (A,B,C,D))) \ + ) + +#endif // BOOST_PP_VARIADICS + +#endif diff --git a/test/sequence/adapt_adt.cpp b/test/sequence/adapt_adt.cpp index f2b15b1f..3a08000f 100644 --- a/test/sequence/adapt_adt.cpp +++ b/test/sequence/adapt_adt.cpp @@ -102,9 +102,9 @@ namespace ns #if BOOST_PP_VARIADICS BOOST_FUSION_ADAPT_ADT( ns::point, - (int, int, obj.get_x(), obj.set_x(val)) + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_x(), obj.set_x(val)) (obj.get_y(), obj.set_y(val)) - (obj.get_z(), obj.set_z(val)) + (int, int, obj.get_z(), obj.set_z(val)) ) # if !BOOST_WORKAROUND(__GNUC__,<4) From aa7b0a697229305f12d89ba3f17b4ce9f909519d Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 23 Sep 2014 23:07:00 +0200 Subject: [PATCH 59/99] Factoring out the workaround to access last variadic parameter. Indeed when some parameter are BOOST_PP_EMPTY the last parameter is accessed correctly but results in a compilation error which doesn't stop some compiler (e.g. g++) to go through the preprocessing pass and still compile the binary correctly. But to avoid the error message I used a workaround which behaves better. I preferred factoring it out to make clear that there are some reason why this element is strangely accessed. --- .../adapted/adt/detail/adapt_base_attr_filler.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base_attr_filler.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base_attr_filler.hpp index e88d7f1e..09bd4014 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base_attr_filler.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base_attr_filler.hpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -53,13 +54,18 @@ BOOST_PP_IS_EMPTY(BOOST_PP_VARIADIC_ELEM(1, __VA_ARGS__))), \ BOOST_FUSION_ADAPT_ADT_WRAP_ATTR( \ BOOST_PP_VARIADIC_ELEM(2, __VA_ARGS__), \ - BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_REST_N(3, \ - BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))) ), \ + BOOST_FUSION_WORKAROUND_VARIADIC_EMPTINESS_LAST_ELEM(__VA_ARGS__) \ + ), \ BOOST_FUSION_ADAPT_ADT_WRAP_ATTR(__VA_ARGS__)) # define BOOST_FUSION_ADAPT_ADT_WRAP_ATTR(...) \ ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) +# define BOOST_FUSION_WORKAROUND_VARIADIC_EMPTINESS_LAST_ELEM(...) \ + BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_REST_N( \ + BOOST_PP_SUB(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), 1), \ + BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))) + #else // BOOST_PP_VARIADICS # define BOOST_FUSION_ADAPT_ADT_FILLER_0(A, B, C, D) \ From c8ffc6498b12e0979ee3f216a91963f467555757 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 7 Oct 2014 21:39:18 +0200 Subject: [PATCH 60/99] add documentation for BOOST_FUSION_ADAPT_ADT and type deduction. --- doc/adapted.qbk | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/adapted.qbk b/doc/adapted.qbk index c11d733e..8d6893ba 100644 --- a/doc/adapted.qbk +++ b/doc/adapted.qbk @@ -664,8 +664,8 @@ __random_access_sequence__. BOOST_FUSION_ADAPT_ADT( type_name, - (attribute_type0, attribute_const_type0, get_expr0, set_expr0) - (attribute_type1, attribute_const_type1, get_expr1, set_expr1) + ([attribute_type0, attribute_const_type0,] get_expr0, set_expr0) + ([attribute_type1, attribute_const_type1,] get_expr1, set_expr1) ... ) @@ -674,7 +674,7 @@ __random_access_sequence__. The above macro generates the necessary code to adapt `type_name` as a model of __random_access_sequence__. The sequence of -[^(attribute_type['N], attribute_const_type['N], get_expr['N], set_expr['N])] +[^([attribute_type['N], attribute_const_type['N],] get_expr['N], set_expr['N])] quadruples declares the types, const types, get-expressions and set-expressions of the elements that are part of the adapted fusion sequence. [^get_expr['N]] is the expression that is invoked to get the ['N]th element @@ -682,7 +682,9 @@ of an instance of `type_name`. This expression may access a variable named `obj` of type `type_name&` or `type_name const&` which represents the underlying instance of `type_name`. [^attribute_type['N]] and [^attribute_const_type['N]] may specify the types -that [^get_expr['N]] denotes to. +that [^get_expr['N]] denotes to, when omitted the type is deduced from +[get_expr['N]] return type via BOOST_TYPEOF. On compiler missing support for +variadic macros BOOST_FUSION_ADAPT_AUTO can be used to avoid repeating the type. [^set_expr['N]] is the expression that is invoked to set the ['N]th element of an instance of `type_name`. This expression may access variables named `obj` of type `type_name&`, which represent the corresponding instance of From 103b02fda2d438350f0836af41e69bd49aed62fe Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 12 Oct 2014 12:50:56 +0200 Subject: [PATCH 61/99] add test for BOOST_FUSION_ADAPT_ADT_NAMED deducing types. --- test/sequence/adapt_adt_named.cpp | 48 ++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/test/sequence/adapt_adt_named.cpp b/test/sequence/adapt_adt_named.cpp index 38415633..cdb4806f 100644 --- a/test/sequence/adapt_adt_named.cpp +++ b/test/sequence/adapt_adt_named.cpp @@ -37,28 +37,46 @@ namespace ns { public: - point() : x(0), y(0) {} - point(int in_x, int in_y) : x(in_x), y(in_y) {} + point() : x(0), y(0), z(0) {} + point(int in_x, int in_y, int in_z) : x(in_x), y(in_y), z(in_z) {} int get_x() const { return x; } int get_y() const { return y; } + int get_z() const { return z; } void set_x(int x_) { x = x_; } void set_y(int y_) { y = y_; } + void set_z(int z_) { z = z_; } private: int x; int y; + int z; }; } +#if BOOST_PP_VARIADICS + // this creates a fusion view: boost::fusion::adapted::point BOOST_FUSION_ADAPT_ADT_NAMED( ns::point, point, (int, int, obj.obj.get_x(), obj.obj.set_x(val)) (int, int, obj.obj.get_y(), obj.obj.set_y(val)) + (obj.obj.get_z(), obj.obj.set_z(val)) ) +#else // BOOST_PP_VARIADICS + +// this creates a fusion view: boost::fusion::adapted::point +BOOST_FUSION_ADAPT_ADT_NAMED( + ns::point, point, + (int, int, obj.obj.get_x(), obj.obj.set_x(val)) + (int, int, obj.obj.get_y(), obj.obj.set_y(val)) + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.obj.get_z(), obj.obj.set_z(val)) +) + +#endif // BOOST_PP_VARIADICS + int main() { @@ -71,31 +89,33 @@ main() { BOOST_MPL_ASSERT((traits::is_view)); - ns::point basep(123, 456); + ns::point basep(123, 456, 789); adapted::point p(basep); 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); } { - fusion::vector v1(4, 2); - ns::point basep(5, 3); + fusion::vector v1(4, 2, 2); + ns::point basep(5, 3, 3); adapted::point v2(basep); - fusion::vector v3(5, 4); + fusion::vector v3(5, 4, 4); BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); @@ -108,19 +128,19 @@ main() { // conversion from ns::point to vector - ns::point basep(5, 3); + ns::point basep(5, 3, 3); adapted::point p(basep); - fusion::vector v(p); + fusion::vector v(p); v = p; } { // conversion from ns::point to list - ns::point basep(5, 3); + ns::point basep(5, 3, 3); adapted::point p(basep); - fusion::list l(p); + fusion::list l(p); l = p; } From 644d72ccfe8ec190c8c3f499bc85069568521142 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 12 Oct 2014 14:51:04 +0200 Subject: [PATCH 62/99] adds type deduction support for BOOST_FUSION_ADAPT_ASSOC_ADT. --- .../fusion/adapted/adt/adapt_assoc_adt.hpp | 22 ++++--- .../detail/adapt_base_assoc_attr_filler.hpp | 61 +++++++++++++++++++ test/sequence/adapt_assoc_adt.cpp | 56 ++++++++++++----- 3 files changed, 114 insertions(+), 25 deletions(-) create mode 100644 include/boost/fusion/adapted/adt/detail/adapt_base_assoc_attr_filler.hpp diff --git a/include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp b/include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp index ff33ac59..14eec414 100644 --- a/include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp +++ b/include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp @@ -2,6 +2,7 @@ Copyright (c) 2001-2009 Joel de Guzman Copyright (c) 2007 Dan Marsden 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) @@ -35,25 +36,28 @@ #include #include #include - -#define BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_0(A, B, C, D, E)\ - ((A, B, C, D, E)) BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_1 -#define BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_1(A, B, C, D, E)\ - ((A, B, C, D, E)) BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_0 -#define BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_0_END -#define BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_1_END +#include #define BOOST_FUSION_ADAPT_ASSOC_ADT_C( \ TEMPLATE_PARAMS_SEQ, NAME_SEQ, IS_VIEW, I, ATTRIBUTE) \ \ - BOOST_FUSION_ADAPT_ADT_C_BASE(TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,ATTRIBUTE,5) \ + BOOST_FUSION_ADAPT_ADT_C_BASE( \ + TEMPLATE_PARAMS_SEQ, \ + NAME_SEQ, \ + I, \ + BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR(ATTRIBUTE), \ + BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR_SIZE(ATTRIBUTE), \ + BOOST_PP_IF( \ + BOOST_PP_LESS( \ + BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR_SIZE(ATTRIBUTE), 5) \ + , 1, 0)) \ \ template< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \ > \ struct struct_assoc_key \ { \ - typedef BOOST_PP_TUPLE_ELEM(5, 4, ATTRIBUTE) type; \ + typedef BOOST_FUSION_ADAPT_ASSOC_ADT_WRAPPEDATTR_GET_KEY(ATTRIBUTE) type;\ }; #define BOOST_FUSION_ADAPT_ASSOC_TPL_ADT( \ diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base_assoc_attr_filler.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base_assoc_attr_filler.hpp new file mode 100644 index 00000000..b9c93b7d --- /dev/null +++ b/include/boost/fusion/adapted/adt/detail/adapt_base_assoc_attr_filler.hpp @@ -0,0 +1,61 @@ +/*============================================================================= + 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_ADAPTER_ADT_DETAIL_ADAPT_BASE_ASSOC_ATTR_FILLER_HPP +#define BOOST_FUSION_ADAPTER_ADT_DETAIL_ADAPT_BASE_ASSOC_ATTR_FILLER_HPP + +#include + +#include + +#include +#include +#include +#include + +#if BOOST_PP_VARIADICS + +#define BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_0(...) \ + BOOST_FUSION_ADAPT_ASSOC_ADT_WRAP_ATTR(__VA_ARGS__) \ + BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_1 + +#define BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_1(...) \ + BOOST_FUSION_ADAPT_ASSOC_ADT_WRAP_ATTR(__VA_ARGS__) \ + BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_0 + +#define BOOST_FUSION_ADAPT_ASSOC_ADT_WRAP_ATTR(...) \ + ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) + +#else // BOOST_PP_VARIADICS + +#define BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_0(A, B, C, D, E) \ + BOOST_FUSION_ADAPT_ASSOC_ADT_WRAP_ATTR(A, B, C, D, E) \ + BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_1 + +#define BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_1(A, B, C, D, E) \ + BOOST_FUSION_ADAPT_ASSOC_ADT_WRAP_ATTR(A, B, C, D, E) \ + BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_0 + +#define BOOST_FUSION_ADAPT_ASSOC_ADT_WRAP_ATTR(A, B, C, D, E) \ + BOOST_PP_IF(BOOST_PP_IS_EMPTY(A), \ + ((3, (C,D,E))), \ + ((5, (A,B,C,D,E))) \ + ) + +#endif // BOOST_PP_VARIADICS + +#define BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_0_END +#define BOOST_FUSION_ADAPT_ASSOC_ADT_FILLER_1_END + + +#define BOOST_FUSION_ADAPT_ASSOC_ADT_WRAPPEDATTR_GET_KEY(ATTRIBUTE) \ + BOOST_PP_TUPLE_ELEM( \ + BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR_SIZE(ATTRIBUTE), \ + BOOST_PP_SUB(BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR_SIZE(ATTRIBUTE), 1), \ + BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR(ATTRIBUTE)) + +#endif diff --git a/test/sequence/adapt_assoc_adt.cpp b/test/sequence/adapt_assoc_adt.cpp index c97e84b0..70d70ba4 100644 --- a/test/sequence/adapt_assoc_adt.cpp +++ b/test/sequence/adapt_assoc_adt.cpp @@ -26,31 +26,50 @@ namespace ns struct y_member; struct z_member; + struct unavailable_member; + class point { public: - point() : x(0), y(0) {} - point(int in_x, int in_y) : x(in_x), y(in_y) {} + point() : x(0), y(0), z(0) {} + point(int in_x, int in_y, int in_z) : x(in_x), y(in_y), z(in_z) {} int get_x() const { return x; } int get_y() const { return y; } + int get_z() const { return z; } void set_x(int x_) { x = x_; } void set_y(int y_) { y = y_; } + void set_z(int z_) { z = z_; } private: int x; int y; + int z; }; } +#if BOOST_PP_VARIADICS + BOOST_FUSION_ADAPT_ASSOC_ADT( ns::point, (int, int, obj.get_x(), obj.set_x(val), ns::x_member) (int, int, obj.get_y(), obj.set_y(val), ns::y_member) + (obj.get_z(), obj.set_z(val), ns::z_member) ) +#else // BOOST_PP_VARIADICS + +BOOST_FUSION_ADAPT_ASSOC_ADT( + ns::point, + (int, int, obj.get_x(), obj.set_x(val), ns::x_member) + (int, int, obj.get_y(), obj.set_y(val), ns::y_member) + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_z(), obj.set_z(val), ns::z_member) +) + +#endif + int main() { @@ -62,28 +81,30 @@ main() { BOOST_MPL_ASSERT_NOT((traits::is_view)); - ns::point p(123, 456); + ns::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); } { - boost::fusion::vector v1(4, 2); - ns::point v2(5, 3); - boost::fusion::vector v3(5, 4); + boost::fusion::vector v1(4, 2, 2); + ns::point v2(5, 3, 3); + boost::fusion::vector v3(5, 4, 4); BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); @@ -96,15 +117,15 @@ main() { // conversion from ns::point to vector - ns::point p(5, 3); - boost::fusion::vector v(p); + ns::point p(5, 3, 3); + boost::fusion::vector v(p); v = p; } { // conversion from ns::point to list - ns::point p(5, 3); - boost::fusion::list l(p); + ns::point p(5, 3, 3); + boost::fusion::list l(p); l = p; } @@ -119,15 +140,18 @@ main() // 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::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 p(5, 3); + ns::point p(5, 3, 1); BOOST_TEST(at_key(p) == 5); BOOST_TEST(at_key(p) == 3); + BOOST_TEST(at_key(p) == 1); } return boost::report_errors(); From cd0d3ce09ac75bb9545f959684d99996e72fb03e Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 12 Oct 2014 14:51:34 +0200 Subject: [PATCH 63/99] add comments for readability. --- .../adapted/struct/detail/adapt_base_assoc_attr_filler.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base_assoc_attr_filler.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base_assoc_attr_filler.hpp index 725af756..c75e83c3 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base_assoc_attr_filler.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base_assoc_attr_filler.hpp @@ -31,7 +31,8 @@ #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_WRAP_ATTR(...) \ ((BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))) -#else +#else // BOOST_PP_VARIADICS + #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0(X, Y, Z) \ BOOST_FUSION_ADAPT_ASSOC_STRUCT_WRAP_ATTR(X, Y, Z) \ @@ -47,7 +48,7 @@ ((3, (X,Y,Z))) \ ) -#endif +#endif // BOOST_PP_VARIADICS #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0_END #define BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_1_END From 2b5da49628a22856c6939e568bf866d8d3fd5ae7 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 12 Oct 2014 16:25:59 +0200 Subject: [PATCH 64/99] lvalue access::struct_member was wrongly set to be adt_attribute_proxy<> instead of adt_attribute_proxy<>::type. Shame on me. --- include/boost/fusion/adapted/adt/detail/adapt_base.hpp | 2 +- test/sequence/adapt_assoc_adt.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index 8512d04a..c304a4d1 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -219,7 +219,7 @@ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ , false \ - > lvalue; \ + >::type lvalue; \ \ BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ TEMPLATE_PARAMS_SEQ) \ diff --git a/test/sequence/adapt_assoc_adt.cpp b/test/sequence/adapt_assoc_adt.cpp index 70d70ba4..220c4d8c 100644 --- a/test/sequence/adapt_assoc_adt.cpp +++ b/test/sequence/adapt_assoc_adt.cpp @@ -146,6 +146,7 @@ main() BOOST_MPL_ASSERT((boost::is_same::type, int>)); BOOST_MPL_ASSERT((boost::is_same::type, int>)); + BOOST_MPL_ASSERT((boost::is_same::type, int>)); ns::point p(5, 3, 1); From 03ba146d8473c3178bccc05c7d1abebbd393a850 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Mon, 20 Oct 2014 12:54:31 +0200 Subject: [PATCH 65/99] lvalue typedef for acess::struct_member is a dependent scope to templated parameter when used within BOOST_FUSION_ADAPT_ASSOC_TPL_ADT. This fixes test sequence/adapt_assoc_tpl_adt.cpp. --- include/boost/fusion/adapted/adt/detail/adapt_base.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index c304a4d1..80a62b3e 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -214,12 +214,12 @@ , I \ > \ { \ - typedef \ + typedef typename \ adt_attribute_proxy< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ , false \ - >::type lvalue; \ + >::type lvalue; \ \ BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ TEMPLATE_PARAMS_SEQ) \ From cfcdbe119557f12044719a148680194cab3f27c8 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Mon, 20 Oct 2014 21:25:07 +0200 Subject: [PATCH 66/99] Change adapt_assoc_tpl_adt to test type inference from templated type. --- test/sequence/adapt_assoc_adt.cpp | 4 +-- test/sequence/adapt_assoc_tpl_adt.cpp | 51 ++++++++++++++++----------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/test/sequence/adapt_assoc_adt.cpp b/test/sequence/adapt_assoc_adt.cpp index 220c4d8c..a03605f1 100644 --- a/test/sequence/adapt_assoc_adt.cpp +++ b/test/sequence/adapt_assoc_adt.cpp @@ -26,7 +26,7 @@ namespace ns struct y_member; struct z_member; - struct unavailable_member; + struct non_member; class point { @@ -141,7 +141,7 @@ main() BOOST_MPL_ASSERT((boost::fusion::result_of::has_key)); 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::mpl::not_ >)); BOOST_MPL_ASSERT((boost::is_same::type, int>)); diff --git a/test/sequence/adapt_assoc_tpl_adt.cpp b/test/sequence/adapt_assoc_tpl_adt.cpp index 15e2124c..d8bd0864 100644 --- a/test/sequence/adapt_assoc_tpl_adt.cpp +++ b/test/sequence/adapt_assoc_tpl_adt.cpp @@ -26,31 +26,37 @@ namespace ns struct y_member; struct z_member; - template + struct non_member; + + template class point { public: - point() : x(0), y(0) {} - point(X in_x, Y in_y) : x(in_x), y(in_y) {} + point() : x(0), y(0), z(0) {} + point(X in_x, Y in_y, Z in_z) : x(in_x), y(in_y), z(in_z) {} X get_x() const { return x; } Y get_y() const { return y; } + Z get_z() const { return z; } void set_x(X x_) { x = x_; } void set_y(Y y_) { y = y_; } + void set_z(Z z_) { z = z_; } private: X x; Y y; + Z z; }; } BOOST_FUSION_ADAPT_ASSOC_TPL_ADT( - (X)(Y), - (ns::point)(X)(Y), + (X)(Y)(Z), + (ns::point)(X)(Y)(Z), (X, X, obj.get_x(), obj.set_x(val), ns::x_member) (Y, Y, obj.get_y(), obj.set_y(val), ns::y_member) + (obj.get_z(), obj.set_z(val), ns::z_member) ) int @@ -58,7 +64,7 @@ main() { using namespace boost::fusion; - typedef ns::point point; + typedef ns::point point; std::cout << tuple_open('['); std::cout << tuple_close(']'); @@ -66,28 +72,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); } { - boost::fusion::vector v1(4, 2); - point v2(5, 3); - boost::fusion::vector v3(5, 4); + boost::fusion::vector v1(4, 2, 2); + point v2(5, 3, 3); + boost::fusion::vector v3(5, 4, 4); BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); @@ -100,15 +108,15 @@ main() { // conversion from point to vector - point p(5, 3); - boost::fusion::vector v(p); + point p(5, 3, 3); + boost::fusion::vector v(p); v = p; } { // conversion from point to list - point p(5, 3); - boost::fusion::list l(p); + point p(5, 3, 3); + boost::fusion::list l(p); l = p; } @@ -123,15 +131,18 @@ main() // 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::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>)); + BOOST_MPL_ASSERT((boost::is_same::type, long>)); - point p(5, 3); + point p(5, 3, 1); BOOST_TEST(at_key(p) == 5); BOOST_TEST(at_key(p) == 3); + BOOST_TEST(at_key(p) == 1); } return boost::report_errors(); From 3a28c3fd81fb1b5f5f4988a9abb1ef369063f224 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Mon, 20 Oct 2014 21:35:01 +0200 Subject: [PATCH 67/99] Updates the doc of ADAPT_ADTs macros --- doc/adapted.qbk | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/doc/adapted.qbk b/doc/adapted.qbk index 8d6893ba..9fd6c24a 100644 --- a/doc/adapted.qbk +++ b/doc/adapted.qbk @@ -742,8 +742,8 @@ namespace qualified name of the class type to be adapted. BOOST_FUSION_ADAPT_ADT( demo::employee, - (std::string const&, std::string const&, obj.get_name(), obj.set_name(val)) - (int, int, obj.get_age(), obj.set_age(val))) + (obj.get_name(), obj.set_name(val)) + (obj.get_age(), obj.set_age(val))) demo::employee e; front(e)="Edward Norton"; @@ -768,8 +768,8 @@ __random_access_sequence__. BOOST_FUSION_ADAPT_TPL_ADT( (template_param0)(template_param1)..., (type_name) (specialization_param0)(specialization_param1)..., - (attribute_type0, attribute_const_type0, get_expr0, set_expr0) - (attribute_type1, attribute_const_type1, get_expr1, set_expr1) + ([attribute_type0, attribute_const_type0,] get_expr0, set_expr0) + ([attribute_type1, attribute_const_type1,] get_expr1, set_expr1) ... ) @@ -792,7 +792,9 @@ of an instance of `type_name`. This expression may access a variable named `obj` of type `type_name&` or `type_name const&` which represents the underlying instance of `type_name`. [^attribute_type['N]] and [^attribute_const_type['N]] may specify the types -that [^get_expr['N]] denotes to. +that [^get_expr['N]] denotes to, when omitted the type is deduced from +[get_expr['N]] return type via BOOST_TYPEOF. On compiler missing support for +variadic macros BOOST_FUSION_ADAPT_AUTO can be used to avoid repeating the type. [^set_expr['N]] is the expression that is invoked to set the ['N]th element of an instance of `type_name`. This expression may access variables named `obj` of type `type_name&`, which represent the corresponding instance of @@ -877,8 +879,8 @@ __random_access_sequence__ and __associative_sequence__. BOOST_FUSION_ADAPT_ASSOC_ADT( type_name, - (attribute_type0, attribute_const_type0, get_expr0, set_expr0, key_type0) - (attribute_type1, attribute_const_type1, get_expr1, set_expr1, key_type1) + ([attribute_type0, attribute_const_type0,] get_expr0, set_expr0, key_type0) + ([attribute_type1, attribute_const_type1,] get_expr1, set_expr1, key_type1) ... ) @@ -895,7 +897,9 @@ of an instance of `type_name`. This expression may access a variable named `obj` of type `type_name&` or `type_name const&` which represents the underlying instance of `type_name`. [^attribute_type['N]] and [^attribute_const_type['N]] may specify the types -that [^get_expr['N]] denotes to. +that [^get_expr['N]] denotes to, when omitted the type is deduced from +[get_expr['N]] return type via BOOST_TYPEOF. On compiler missing support for +variadic macros BOOST_FUSION_ADAPT_AUTO can be used to avoid repeating the type. [^set_expr['N]] is the expression that is invoked to set the ['N]th element of an instance of `type_name`. This expression may access variables named `obj` of type `type_name&`, which represent the corresponding instance of @@ -959,8 +963,8 @@ namespace qualified name of the class type to be adapted. BOOST_FUSION_ADAPT_ASSOC_ADT( demo::employee, - (std::string const&, std::string const&, obj.get_name(), obj.set_name(val), keys::name) - (int, int, obj.get_age(), obj.set_age(val), keys::age)) + (obj.get_name(), obj.set_name(val), keys::name) + (obj.get_age(), obj.set_age(val), keys::age)) demo::employee e; at_key(e)="Edward Norton"; @@ -985,8 +989,8 @@ __random_access_sequence__ and __associative_sequence__. BOOST_FUSION_ADAPT_ASSOC_TPL_ADT( (template_param0)(template_param1)..., (type_name) (specialization_param0)(specialization_param1)..., - (attribute_type0, attribute_const_type0, get_expr0, set_expr0, key_type0) - (attribute_type1, attribute_const_type1, get_expr1, set_expr1, key_type1) + ([attribute_type0, attribute_const_type0,] get_expr0, set_expr0, key_type0) + ([attribute_type1, attribute_const_type1,] get_expr1, set_expr1, key_type1) ... ) @@ -1001,7 +1005,7 @@ The sequence `(specialization_param0)(specialization_param1)...` declares the template parameters of the actual specialization of `type_name` that is adapted as a fusion sequence. The sequence of -[^(attribute_type['N], attribute_const_type['N], get_expr['N], set_expr['N], key_type['N])] +[^([attribute_type['N], attribute_const_type['N],] get_expr['N], set_expr['N], key_type['N])] 5-tuples declares the types, const types, get-expressions, set-expressions and key types of the elements that are part of the adapted fusion sequence. [^get_expr['N]] is the expression that is invoked to get the ['N]th element @@ -1009,7 +1013,9 @@ of an instance of `type_name`. This expression may access a variable named `obj` of type `type_name&` or `type_name const&` which represents the underlying instance of `type_name`. [^attribute_type['N]] and [^attribute_const_type['N]] may specify the types -that [^get_expr['N]] denotes to. +that [^get_expr['N]] denotes to, when omitted the type is deduced from +[get_expr['N]] return type via BOOST_TYPEOF. On compiler missing support for +variadic macros BOOST_FUSION_ADAPT_AUTO can be used to avoid repeating the type. [^set_expr['N]] is the expression that is invoked to set the ['N]th element of an instance of `type_name`. This expression may access variables named `obj` of type `type_name&`, which represent the corresponding instance of From 020b22f9b9fd16762cd568aaaf8313d9c9d741fe Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Mon, 20 Oct 2014 22:32:28 +0200 Subject: [PATCH 68/99] Fix test for compiler not supporting BOOST_PP_VARIADIC. --- test/sequence/adapt_assoc_tpl_adt.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/sequence/adapt_assoc_tpl_adt.cpp b/test/sequence/adapt_assoc_tpl_adt.cpp index d8bd0864..8aa600ff 100644 --- a/test/sequence/adapt_assoc_tpl_adt.cpp +++ b/test/sequence/adapt_assoc_tpl_adt.cpp @@ -51,6 +51,7 @@ namespace ns }; } +#if BOOST_PP_VARIADICS BOOST_FUSION_ADAPT_ASSOC_TPL_ADT( (X)(Y)(Z), (ns::point)(X)(Y)(Z), @@ -58,6 +59,17 @@ BOOST_FUSION_ADAPT_ASSOC_TPL_ADT( (Y, Y, obj.get_y(), obj.set_y(val), ns::y_member) (obj.get_z(), obj.set_z(val), ns::z_member) ) + +#else // BOOST_PP_VARIADICS +BOOST_FUSION_ADAPT_ASSOC_TPL_ADT( + (X)(Y)(Z), + (ns::point)(X)(Y)(Z), + (X, X, obj.get_x(), obj.set_x(val), ns::x_member) + (Y, Y, obj.get_y(), obj.set_y(val), ns::y_member) + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_z(), obj.set_z(val), ns::z_member) +) + +#endif int main() From e50f5852e4cb7816de90f5e1dd15966a9cb659c5 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 22 Oct 2014 22:06:31 +0200 Subject: [PATCH 69/99] Changes the test cases, as the behaviour about const-qualifier for attribute_type and attribute_const_type when type is deduced can be different than when the type is provided. Indeed when specifying attribute_type and attribute_const_type manually it's possible to provide a type which isn't const qualified as attribute_const_type. When deducing the types from the get_expr, a const and a non const qualified type is taken respectively for attribute_type and attribute_const_type. --- .../fusion/adapted/adt/detail/adapt_base.hpp | 10 +++---- test/sequence/adapt_adt.cpp | 29 +++++++++++++++++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index 80a62b3e..c1c78962 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -84,7 +84,7 @@ BOOST_PP_IF(DEDUCE_TYPE, \ BOOST_FUSION_ADT_ATTRIBUTE_TYPEOF, \ BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE \ - )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) /* XXX: Check PROXY PREFIX */\ + )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ \ template \ BOOST_FUSION_GPU_ENABLED \ @@ -98,7 +98,7 @@ } \ \ BOOST_FUSION_GPU_ENABLED \ - static type /* TODO: Check Type here */ \ + static type \ boost_fusion_adapt_adt_impl_get( \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj) \ { \ @@ -107,7 +107,7 @@ } \ \ BOOST_FUSION_GPU_ENABLED \ - static const_type /* TODO: check Const Type here */ \ + static const_type \ boost_fusion_adapt_adt_impl_get( \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) const& obj) \ { \ @@ -128,7 +128,7 @@ typedef typename access::adt_attribute_access< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ - >::const_type type; /* TODO: check const Type here */ \ + >::const_type type; \ \ BOOST_FUSION_GPU_ENABLED \ explicit \ @@ -167,7 +167,7 @@ typedef typename access::adt_attribute_access< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ - >::type type; /* TODO: check Type here */ \ + >::type type; \ \ BOOST_FUSION_GPU_ENABLED \ explicit \ diff --git a/test/sequence/adapt_adt.cpp b/test/sequence/adapt_adt.cpp index 3a08000f..265cfca5 100644 --- a/test/sequence/adapt_adt.cpp +++ b/test/sequence/adapt_adt.cpp @@ -102,9 +102,9 @@ namespace ns #if BOOST_PP_VARIADICS BOOST_FUSION_ADAPT_ADT( ns::point, - (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_x(), obj.set_x(val)) - (obj.get_y(), obj.set_y(val)) - (int, int, obj.get_z(), obj.set_z(val)) + (int, int, obj.get_x(), obj.set_x(val)) + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_y(), obj.set_y(val)) + (obj.get_z(), obj.set_z(val)) ) # if !BOOST_WORKAROUND(__GNUC__,<4) @@ -255,6 +255,7 @@ main() #endif { + // Check types provided in case it's provided BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::front::type, @@ -275,6 +276,28 @@ main() boost::fusion::result_of::front::type::type, int >)); + + // Check types provided in case it's deduced + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::back::type, + boost::fusion::extension::adt_attribute_proxy + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::back::type::type, + int + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::back::type, + boost::fusion::extension::adt_attribute_proxy + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::back::type::type, + const int + >)); } return boost::report_errors(); From 18fa262a4edcfbee1455070af33a1e773ec1c38d Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 18 Nov 2014 22:50:07 +0100 Subject: [PATCH 70/99] BUGFIX: Use of non-static member in typedef to retrieve the type. clang doesn't allow this even in unevaluated context like decltype. --- include/boost/fusion/adapted/adt/detail/adapt_base.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index c1c78962..2b47e70e 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -48,6 +48,7 @@ NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ \ struct deduced_attr_type { \ + static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ typedef BOOST_TYPEOF( \ BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR( \ From b5018586aad1475652702a41d4f317f4494bdda9 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 18 Nov 2014 23:38:47 +0100 Subject: [PATCH 71/99] Breaking change of BOOST_FUSION_ADAPT_ADT_NAMED and BOOST_FUSION_ADAPT_ASSOC_ADT_NAMED API to be coherent with the expressions of BOOST_FUSION_ADAPT_ADT thanks to correct usage of BOOST_FUSION_PROXY_PREFIX. --- .../boost/fusion/adapted/adt/adapt_adt.hpp | 2 ++ .../fusion/adapted/adt/adapt_assoc_adt.hpp | 2 ++ .../fusion/adapted/adt/detail/adapt_base.hpp | 19 ++++++++++--------- test/sequence/adapt_adt_named.cpp | 12 ++++++------ test/sequence/adapt_assoc_adt_named.cpp | 4 ++-- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/include/boost/fusion/adapted/adt/adapt_adt.hpp b/include/boost/fusion/adapted/adt/adapt_adt.hpp index 37781765..7ff6f4ee 100644 --- a/include/boost/fusion/adapted/adt/adapt_adt.hpp +++ b/include/boost/fusion/adapted/adt/adapt_adt.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,7 @@ TEMPLATE_PARAMS_SEQ, \ NAME_SEQ, \ I, \ + BOOST_PP_IF(IS_VIEW, BOOST_FUSION_PROXY_PREFIX, BOOST_PP_EMPTY), \ BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR(ATTRIBUTE), \ BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR_SIZE(ATTRIBUTE), \ BOOST_PP_IF( \ diff --git a/include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp b/include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp index 14eec414..49a8805d 100644 --- a/include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp +++ b/include/boost/fusion/adapted/adt/adapt_assoc_adt.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,7 @@ TEMPLATE_PARAMS_SEQ, \ NAME_SEQ, \ I, \ + BOOST_PP_IF(IS_VIEW, BOOST_FUSION_PROXY_PREFIX, BOOST_PP_EMPTY), \ BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR(ATTRIBUTE), \ BOOST_FUSION_ADAPT_ADT_WRAPPEDATTR_SIZE(ATTRIBUTE), \ BOOST_PP_IF( \ diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index 2b47e70e..9768ae3a 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -45,14 +45,14 @@ BOOST_PP_IF(DEDUCE_TYPE, 1, 3), ATTRIBUTE) #define BOOST_FUSION_ADT_ATTRIBUTE_TYPEOF( \ - NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ \ struct deduced_attr_type { \ static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ typedef BOOST_TYPEOF( \ - BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR( \ - ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ + PREFIX() BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR( \ + ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ }; \ \ typedef typename boost::remove_const< \ @@ -64,14 +64,15 @@ >::type const_type; #define BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE( \ - NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ \ typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) type; \ typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE) const_type; #define BOOST_FUSION_ADAPT_ADT_C_BASE( \ - TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,ATTRIBUTE,ATTRIBUTE_TUPEL_SIZE, DEDUCE_TYPE) \ + TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,PREFIX, \ + ATTRIBUTE,ATTRIBUTE_TUPEL_SIZE, DEDUCE_TYPE) \ \ template< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \ @@ -85,7 +86,7 @@ BOOST_PP_IF(DEDUCE_TYPE, \ BOOST_FUSION_ADT_ATTRIBUTE_TYPEOF, \ BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE \ - )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ + )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ \ template \ BOOST_FUSION_GPU_ENABLED \ @@ -94,7 +95,7 @@ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj, \ Val const& val) \ { \ - BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_SETEXPR(ATTRIBUTE, \ + PREFIX() BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_SETEXPR(ATTRIBUTE, \ ATTRIBUTE_TUPEL_SIZE, DEDUCE_TYPE); \ } \ \ @@ -103,7 +104,7 @@ boost_fusion_adapt_adt_impl_get( \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj) \ { \ - return BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR(ATTRIBUTE, \ + return PREFIX() BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR(ATTRIBUTE, \ ATTRIBUTE_TUPEL_SIZE, DEDUCE_TYPE); \ } \ \ @@ -112,7 +113,7 @@ boost_fusion_adapt_adt_impl_get( \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) const& obj) \ { \ - return BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR(ATTRIBUTE, \ + return PREFIX() BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR(ATTRIBUTE, \ ATTRIBUTE_TUPEL_SIZE, DEDUCE_TYPE); \ } \ }; \ diff --git a/test/sequence/adapt_adt_named.cpp b/test/sequence/adapt_adt_named.cpp index cdb4806f..8924ce41 100644 --- a/test/sequence/adapt_adt_named.cpp +++ b/test/sequence/adapt_adt_named.cpp @@ -60,9 +60,9 @@ namespace ns // this creates a fusion view: boost::fusion::adapted::point BOOST_FUSION_ADAPT_ADT_NAMED( ns::point, point, - (int, int, obj.obj.get_x(), obj.obj.set_x(val)) - (int, int, obj.obj.get_y(), obj.obj.set_y(val)) - (obj.obj.get_z(), obj.obj.set_z(val)) + (int, int, obj.get_x(), obj.set_x(val)) + (int, int, obj.get_y(), obj.set_y(val)) + (obj.get_z(), obj.set_z(val)) ) #else // BOOST_PP_VARIADICS @@ -70,9 +70,9 @@ BOOST_FUSION_ADAPT_ADT_NAMED( // this creates a fusion view: boost::fusion::adapted::point BOOST_FUSION_ADAPT_ADT_NAMED( ns::point, point, - (int, int, obj.obj.get_x(), obj.obj.set_x(val)) - (int, int, obj.obj.get_y(), obj.obj.set_y(val)) - (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.obj.get_z(), obj.obj.set_z(val)) + (int, int, obj.get_x(), obj.set_x(val)) + (int, int, obj.get_y(), obj.set_y(val)) + (BOOST_FUSION_ADAPT_AUTO, BOOST_FUSION_ADAPT_AUTO, obj.get_z(), obj.set_z(val)) ) #endif // BOOST_PP_VARIADICS diff --git a/test/sequence/adapt_assoc_adt_named.cpp b/test/sequence/adapt_assoc_adt_named.cpp index d68d9904..8ef9aa27 100644 --- a/test/sequence/adapt_assoc_adt_named.cpp +++ b/test/sequence/adapt_assoc_adt_named.cpp @@ -48,8 +48,8 @@ namespace ns BOOST_FUSION_ADAPT_ASSOC_ADT_NAMED( ns::point, point, - (int, int, obj.obj.get_x(), obj.obj.set_x(val), ns::x_member) - (int, int, obj.obj.get_y(), obj.obj.set_y(val), ns::y_member) + (int, int, obj.get_x(), obj.set_x(val), ns::x_member) + (int, int, obj.get_y(), obj.set_y(val), ns::y_member) ) int From bc07cac46c9b136450c906d5469c3ac6df1cfb58 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Tue, 18 Nov 2014 23:39:53 +0100 Subject: [PATCH 72/99] Fix use of non-static "obj" in unevaluated expression context of decltype. --- .../fusion/adapted/adt/detail/adapt_base.hpp | 1 - .../adapted/struct/detail/adapt_base.hpp | 25 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index 9768ae3a..b9126c94 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -49,7 +49,6 @@ \ struct deduced_attr_type { \ static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ - const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ typedef BOOST_TYPEOF( \ PREFIX() BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR( \ ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index dc6ec3ce..3d755f72 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -64,13 +64,21 @@ #define BOOST_FUSION_ATTRIBUTE_TYPEOF( \ NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ - BOOST_TYPEOF( \ - BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)::PREFIX() \ - BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE)) + \ + struct deduced_attr_type { \ + static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ + typedef BOOST_TYPEOF( \ + PREFIX() obj.BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE)) \ + type; \ + }; \ + \ + typedef typename deduced_attr_type::type attribute_type; #define BOOST_FUSION_ATTRIBUTE_GIVENTYPE( \ NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, unused) \ - BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) + typedef \ + BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) attribute_type; + #ifdef BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS # define BOOST_FUSION_ADAPT_STRUCT_TAG_OF_SPECIALIZATION( \ @@ -137,11 +145,10 @@ , I \ > \ { \ - typedef \ - BOOST_PP_IF(DEDUCE_TYPE, \ - BOOST_FUSION_ATTRIBUTE_TYPEOF, BOOST_FUSION_ATTRIBUTE_GIVENTYPE \ - )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ - attribute_type; \ + BOOST_PP_IF(DEDUCE_TYPE, \ + BOOST_FUSION_ATTRIBUTE_TYPEOF, BOOST_FUSION_ATTRIBUTE_GIVENTYPE \ + )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ + \ BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ TEMPLATE_PARAMS_SEQ) \ \ From 51d638f51cbbfab282771bbdb31d2d4c691b9751 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Mon, 5 Jan 2015 08:19:31 +0900 Subject: [PATCH 73/99] Fix documentation of transform correctly. --- doc/algorithm.qbk | 49 ++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/doc/algorithm.qbk b/doc/algorithm.qbk index d902ebe4..1a5bf453 100644 --- a/doc/algorithm.qbk +++ b/doc/algorithm.qbk @@ -2089,32 +2089,33 @@ Constant. [section transform] [heading Description] -For a sequence `seq` and function object or function pointer `f`, `transform` returns a new sequence -with elements created by applying `f(e)` to each element of `e` of `seq`. +Returns the result type of __transform__, given the types of the input sequence and unary __poly_func_obj__. [heading Unary version synopsis] template< typename Sequence, typename F > - typename __result_of_transform__::type transform( - Sequence const& seq, F f); + struct transform + { + typedef __unspecified__ type; + }; [table Parameters [[Parameter][Requirement][Description]] - [[`seq`][A model of __forward_sequence__][Operation's argument]] - [[`f`][`f(e)` is a valid expression for each element `e` of `seq`. `__boost_result_of_call__::type` is the return type of `f` when called with a value of each element type `E`.][Transformation function]] + [[`Sequence`][A model of __forward_sequence__][Operation's argument]] + [[`F`][A model of unary __poly_func_obj__][Transformation metafunction]] ] [heading Expression Semantics] - __transform__(seq, f); + __result_of_transform__::type [*Return type]: * A model of __forward_sequence__ * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model. -[*Semantics]: Returns a new sequence, containing the return values of `f(e)` for each element `e` within `seq`. +[*Semantics]: Returns a sequence that contains the types of `__result_of__::type` for each element `E` within `Sequence`. [heading Binary version synopsis] template< @@ -2122,41 +2123,33 @@ with elements created by applying `f(e)` to each element of `e` of `seq`. typename Sequence2, typename F > - typename __result_of_transform__::type transform( - Sequence1 const& seq1, Sequence2 const& seq2, F f); + struct transform + { + typedef __unspecified__ type; + }; [table Parameters [[Parameter][Requirement][Description]] - [[`seq1`][A model of __forward_sequence__][Operation's argument]] - [[`seq2`][A model of __forward_sequence__][Operation's argument]] - [[`f`][`f(e1,e2)` is a valid expression for each pair of elements `e1` of `seq1` and `e2` of `seq2`. `__boost_result_of_call__::type` is the return type of `f` when called with elements of type `E1` and `E2`][Transformation function]] + [[`Sequence1`][A model of __forward_sequence__][Operation's argument]] + [[`Sequence2`][A model of __forward_sequence__][Operation's argument]] + [[`F`][A model of binary __poly_func_obj__][Transformation metafunction]] ] +[heading Expression Semantics] + __result_of_transform__::type + [*Return type]: A model of __forward_sequence__. -[*Semantics]: Returns a new sequence, containing the return values of `f(e1, e2)` for each pair of elements `e1` and `e2` within `seq1` and `seq2` respectively. +[*Semantics]: Returns a sequence, that contains the types of `__result_of__::type` for each pair of elements `E1` and `E2` within `Sequence1` and `Sequence2` respectively. [heading Complexity] -Constant. Returns a view which is lazily evaluated. +Constant. [heading Header] #include #include -[heading Example] - struct triple - { - typedef int result_type; - - int operator()(int t) const - { - return t * 3; - }; - }; - ... - assert(__transform__(__make_vector__(1,2,3), triple()) == __make_vector__(3,6,9)); - [endsect] [section replace] From a2269f447ed93646cf00735d25a23e4ac2e2539c Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Mon, 5 Jan 2015 08:23:21 +0900 Subject: [PATCH 74/99] Fix requirements documentation of replace_if. --- doc/algorithm.qbk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/algorithm.qbk b/doc/algorithm.qbk index 1a5bf453..915aecba 100644 --- a/doc/algorithm.qbk +++ b/doc/algorithm.qbk @@ -2193,7 +2193,7 @@ Constant. [section replace_if] [heading Description] -Returns the result type of __replace_if__, given the types of the sequence, __poly_func_obj__ predicate and replacement object. +Returns the result type of __replace_if__, given the types of the sequence, unary __mpl_lambda_expression__ predicate and replacement object. [heading Synopsis] template< @@ -2208,7 +2208,7 @@ Returns the result type of __replace_if__, given the types of the sequence, __po [table Parameters [[Parameter][Requirement][Description]] [[`Sequence`][A model of __forward_sequence__][Operation's argument]] - [[`F`][A model of unary __poly_func_obj__][Replacement predicate]] + [[`F`][A model of unary __mpl_lambda_expression__][Replacement predicate]] [[`T`][Any type][The type of the replacement object]] ] From 85ce2a3eb2ce2c3bfebf56584077dd4cd6c22fa5 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Mon, 5 Jan 2015 08:24:14 +0900 Subject: [PATCH 75/99] Fix link of result_of::remove_if. --- doc/algorithm.qbk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/algorithm.qbk b/doc/algorithm.qbk index 915aecba..bdcb66bb 100644 --- a/doc/algorithm.qbk +++ b/doc/algorithm.qbk @@ -2258,7 +2258,7 @@ Returns the result type of __remove__, given the sequence and removal types. * A model of __forward_sequence__. * A model of __associative_sequence__ if `Sequence` implements the __associative_sequence__ model. -[*Semantics]: Returns a sequence containing the elements of `Sequence` not of type `T`. Equivalent to `__result_of_replace_if__ >::type`. +[*Semantics]: Returns a sequence containing the elements of `Sequence` not of type `T`. Equivalent to `__result_of_remove_if__ >::type`. [heading Complexity] Constant. From 205c0f1eb4c75a73d67a30465525ec9cd5a54dd1 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Mon, 12 Jan 2015 23:34:13 +0900 Subject: [PATCH 76/99] update overview of directory structure. --- doc/organization.qbk | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/organization.qbk b/doc/organization.qbk index e3dd7fb4..b7166f5d 100644 --- a/doc/organization.qbk +++ b/doc/organization.qbk @@ -36,20 +36,26 @@ link against. * tuple * algorithm + * auxiliary * iteration * query * transformation * adapted + * adt * array - * mpl + * boost::array * boost::tuple + * mpl * std_pair + * std_tuple * struct - * variant * view * filter_view + * flatten_view * iterator_range * joint_view + * nview + * repetitive_view * reverse_view * single_view * transform_view @@ -63,6 +69,9 @@ link against. * generation * mpl * functional + * adapter + * generation + * invocation * sequence * comparison * intrinsic From e572c382f73ac4c40ede2c5fab8eac1e902d6cdd Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Thu, 15 Jan 2015 14:57:48 +0900 Subject: [PATCH 77/99] Fixing a broken table notation. --- doc/iterator.qbk | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/iterator.qbk b/doc/iterator.qbk index 50430a4d..0aa7b607 100644 --- a/doc/iterator.qbk +++ b/doc/iterator.qbk @@ -67,8 +67,7 @@ the following expressions are valid: ] [heading Expression Semantics] -[ -table +[table [[Expression] [Semantics]] [[`__next__(i)`] [An iterator to the element following `i`]] [[`i == j`] [Iterator equality comparison]] From fbd6a8a50fb6fdbfc67fff1ee278ef9bca0bc76c Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Thu, 15 Jan 2015 16:13:12 +0900 Subject: [PATCH 78/99] Fixing template parameter order and a function parameter type. --- doc/iterator.qbk | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/iterator.qbk b/doc/iterator.qbk index 0aa7b607..d400003c 100644 --- a/doc/iterator.qbk +++ b/doc/iterator.qbk @@ -417,15 +417,15 @@ Moves an iterator by a specified distance. [heading Synopsis] template< - typename I, - typename M + typename M, + typename I > typename __result_of_advance__::type advance(I const& i); [table Parameters [[Parameter] [Requirement] [Description]] [[`i`] [Model of __forward_iterator__] [Iterator to move relative to]] - [[`N`] [An __mpl_integral_constant__] [Number of positions to move]] + [[`M`] [An __mpl_integral_constant__] [Number of positions to move]] ] [heading Expression Semantics] @@ -454,8 +454,8 @@ Moves an iterator by a specified distance. [heading Synopsis] template< - typename I, - int N + int N, + typename I > typename __result_of_advance_c__::type advance_c(I const& i); @@ -536,7 +536,7 @@ Dereferences an iterator. template< typename I > - typename __result_of_deref__::type operator*(__unspecified__ const& i); + typename __result_of_deref__::type operator*(I const& i); [table Parameters [[Parameter] [Requirement] [Description]] From 0360dc44b24d77c2e806d40dee2fa58bfa8ed423 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Thu, 15 Jan 2015 17:48:17 +0900 Subject: [PATCH 79/99] Fix documentation typo of sequence concepts. --- doc/sequence.qbk | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/sequence.qbk b/doc/sequence.qbk index 2d323e37..cf05a53d 100644 --- a/doc/sequence.qbk +++ b/doc/sequence.qbk @@ -249,15 +249,18 @@ any Random Access Sequence the following must be met: [[Expression] [Compile Time Complexity]] [[`__result_of_begin__::type`] [Amortized constant time]] [[`__result_of_end__::type`] [Amortized constant time]] - [[`__result_of_at__::type`] [Amortized constant time]] - [[`__result_of_value_at__::type`] [Amortized constant time]] + [[`__result_of_at__::type`] [Amortized constant time]] + [[`__result_of_at_c__::type`] [Amortized constant time]] + [[`__result_of_value_at__::type`] [Amortized constant time]] + [[`__result_of_value_at_c__::type`] [Amortized constant time]] ] -[blurb __note__ `__result_of_at__` returns the actual type returned by -`__at__(s)`. In most cases, this is a reference. Hence, there is no way to -know the exact element type using `__result_of_at__`.The element at `N` +[blurb __note__ `__result_of_at__` returns the actual type returned by +`__at__(s)`. In most cases, this is a reference. Hence, there is no way to +know the exact element type using `__result_of_at__`.The element at `M` may actually be a reference to begin with. For this purpose, you can use -`__result_of_value_at__`.] +`__result_of_value_at__` (Note that, `__result_of_value_at_c__` +is a counterpart of `__result_of_at_c__` as well).] [heading Expression Semantics] @@ -331,7 +334,7 @@ For any Associative Sequence the following expressions must be valid: by `__at_key__(s)`. In most cases, this is a reference. Hence, there is no way to know the exact element type using `__result_of_at_key__`.The element at `K` may actually be a reference to begin with. For this purpose, -you can use `__result_of_value_at_key__`.] +you can use `__result_of_value_at_key__`.] [heading Expression Semantics] From 28598a791925156f29e54ab2fc327220ccd6871d Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Thu, 15 Jan 2015 18:24:44 +0900 Subject: [PATCH 80/99] doc: Plural form and links. --- doc/sequence.qbk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/sequence.qbk b/doc/sequence.qbk index cf05a53d..4722124a 100644 --- a/doc/sequence.qbk +++ b/doc/sequence.qbk @@ -1326,7 +1326,7 @@ Returns the result type of __has_key__. [heading Description] Returns the result type of __at_key__[footnote __result_of_at_key__ -reflects the actual return type of the function __at_key__. __sequence__s +reflects the actual return type of the function __at_key__. __sequence__(s) typically return references to its elements via the __at_key__ function. If you want to get the actual element type, use __result_of_value_at_key__]. @@ -1448,7 +1448,7 @@ operators for free. The I/O operators: `<<` and `>>` work generically on all Fusion sequences. The I/O operators are overloaded in namespace `boost::fusion` -[footnote __sequences__ and __views__ residing in different namespaces +[footnote __sequence__(s) and __views__ residing in different namespaces will have to either provide their own I/O operators (possibly forwarding to fusion's I/O operators) or hoist fusion's I/O operators (using declaration), in their own namespaces for proper argument dependent @@ -1640,7 +1640,7 @@ compile time error. [*Semantics]: For each element, `e1`, in sequence `a`, and for each element, `e2`, in -sequence `b`, `e1 == e2` returns true. For any 2 zero length __sequence__s, +sequence `b`, `e1 == e2` returns true. For any 2 zero length __sequence__(s), e and f, e == f returns true. [heading Header] From ce8bf1079ab53ef2913fa4d5a729cc92574a03a0 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Thu, 15 Jan 2015 18:58:33 +0900 Subject: [PATCH 81/99] Support removing the C++11 standard reference wrappers. --- doc/notes.qbk | 4 +++- doc/support.qbk | 3 ++- include/boost/fusion/support/deduce.hpp | 19 +++++++++++++++++++ .../support/detail/as_fusion_element.hpp | 12 ++++++++++++ test/sequence/deduce_sequence.cpp | 11 +++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/doc/notes.qbk b/doc/notes.qbk index 26a938fb..0377023c 100644 --- a/doc/notes.qbk +++ b/doc/notes.qbk @@ -121,7 +121,7 @@ creates a __list__ of type __list__ -[heading boost::ref] +[heading Reference Wrappers] Fusion's generation functions (e.g. __make_list__) by default stores the element types as plain non-reference types. Example: @@ -151,6 +151,8 @@ For example: See __boost_ref__ for details. +Since C++11, the standard reference wrappers (`std::ref` and `std::cref`) work as well. + [heading adt_attribute_proxy] To adapt arbitrary data types that do not allow direct access to their members, diff --git a/doc/support.qbk b/doc/support.qbk index 8c2ef1de..1a473819 100644 --- a/doc/support.qbk +++ b/doc/support.qbk @@ -254,7 +254,8 @@ Metafunction to apply __element_conversion__ to the full argument type. It removes references to `const`, references to array types are kept, even if the array is `const`. Reference wrappers are removed (see -__note_boost_ref__). +__note_boost_ref__)[footnote Since C++11, the standard reference wrappers +are also removed.]. [heading Header] diff --git a/include/boost/fusion/support/deduce.hpp b/include/boost/fusion/support/deduce.hpp index 8d53115f..b75381c5 100644 --- a/include/boost/fusion/support/deduce.hpp +++ b/include/boost/fusion/support/deduce.hpp @@ -12,6 +12,10 @@ #include #include +#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL +#include +#endif + namespace boost { namespace fusion { namespace traits { template struct deduce; @@ -86,6 +90,21 @@ namespace boost { namespace fusion { namespace traits typedef T& type; }; + // Also unwrap C++11 std::ref if available (referencee cv is deduced) +#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL + template + struct deduce &> + { + typedef T& type; + }; + + template + struct deduce const &> + { + typedef T& type; + }; +#endif + // Keep references on arrays, even if const template diff --git a/include/boost/fusion/support/detail/as_fusion_element.hpp b/include/boost/fusion/support/detail/as_fusion_element.hpp index 628dca4d..2af960ee 100644 --- a/include/boost/fusion/support/detail/as_fusion_element.hpp +++ b/include/boost/fusion/support/detail/as_fusion_element.hpp @@ -11,6 +11,10 @@ #include #include +#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL +#include +#endif + namespace boost { namespace fusion { namespace detail { template @@ -25,6 +29,14 @@ namespace boost { namespace fusion { namespace detail typedef T& type; }; +#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL + template + struct as_fusion_element > + { + typedef T& type; + }; +#endif + template struct as_fusion_element { diff --git a/test/sequence/deduce_sequence.cpp b/test/sequence/deduce_sequence.cpp index ea661662..a1569f46 100644 --- a/test/sequence/deduce_sequence.cpp +++ b/test/sequence/deduce_sequence.cpp @@ -6,6 +6,7 @@ http://www.boost.org/LICENSE_1_0.txt). ==============================================================================*/ +#include #include #include #include @@ -13,6 +14,9 @@ #include #include +#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL +#include +#endif using boost::is_same; using boost::reference_wrapper; @@ -66,6 +70,13 @@ int main() TEST_SAME_TYPE(deduce< reference_wrapper const & >::type, int &); TEST_SAME_TYPE(deduce< reference_wrapper const & >::type, int const &); +#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL + TEST_SAME_TYPE(deduce< std::reference_wrapper & >::type, int &); + TEST_SAME_TYPE(deduce< std::reference_wrapper & >::type, int const &); + TEST_SAME_TYPE(deduce< std::reference_wrapper const & >::type, int &); + TEST_SAME_TYPE(deduce< std::reference_wrapper const & >::type, int const &); +#endif + TEST_SAME_TYPE(deduce< int(&)[2] >::type, int(&)[2]); TEST_SAME_TYPE(deduce< int const (&)[2] >::type, int const (&)[2]); TEST_SAME_TYPE(deduce< int volatile (&)[2] >::type, int volatile (&)[2]); From 326104a9b754ddfee00ff36f7daad71d24762f51 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Sun, 18 Jan 2015 02:23:40 +0900 Subject: [PATCH 82/99] Fix unexpected overload resolution on MSVC. --- include/boost/fusion/container/deque/detail/cpp03/deque.hpp | 5 ++++- .../boost/fusion/container/deque/detail/keyed_element.hpp | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/boost/fusion/container/deque/detail/cpp03/deque.hpp b/include/boost/fusion/container/deque/detail/cpp03/deque.hpp index 1b92ceaf..7f630bbb 100644 --- a/include/boost/fusion/container/deque/detail/cpp03/deque.hpp +++ b/include/boost/fusion/container/deque/detail/cpp03/deque.hpp @@ -141,7 +141,10 @@ FUSION_HASH if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) {} template BOOST_FUSION_GPU_ENABLED - deque(deque&& seq) + deque(deque&& seq + , typename disable_if< + is_convertible, T0> + >::type* /*dummy*/ = 0) : base(std::forward>(seq)) {} template diff --git a/include/boost/fusion/container/deque/detail/keyed_element.hpp b/include/boost/fusion/container/deque/detail/keyed_element.hpp index 37aba9fd..0137444a 100644 --- a/include/boost/fusion/container/deque/detail/keyed_element.hpp +++ b/include/boost/fusion/container/deque/detail/keyed_element.hpp @@ -66,7 +66,8 @@ namespace boost { namespace fusion { namespace detail template BOOST_FUSION_GPU_ENABLED - keyed_element(keyed_element const& rhs) + keyed_element(keyed_element const& rhs + , typename enable_if >::type* = 0) : Rest(rhs.get_base()), value_(rhs.value_) {} From 5e4978b8707e977db9f797c238f8eee26e73829c Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 21 Jan 2015 01:13:19 +0900 Subject: [PATCH 83/99] Fix some warnings within tests. --- test/algorithm/pop_back.cpp | 2 +- test/functional/invoke.cpp | 34 +++++++++++++++++++++------- test/functional/invoke_procedure.cpp | 17 ++++++++++---- test/sequence/adapt_struct.cpp | 2 +- test/sequence/move.hpp | 4 ++-- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/test/algorithm/pop_back.cpp b/test/algorithm/pop_back.cpp index e374152f..b594f6c8 100644 --- a/test/algorithm/pop_back.cpp +++ b/test/algorithm/pop_back.cpp @@ -95,7 +95,7 @@ main() #endif { - boost::array a = { 10, 50 }; + boost::array a = {{ 10, 50 }}; BOOST_TEST(back(pop_back(a)) == 10); } diff --git a/test/functional/invoke.cpp b/test/functional/invoke.cpp index 67e65feb..fa93332c 100644 --- a/test/functional/invoke.cpp +++ b/test/functional/invoke.cpp @@ -7,6 +7,7 @@ http://www.boost.org/LICENSE_1_0.txt). ==============================================================================*/ +#include #include #include @@ -146,11 +147,28 @@ class members int binary_c(int i, object) const { return data + 6 + i; } }; +#ifdef BOOST_NO_CXX11_SMART_PTR +typedef std::auto_ptr members_ptr; +typedef std::auto_ptr const_members_ptr; +#else +typedef std::unique_ptr members_ptr; +typedef std::unique_ptr const_members_ptr; +#endif + struct derived : members { }; +#ifdef BOOST_NO_CXX11_SMART_PTR +typedef std::auto_ptr derived_ptr; +typedef std::auto_ptr const_derived_ptr; +#else +typedef std::unique_ptr derived_ptr; +typedef std::unique_ptr const_derived_ptr; +#endif + + typedef int element1_type; typedef object element2_type; typedef object_nc & element3_type; @@ -161,8 +179,8 @@ object_nc element3; members that; -std::auto_ptr spt_that(new members); -std::auto_ptr spt_that_c(new members); +members_ptr spt_that(new members); +const_members_ptr spt_that_c(new members); fusion::single_view sv_obj_ctx( that); fusion::single_view sv_ref_ctx( that); @@ -170,13 +188,13 @@ fusion::single_view sv_ptr_ctx(& that); fusion::single_view sv_obj_c_ctx( that); fusion::single_view sv_ref_c_ctx( that); fusion::single_view sv_ptr_c_ctx(& that); -fusion::single_view const &> sv_spt_ctx(spt_that); -fusion::single_view< std::auto_ptr const &> sv_spt_c_ctx(spt_that_c); +fusion::single_view sv_spt_ctx(spt_that); +fusion::single_view sv_spt_c_ctx(spt_that_c); derived derived_that; -std::auto_ptr spt_derived_that(new derived); -std::auto_ptr spt_derived_that_c(new derived); +derived_ptr spt_derived_that(new derived); +const_derived_ptr spt_derived_that_c(new derived); fusion::single_view sv_obj_d_ctx( derived_that); fusion::single_view sv_ref_d_ctx( derived_that); @@ -184,8 +202,8 @@ fusion::single_view sv_ptr_d_ctx(& derived_that); fusion::single_view sv_obj_c_d_ctx( derived_that); fusion::single_view sv_ref_c_d_ctx( derived_that); fusion::single_view sv_ptr_c_d_ctx(& derived_that); -fusion::single_view const &> sv_spt_d_ctx(spt_derived_that); -fusion::single_view< std::auto_ptr const &> sv_spt_c_d_ctx(spt_derived_that_c); +fusion::single_view sv_spt_d_ctx(spt_derived_that); +fusion::single_view sv_spt_c_d_ctx(spt_derived_that_c); template void test_sequence_n(Sequence & seq, mpl::int_<0>) diff --git a/test/functional/invoke_procedure.cpp b/test/functional/invoke_procedure.cpp index 49c35d37..2ee8354d 100644 --- a/test/functional/invoke_procedure.cpp +++ b/test/functional/invoke_procedure.cpp @@ -7,6 +7,7 @@ http://www.boost.org/LICENSE_1_0.txt). ==============================================================================*/ +#include #include #include @@ -65,9 +66,17 @@ class members int binary_c(int & i, object) const { return i = data + 6; } }; +#ifdef BOOST_NO_CXX11_SMART_PTR +typedef std::auto_ptr members_ptr; +typedef std::auto_ptr const_members_ptr; +#else +typedef std::unique_ptr members_ptr; +typedef std::unique_ptr const_members_ptr; +#endif + members that; -std::auto_ptr spt_that(new members); -std::auto_ptr spt_that_c(new members); +members_ptr spt_that(new members); +const_members_ptr spt_that_c(new members); fusion::single_view sv_obj_ctx( that); fusion::single_view sv_ref_ctx( that); @@ -75,8 +84,8 @@ fusion::single_view sv_ptr_ctx(& that); fusion::single_view sv_obj_c_ctx( that); fusion::single_view sv_ref_c_ctx( that); fusion::single_view sv_ptr_c_ctx(& that); -fusion::single_view const &> sv_spt_ctx(spt_that); -fusion::single_view< std::auto_ptr const &> sv_spt_c_ctx(spt_that_c); +fusion::single_view sv_spt_ctx(spt_that); +fusion::single_view sv_spt_c_ctx(spt_that_c); struct fobj { diff --git a/test/sequence/adapt_struct.cpp b/test/sequence/adapt_struct.cpp index e64507cf..012e8e14 100644 --- a/test/sequence/adapt_struct.cpp +++ b/test/sequence/adapt_struct.cpp @@ -178,7 +178,7 @@ main() { fusion::vector v1(4, 2); - ns::bar v2 = {5, 3}; + ns::bar v2 = {{5}, 3}; BOOST_TEST(v1 < v2); BOOST_TEST(v1 <= v2); BOOST_TEST(v2 > v1); diff --git a/test/sequence/move.hpp b/test/sequence/move.hpp index febbc2bb..8636604f 100644 --- a/test/sequence/move.hpp +++ b/test/sequence/move.hpp @@ -38,12 +38,12 @@ namespace test_detail return *this; } - x(x const& rhs) + x(x const& /*rhs*/) { incr_copy(); } - x& operator=(x const& rhs) + x& operator=(x const& /*rhs*/) { incr_copy(); return *this; From 98247fb97fac82c0af8d27bc03f02bff2dc299bd Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Wed, 21 Jan 2015 00:28:13 +0100 Subject: [PATCH 84/99] =?UTF-8?q?BUGFIX:=C2=A0MSVC=20doesn't=20accept=20ty?= =?UTF-8?q?pename=20to=20specify=20a=20dependent=20scope=20within=20templa?= =?UTF-8?q?te=20specialization=20in=20C++03=20as=20standard=20specify=20it?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also works on GCC 4.6, 4.8.2 and 4.9 in C++11 and C++03, I needlessly added this during some debugging where the compiler was telling me to do so. I shouldn't have followed it's advice, as this breaks compatibility with other compilers. --- .../boost/fusion/adapted/adt/detail/adapt_base.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index b9126c94..0c1cebd0 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -54,12 +54,12 @@ ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ }; \ \ - typedef typename boost::remove_const< \ - typename deduced_attr_type::type \ + typedef boost::remove_const< \ + deduced_attr_type::type \ >::type type; \ \ - typedef typename boost::add_const< \ - typename deduced_attr_type::type \ + typedef boost::add_const< \ + deduced_attr_type::type \ >::type const_type; #define BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE( \ @@ -126,7 +126,7 @@ , true \ > \ { \ - typedef typename access::adt_attribute_access< \ + typedef access::adt_attribute_access< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ >::const_type type; \ @@ -165,7 +165,7 @@ , false \ > \ { \ - typedef typename access::adt_attribute_access< \ + typedef access::adt_attribute_access< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ >::type type; \ @@ -215,7 +215,7 @@ , I \ > \ { \ - typedef typename \ + typedef \ adt_attribute_proxy< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ From 3955f7651169c8907d7f0fb25ab62b787fc53c00 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 21 Jan 2015 17:27:14 +0900 Subject: [PATCH 85/99] Cosmetic --- doc/algorithm.qbk | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/algorithm.qbk b/doc/algorithm.qbk index bdcb66bb..3344d366 100644 --- a/doc/algorithm.qbk +++ b/doc/algorithm.qbk @@ -441,10 +441,10 @@ Linear, exactly `__result_of_size__::value` applications of `F`. [endsect] [section for_each] -A metafunction returning the result type of applying __for_each__ to a sequence. The -return type of __for_each__ is always `void`. [heading Description] +A metafunction returning the result type of applying __for_each__ to a sequence. The +return type of __for_each__ is always `void`. [heading Synopsis] template< @@ -724,8 +724,10 @@ or `__end__(seq)` if there is no such element. [heading Complexity] Linear. At most `__result_of_size__::value` comparisons. -#include -#include +[heading Header] + + #include + #include [heading Example] const __vector__ vec(1.0,2); From b3c560d3b6d062935b1e052c930f4440afe4c973 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 21 Jan 2015 19:34:44 +0900 Subject: [PATCH 86/99] Fix some typos. --- doc/algorithm.qbk | 4 ++-- doc/extension.qbk | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/algorithm.qbk b/doc/algorithm.qbk index 3344d366..f47fce5c 100644 --- a/doc/algorithm.qbk +++ b/doc/algorithm.qbk @@ -1363,7 +1363,7 @@ Returns a new sequence, with all the elements of the original sequence, except t typename T, typename Sequence > - typename __result_of_remove__::type replace(Sequence const& seq); + typename __result_of_remove__::type remove(Sequence const& seq); [table Parameters [[Parameter][Requirement][Description]] @@ -1832,7 +1832,7 @@ Constant. Returns a view which is lazily evaluated. #include [heading Example] - assert(___pop_back__(__make_vector__(1,2,3)) == __make_vector__(1,2)); + assert(__pop_back__(__make_vector__(1,2,3)) == __make_vector__(1,2)); [endsect] diff --git a/doc/extension.qbk b/doc/extension.qbk index 96e5ef61..cbb61ce5 100644 --- a/doc/extension.qbk +++ b/doc/extension.qbk @@ -323,7 +323,7 @@ For our __random_access_sequence__ we will also need to implement `size_impl`, In order for `example_struct` to serve as an associative forward sequence, we need to adapt the traversal category of our sequence and our iterator accordingly and enable 3 intrinsic sequence lookup features, __at_key__, -__value_at_key__ and __has_key__. We also need to enable 3 iterator lookup +__result_of_value_at_key__ and __has_key__. We also need to enable 3 iterator lookup features, __result_of_key_of__, __result_of_value_of_data__ and __deref_data__. To implement `at_key_impl` we need to associate the `fields::name` and `fields::age` From 995202044c7a1c23f101469aa3683dc8a3a5b981 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Sun, 18 Jan 2015 23:01:48 +0900 Subject: [PATCH 87/99] Basic move support for c++03 map --- .../fusion/container/map/detail/cpp03/map.hpp | 45 +++++++++++++++++++ .../map/detail/cpp03/map_forward_ctor.hpp | 30 +++++++++++-- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/include/boost/fusion/container/map/detail/cpp03/map.hpp b/include/boost/fusion/container/map/detail/cpp03/map.hpp index 8673895e..77227aae 100644 --- a/include/boost/fusion/container/map/detail/cpp03/map.hpp +++ b/include/boost/fusion/container/map/detail/cpp03/map.hpp @@ -24,6 +24,15 @@ #include #include #include +#include +#include +#include +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + defined(BOOST_MSVC) && (BOOST_MSVC == 1700) +// see map_forward_ctor.hpp +#include +#include +#endif #if !defined(BOOST_FUSION_DONT_USE_PREPROCESSED_FILES) #include @@ -45,6 +54,8 @@ #pragma wave option(preserve: 1) #endif +#define FUSION_HASH # + namespace boost { namespace fusion { struct void_; @@ -69,6 +80,10 @@ namespace boost { namespace fusion map() : data() {} + BOOST_FUSION_GPU_ENABLED + map(map const& rhs) + : data(rhs.data) {} + template BOOST_FUSION_GPU_ENABLED map(Sequence const& rhs) @@ -91,6 +106,34 @@ namespace boost { namespace fusion return *this; } +#if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES) +FUSION_HASH if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +#endif +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \ + (defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)) + BOOST_FUSION_GPU_ENABLED + map(map&& rhs) + : data(std::move(rhs.data)) {} + + template + BOOST_FUSION_GPU_ENABLED + map& operator=(T&& rhs) + { + data = BOOST_FUSION_FWD_ELEM(T, rhs); + return *this; + } + + BOOST_FUSION_GPU_ENABLED + map& operator=(map&& rhs) + { + data = std::move(rhs.data); + return *this; + } +#endif +#if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES) +FUSION_HASH endif +#endif + BOOST_FUSION_GPU_ENABLED storage_type& get_data() { return data; } BOOST_FUSION_GPU_ENABLED @@ -102,6 +145,8 @@ namespace boost { namespace fusion }; }} +#undef FUSION_HASH + #if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES) #pragma wave option(output: null) #endif diff --git a/include/boost/fusion/container/map/detail/cpp03/map_forward_ctor.hpp b/include/boost/fusion/container/map/detail/cpp03/map_forward_ctor.hpp index 3938f9a4..f69e5ee6 100644 --- a/include/boost/fusion/container/map/detail/cpp03/map_forward_ctor.hpp +++ b/include/boost/fusion/container/map/detail/cpp03/map_forward_ctor.hpp @@ -8,15 +8,14 @@ #if !defined(FUSION_MAP_FORWARD_CTOR_07222005_0106) #define FUSION_MAP_FORWARD_CTOR_07222005_0106 -#include -#include -#include +#define FUSION_FORWARD_CTOR_FORWARD(z, n, _) BOOST_FUSION_FWD_ELEM(U##n, _##n) #define BOOST_PP_FILENAME_1 \ #define BOOST_PP_ITERATION_LIMITS (1, FUSION_MAX_MAP_SIZE) #include BOOST_PP_ITERATE() +#undef FUSION_FORWARD_CTOR_FORWARD #endif #else // defined(BOOST_PP_IS_ITERATING) /////////////////////////////////////////////////////////////////////////////// @@ -34,6 +33,31 @@ map(BOOST_PP_ENUM_BINARY_PARAMS(N, typename detail::call_param::type arg)) : data(BOOST_PP_ENUM_PARAMS(N, arg)) {} +#if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES) +FUSION_HASH if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +#endif +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \ + (defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)) + template + BOOST_FUSION_GPU_ENABLED +#if N == 1 + explicit +#endif + map(BOOST_PP_ENUM_BINARY_PARAMS(N, U, && arg) +#if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES) && \ + N == 1 + // workaround for MSVC 10 +FUSION_HASH if defined(BOOST_MSVC) && (BOOST_MSVC == 1700) + , typename enable_if >::type* = 0 +FUSION_HASH endif +#endif + ) + : data(BOOST_PP_ENUM(N, FUSION_FORWARD_CTOR_FORWARD, arg)) {} +#endif +#if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES) +FUSION_HASH endif +#endif + #undef N #endif // defined(BOOST_PP_IS_ITERATING) From e4d43b00c1c63059e1cd4323ab99a30d58858420 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Thu, 22 Jan 2015 01:02:28 +0900 Subject: [PATCH 88/99] Cosmetic --- doc/fusion.qbk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/fusion.qbk b/doc/fusion.qbk index f6c5f654..829979e6 100644 --- a/doc/fusion.qbk +++ b/doc/fusion.qbk @@ -321,10 +321,10 @@ [def __result_of_invoke__ [link fusion.functional.invocation.metafunctions.invoke `result_of::invoke`]] [def __result_of_invoke_procedure__ [link fusion.functional.invocation.metafunctions.invoke_proc `result_of::invoke_procedure`]] [def __result_of_invoke_function_object__ [link fusion.functional.invocation.metafunctions.invoke_fobj `result_of::invoke_function_object`]] -[def __result_of_make_fused__ [link fusion.functional.generation.metafunctions.mk_fused `make_fused`]] -[def __result_of_make_fused_procedure__ [link fusion.functional.generation.metafunctions.mk_fused_proc `make_fused_procedure`]] -[def __result_of_make_fused_function_object__ [link fusion.functional.generation.metafunctions.mk_fused_fobj `make_fused_function_object`]] -[def __result_of_make_unfused__ [link fusion.functional.generation.metafunctions.mk_unfused `make_unfused`]] +[def __result_of_make_fused__ [link fusion.functional.generation.metafunctions.mk_fused `result_of::make_fused`]] +[def __result_of_make_fused_procedure__ [link fusion.functional.generation.metafunctions.mk_fused_proc `result_of::make_fused_procedure`]] +[def __result_of_make_fused_function_object__ [link fusion.functional.generation.metafunctions.mk_fused_fobj `result_of::make_fused_function_object`]] +[def __result_of_make_unfused__ [link fusion.functional.generation.metafunctions.mk_unfused `result_of::make_unfused`]] [def __recursive_inline__ [link fusion.notes.recursive_inlined_functions Recursive Inlined Functions]] [def __overloaded_functions__ [link fusion.notes.overloaded_functions Overloaded Functions]] From 70d5b40a7cfc08089f7ad862af073332cd6ab49e Mon Sep 17 00:00:00 2001 From: Damien Buhl alias daminetreg Date: Sun, 25 Jan 2015 16:10:34 +0100 Subject: [PATCH 89/99] BUGFIX: Expands typename for attribute_type only in case it is really a dependent scope. --- .../fusion/adapted/struct/detail/adapt_base.hpp | 15 ++++++++++----- 1 file changed, 10 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 3d755f72..6120a3b1 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -63,7 +63,7 @@ #define BOOST_FUSION_ATTRIBUTE_TYPEOF( \ - NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, IS_TPL) \ \ struct deduced_attr_type { \ static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ @@ -72,10 +72,11 @@ type; \ }; \ \ - typedef typename deduced_attr_type::type attribute_type; + typedef BOOST_PP_IF(IS_TPL, typename, ) \ + deduced_attr_type::type attribute_type; #define BOOST_FUSION_ATTRIBUTE_GIVENTYPE( \ - NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, unused) \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, IS_TPL) \ typedef \ BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) attribute_type; @@ -146,8 +147,12 @@ > \ { \ BOOST_PP_IF(DEDUCE_TYPE, \ - BOOST_FUSION_ATTRIBUTE_TYPEOF, BOOST_FUSION_ATTRIBUTE_GIVENTYPE \ - )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ + BOOST_FUSION_ATTRIBUTE_TYPEOF, BOOST_FUSION_ATTRIBUTE_GIVENTYPE)( \ + NAME_SEQ, \ + ATTRIBUTE, \ + ATTRIBUTE_TUPEL_SIZE, \ + PREFIX, \ + BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ)) \ \ BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ TEMPLATE_PARAMS_SEQ) \ From 588896de455d78d06f720e8b131fc6c3970b927f Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 25 Jan 2015 16:14:45 +0100 Subject: [PATCH 90/99] =?UTF-8?q?Revert=20"BUGFIX:=C2=A0MSVC=20doesn't=20a?= =?UTF-8?q?ccept=20typename=20to=20specify=20a=20dependent=20scope=20withi?= =?UTF-8?q?n"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 98247fb97fac82c0af8d27bc03f02bff2dc299bd. --- .../boost/fusion/adapted/adt/detail/adapt_base.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index 0c1cebd0..b9126c94 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -54,12 +54,12 @@ ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ }; \ \ - typedef boost::remove_const< \ - deduced_attr_type::type \ + typedef typename boost::remove_const< \ + typename deduced_attr_type::type \ >::type type; \ \ - typedef boost::add_const< \ - deduced_attr_type::type \ + typedef typename boost::add_const< \ + typename deduced_attr_type::type \ >::type const_type; #define BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE( \ @@ -126,7 +126,7 @@ , true \ > \ { \ - typedef access::adt_attribute_access< \ + typedef typename access::adt_attribute_access< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ >::const_type type; \ @@ -165,7 +165,7 @@ , false \ > \ { \ - typedef access::adt_attribute_access< \ + typedef typename access::adt_attribute_access< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ >::type type; \ @@ -215,7 +215,7 @@ , I \ > \ { \ - typedef \ + typedef typename \ adt_attribute_proxy< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ From 382c1e56458d139d8d39b64887cabc98a092cf33 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 25 Jan 2015 21:48:49 +0100 Subject: [PATCH 91/99] BUGFIX: Expands typename for attribute_type only in case it is really a dependent scope. --- .../fusion/adapted/adt/detail/adapt_base.hpp | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index b9126c94..ff514c7f 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -45,7 +45,7 @@ BOOST_PP_IF(DEDUCE_TYPE, 1, 3), ATTRIBUTE) #define BOOST_FUSION_ADT_ATTRIBUTE_TYPEOF( \ - NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, IS_TPL) \ \ struct deduced_attr_type { \ static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ @@ -54,16 +54,16 @@ ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ }; \ \ - typedef typename boost::remove_const< \ - typename deduced_attr_type::type \ + typedef BOOST_PP_IF(IS_TPL, typename, ) boost::remove_const< \ + BOOST_PP_IF(IS_TPL, typename, ) deduced_attr_type::type \ >::type type; \ \ - typedef typename boost::add_const< \ - typename deduced_attr_type::type \ + typedef BOOST_PP_IF(IS_TPL, typename, ) boost::add_const< \ + BOOST_PP_IF(IS_TPL, typename, ) deduced_attr_type::type \ >::type const_type; #define BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE( \ - NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, IS_TPL) \ \ typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) type; \ typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE) const_type; @@ -84,8 +84,12 @@ \ BOOST_PP_IF(DEDUCE_TYPE, \ BOOST_FUSION_ADT_ATTRIBUTE_TYPEOF, \ - BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE \ - )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX) \ + BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE)( \ + NAME_SEQ, \ + ATTRIBUTE, \ + ATTRIBUTE_TUPEL_SIZE, \ + PREFIX, \ + BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ)) \ \ template \ BOOST_FUSION_GPU_ENABLED \ @@ -126,7 +130,9 @@ , true \ > \ { \ - typedef typename access::adt_attribute_access< \ + typedef \ + BOOST_PP_IF(BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ), typename, ) \ + access::adt_attribute_access< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ >::const_type type; \ @@ -165,7 +171,9 @@ , false \ > \ { \ - typedef typename access::adt_attribute_access< \ + typedef \ + BOOST_PP_IF(BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ), typename, ) \ + access::adt_attribute_access< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ >::type type; \ @@ -215,7 +223,7 @@ , I \ > \ { \ - typedef typename \ + typedef BOOST_PP_IF(BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ), typename, ) \ adt_attribute_proxy< \ BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \ , I \ From de43345b346af9fa6c42707fbdea00d1e3a5ed4d Mon Sep 17 00:00:00 2001 From: Damien Buhl alias daminetreg Date: Sun, 25 Jan 2015 23:05:42 +0100 Subject: [PATCH 92/99] BUGFIX: Forwarding template parameters for MSVC to deduced_attr_type context thanks to BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS. --- .../fusion/adapted/adt/detail/adapt_base.hpp | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index ff514c7f..49751d0b 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -44,26 +44,37 @@ BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, \ BOOST_PP_IF(DEDUCE_TYPE, 1, 3), ATTRIBUTE) +#define BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ) \ + BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ) + #define BOOST_FUSION_ADT_ATTRIBUTE_TYPEOF( \ - NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, IS_TPL) \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ + \ + BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ + TEMPLATE_PARAMS_SEQ) \ \ struct deduced_attr_type { \ static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ - typedef BOOST_TYPEOF( \ + typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ + BOOST_TYPEOF( \ PREFIX() BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR( \ ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ }; \ \ - typedef BOOST_PP_IF(IS_TPL, typename, ) boost::remove_const< \ - BOOST_PP_IF(IS_TPL, typename, ) deduced_attr_type::type \ - >::type type; \ + typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ + boost::remove_const< \ + BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ + deduced_attr_type::type \ + >::type type; \ \ - typedef BOOST_PP_IF(IS_TPL, typename, ) boost::add_const< \ - BOOST_PP_IF(IS_TPL, typename, ) deduced_attr_type::type \ + typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ + boost::add_const< \ + BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ + deduced_attr_type::type \ >::type const_type; #define BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE( \ - NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, IS_TPL) \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ \ typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) type; \ typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE) const_type; @@ -89,7 +100,7 @@ ATTRIBUTE, \ ATTRIBUTE_TUPEL_SIZE, \ PREFIX, \ - BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ)) \ + TEMPLATE_PARAMS_SEQ) \ \ template \ BOOST_FUSION_GPU_ENABLED \ From fc1a60e8e660e7dda83acfed10b4f9b9865f0fb5 Mon Sep 17 00:00:00 2001 From: Damien Buhl alias daminetreg Date: Fri, 30 Jan 2015 18:17:36 +0100 Subject: [PATCH 93/99] Adding typename in front of BOOST_TYPEOF is only needed in MSVC when we check the type of a template. --- .../fusion/adapted/adt/detail/adapt_base.hpp | 27 +++++++++++++--- .../adapted/struct/detail/adapt_base.hpp | 32 ++++++++++++++++--- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index 49751d0b..4c277d63 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -47,8 +47,9 @@ #define BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ) \ BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ) -#define BOOST_FUSION_ADT_ATTRIBUTE_TYPEOF( \ - NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ +#ifdef BOOST_MSVC +# define BOOST_FUSION_DEDUCED_ATTR_TYPE(NAME_SEQ, ATTRIBUTE, \ + ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ \ BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ TEMPLATE_PARAMS_SEQ) \ @@ -56,10 +57,26 @@ struct deduced_attr_type { \ static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ - BOOST_TYPEOF( \ - PREFIX() BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR( \ + BOOST_TYPEOF( PREFIX() BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR( \ ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ - }; \ + }; + +#else +# define BOOST_FUSION_DEDUCED_ATTR_TYPE(NAME_SEQ, ATTRIBUTE, \ + ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ + struct deduced_attr_type { \ + static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ + typedef BOOST_TYPEOF( PREFIX() BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR( \ + ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ + }; + +#endif + +#define BOOST_FUSION_ADT_ATTRIBUTE_TYPEOF( \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ + \ + BOOST_FUSION_DEDUCED_ATTR_TYPE( \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ \ typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ boost::remove_const< \ diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index 6120a3b1..856de1f0 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -61,9 +61,31 @@ BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS_IMPL, \ BOOST_PP_TUPLE_EAT(1))(SEQ) +#define BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ) \ + BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ) -#define BOOST_FUSION_ATTRIBUTE_TYPEOF( \ - NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, IS_TPL) \ + +#ifdef BOOST_MSVC +# define BOOST_FUSION_ATTRIBUTE_TYPEOF( \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ + \ + BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ + TEMPLATE_PARAMS_SEQ) \ + \ + struct deduced_attr_type { \ + static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ + typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ + BOOST_TYPEOF( PREFIX() obj.BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, \ + 0, ATTRIBUTE)) \ + type; \ + }; \ + \ + typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ + deduced_attr_type::type attribute_type; + +#else +# define BOOST_FUSION_ATTRIBUTE_TYPEOF( \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ \ struct deduced_attr_type { \ static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ @@ -72,9 +94,11 @@ type; \ }; \ \ - typedef BOOST_PP_IF(IS_TPL, typename, ) \ + typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ deduced_attr_type::type attribute_type; +#endif + #define BOOST_FUSION_ATTRIBUTE_GIVENTYPE( \ NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, IS_TPL) \ typedef \ @@ -152,7 +176,7 @@ ATTRIBUTE, \ ATTRIBUTE_TUPEL_SIZE, \ PREFIX, \ - BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ)) \ + TEMPLATE_PARAMS_SEQ) \ \ BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ TEMPLATE_PARAMS_SEQ) \ From c6c9d872d37f2934605b96f1bed8581a00baceb0 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Sun, 1 Feb 2015 17:20:31 +0100 Subject: [PATCH 94/99] Factored out the IS_TPL macro. --- .../fusion/adapted/adt/detail/adapt_base.hpp | 25 ++++++++++--------- .../adapted/struct/detail/adapt_base.hpp | 16 ++++++------ .../adapted/struct/detail/adapt_is_tpl.hpp | 14 +++++++++++ 3 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 include/boost/fusion/adapted/struct/detail/adapt_is_tpl.hpp diff --git a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp index 4c277d63..79fd00d8 100644 --- a/include/boost/fusion/adapted/adt/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/adt/detail/adapt_base.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -44,9 +45,6 @@ BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, \ BOOST_PP_IF(DEDUCE_TYPE, 1, 3), ATTRIBUTE) -#define BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ) \ - BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ) - #ifdef BOOST_MSVC # define BOOST_FUSION_DEDUCED_ATTR_TYPE(NAME_SEQ, ATTRIBUTE, \ ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ @@ -56,9 +54,10 @@ \ struct deduced_attr_type { \ static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ - typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ - BOOST_TYPEOF( PREFIX() BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR( \ - ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ + typedef \ + BOOST_PP_IF(BOOST_FUSION_ADAPT_IS_TPL(TEMPLATE_PARAMS_SEQ),typename,) \ + BOOST_TYPEOF( PREFIX() BOOST_FUSION_ADAPT_ADT_ATTRIBUTE_GETEXPR( \ + ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, 1)) type; \ }; #else @@ -78,16 +77,18 @@ BOOST_FUSION_DEDUCED_ATTR_TYPE( \ NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ \ - typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ + typedef \ + BOOST_PP_IF(BOOST_FUSION_ADAPT_IS_TPL(TEMPLATE_PARAMS_SEQ),typename,) \ boost::remove_const< \ - BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ - deduced_attr_type::type \ + BOOST_PP_IF(BOOST_FUSION_ADAPT_IS_TPL(TEMPLATE_PARAMS_SEQ),typename,) \ + deduced_attr_type::type \ >::type type; \ \ - typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ + typedef \ + BOOST_PP_IF(BOOST_FUSION_ADAPT_IS_TPL(TEMPLATE_PARAMS_SEQ),typename,) \ boost::add_const< \ - BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ - deduced_attr_type::type \ + BOOST_PP_IF(BOOST_FUSION_ADAPT_IS_TPL(TEMPLATE_PARAMS_SEQ),typename,) \ + deduced_attr_type::type \ >::type const_type; #define BOOST_FUSION_ADT_ATTRIBUTE_GIVENTYPE( \ diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index 856de1f0..7bb90e2e 100644 --- a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp +++ b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -61,10 +62,6 @@ BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS_IMPL, \ BOOST_PP_TUPLE_EAT(1))(SEQ) -#define BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ) \ - BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ) - - #ifdef BOOST_MSVC # define BOOST_FUSION_ATTRIBUTE_TYPEOF( \ NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ @@ -74,13 +71,15 @@ \ struct deduced_attr_type { \ static const BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj; \ - typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ + typedef \ + BOOST_PP_IF(BOOST_FUSION_ADAPT_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ BOOST_TYPEOF( PREFIX() obj.BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, \ 0, ATTRIBUTE)) \ type; \ }; \ \ - typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ + typedef \ + BOOST_PP_IF(BOOST_FUSION_ADAPT_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ deduced_attr_type::type attribute_type; #else @@ -94,13 +93,14 @@ type; \ }; \ \ - typedef BOOST_PP_IF(BOOST_FUSION_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ + typedef \ + BOOST_PP_IF(BOOST_FUSION_ADAPT_IS_TPL(TEMPLATE_PARAMS_SEQ), typename, ) \ deduced_attr_type::type attribute_type; #endif #define BOOST_FUSION_ATTRIBUTE_GIVENTYPE( \ - NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, IS_TPL) \ + NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE, PREFIX, TEMPLATE_PARAMS_SEQ) \ typedef \ BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) attribute_type; diff --git a/include/boost/fusion/adapted/struct/detail/adapt_is_tpl.hpp b/include/boost/fusion/adapted/struct/detail/adapt_is_tpl.hpp new file mode 100644 index 00000000..2b54a2c0 --- /dev/null +++ b/include/boost/fusion/adapted/struct/detail/adapt_is_tpl.hpp @@ -0,0 +1,14 @@ +/*============================================================================= + 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_IS_TPL_HPP +#define BOOST_FUSION_ADAPTED_STRUCT_DETAIL_ADAPT_IS_TPL_HPP + +#define BOOST_FUSION_ADAPT_IS_TPL(TEMPLATE_PARAMS_SEQ) \ + BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ) + +#endif From b60219eb8adbbbf555b7a192208d5c3a67abbfd8 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Mon, 2 Feb 2015 04:08:13 +0900 Subject: [PATCH 95/99] Fix testcase for MSVC 10.0. MSVC 10.0/11.0 have but don't compile variadic templates. --- test/sequence/size.cpp | 6 ++++-- test/sequence/std_tuple_iterator.cpp | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/test/sequence/size.cpp b/test/sequence/size.cpp index f8254dad..8c4c5a55 100644 --- a/test/sequence/size.cpp +++ b/test/sequence/size.cpp @@ -19,7 +19,8 @@ #include #include #include -#if !defined(BOOST_NO_CXX11_HDR_TUPLE) +#if !defined(BOOST_NO_CXX11_HDR_TUPLE) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #include #include #endif @@ -89,7 +90,8 @@ void test() check >(); } -#if !defined(BOOST_NO_CXX11_HDR_TUPLE) +#if !defined(BOOST_NO_CXX11_HDR_TUPLE) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) { check >(); check >(); diff --git a/test/sequence/std_tuple_iterator.cpp b/test/sequence/std_tuple_iterator.cpp index 202fb7a5..e33db386 100644 --- a/test/sequence/std_tuple_iterator.cpp +++ b/test/sequence/std_tuple_iterator.cpp @@ -8,7 +8,8 @@ // The std_tuple_iterator adaptor only supports implementations // using variadic templates -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#if !defined(BOOST_NO_CXX11_HDR_TUPLE) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #include From 6ab68a29d8518e43d7efd1002dd7e12a590191e9 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Thu, 5 Feb 2015 23:04:36 +0900 Subject: [PATCH 96/99] Workaround for LWG 2408: SFINAE-friendly std::iterator_traits. Now available for GCC(libstdc++v3) < 4.5 and MSVC 12.0. It means, there is no ambiguous about calling next/prior/... via ADL. --- .../adapted/boost_array/array_iterator.hpp | 9 +++++++++ .../boost_tuple/boost_tuple_iterator.hpp | 9 +++++++++ .../boost/fusion/adapted/mpl/mpl_iterator.hpp | 9 +++++++++ .../adapted/std_tuple/std_tuple_iterator.hpp | 9 +++++++++ .../fusion/container/deque/deque_iterator.hpp | 9 +++++++++ .../fusion/container/list/cons_iterator.hpp | 9 +++++++++ .../fusion/container/map/map_iterator.hpp | 9 +++++++++ .../container/vector/vector_iterator.hpp | 9 +++++++++ .../boost/fusion/iterator/basic_iterator.hpp | 9 +++++++++ .../fusion/iterator/iterator_adapter.hpp | 9 +++++++++ .../boost/fusion/iterator/iterator_facade.hpp | 9 +++++++++ include/boost/fusion/support/config.hpp | 19 +++++++++++++++++++ .../view/filter_view/filter_view_iterator.hpp | 9 +++++++++ .../flatten_view/flatten_view_iterator.hpp | 9 +++++++++ .../view/joint_view/joint_view_iterator.hpp | 9 +++++++++ .../fusion/view/nview/nview_iterator.hpp | 9 +++++++++ .../repetitive_view_iterator.hpp | 9 +++++++++ .../reverse_view/reverse_view_iterator.hpp | 9 +++++++++ .../view/single_view/single_view_iterator.hpp | 9 +++++++++ .../transform_view_iterator.hpp | 12 ++++++++++++ .../view/zip_view/zip_view_iterator.hpp | 9 +++++++++ 21 files changed, 202 insertions(+) diff --git a/include/boost/fusion/adapted/boost_array/array_iterator.hpp b/include/boost/fusion/adapted/boost_array/array_iterator.hpp index 0e39d457..2002e2cc 100644 --- a/include/boost/fusion/adapted/boost_array/array_iterator.hpp +++ b/include/boost/fusion/adapted/boost_array/array_iterator.hpp @@ -109,4 +109,13 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::array_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/adapted/boost_tuple/boost_tuple_iterator.hpp b/include/boost/fusion/adapted/boost_tuple/boost_tuple_iterator.hpp index 40c5d79c..850eef5f 100644 --- a/include/boost/fusion/adapted/boost_tuple/boost_tuple_iterator.hpp +++ b/include/boost/fusion/adapted/boost_tuple/boost_tuple_iterator.hpp @@ -207,6 +207,15 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::boost_tuple_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/adapted/mpl/mpl_iterator.hpp b/include/boost/fusion/adapted/mpl/mpl_iterator.hpp index 43748d98..87de32ad 100644 --- a/include/boost/fusion/adapted/mpl/mpl_iterator.hpp +++ b/include/boost/fusion/adapted/mpl/mpl_iterator.hpp @@ -114,6 +114,15 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::mpl_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp b/include/boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp index c4d957ea..0ae4ae77 100644 --- a/include/boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp +++ b/include/boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp @@ -106,6 +106,15 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::std_tuple_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/container/deque/deque_iterator.hpp b/include/boost/fusion/container/deque/deque_iterator.hpp index f603b545..2b06bd8c 100644 --- a/include/boost/fusion/container/deque/deque_iterator.hpp +++ b/include/boost/fusion/container/deque/deque_iterator.hpp @@ -118,4 +118,13 @@ namespace boost { namespace fusion { }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::deque_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/container/list/cons_iterator.hpp b/include/boost/fusion/container/list/cons_iterator.hpp index da694756..0c3ec668 100644 --- a/include/boost/fusion/container/list/cons_iterator.hpp +++ b/include/boost/fusion/container/list/cons_iterator.hpp @@ -98,4 +98,13 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::cons_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/container/map/map_iterator.hpp b/include/boost/fusion/container/map/map_iterator.hpp index 4927e155..b79dd1da 100644 --- a/include/boost/fusion/container/map/map_iterator.hpp +++ b/include/boost/fusion/container/map/map_iterator.hpp @@ -163,4 +163,13 @@ namespace boost { namespace fusion }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::map_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/container/vector/vector_iterator.hpp b/include/boost/fusion/container/vector/vector_iterator.hpp index ffa4d138..8e586c54 100644 --- a/include/boost/fusion/container/vector/vector_iterator.hpp +++ b/include/boost/fusion/container/vector/vector_iterator.hpp @@ -48,5 +48,14 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::vector_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/iterator/basic_iterator.hpp b/include/boost/fusion/iterator/basic_iterator.hpp index 5d484132..eae46e63 100644 --- a/include/boost/fusion/iterator/basic_iterator.hpp +++ b/include/boost/fusion/iterator/basic_iterator.hpp @@ -144,4 +144,13 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::basic_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/iterator/iterator_adapter.hpp b/include/boost/fusion/iterator/iterator_adapter.hpp index 7e860c77..de8938f6 100644 --- a/include/boost/fusion/iterator/iterator_adapter.hpp +++ b/include/boost/fusion/iterator/iterator_adapter.hpp @@ -135,4 +135,13 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::iterator_adapter > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/iterator/iterator_facade.hpp b/include/boost/fusion/iterator/iterator_facade.hpp index a2c659ab..1760957e 100644 --- a/include/boost/fusion/iterator/iterator_facade.hpp +++ b/include/boost/fusion/iterator/iterator_facade.hpp @@ -56,4 +56,13 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::iterator_facade > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/support/config.hpp b/include/boost/fusion/support/config.hpp index 15d4be6e..924c2ff1 100644 --- a/include/boost/fusion/support/config.hpp +++ b/include/boost/fusion/support/config.hpp @@ -68,4 +68,23 @@ namespace boost { namespace fusion { namespace detail # define BOOST_FUSION_FWD_ELEM(type, value) std::forward(value) #endif + +// Workaround for LWG 2408: C++17 SFINAE-friendly std::iterator_traits. +// http://cplusplus.github.io/LWG/lwg-defects.html#2408 +// +// - GCC 4.5 enables the feature under C++11. +// https://gcc.gnu.org/ml/gcc-patches/2014-11/msg01105.html +// +// - Only MSVC 12.0 doesn't have the feature. +#if (defined(BOOST_LIBSTDCXX_VERSION) && (BOOST_LIBSTDCXX_VERSION < 40500) && \ + defined(BOOST_LIBSTDCXX11)) || \ + (defined(BOOST_MSVC) && (BOOST_MSVC == 1800)) +# define BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits; +} +#endif + #endif diff --git a/include/boost/fusion/view/filter_view/filter_view_iterator.hpp b/include/boost/fusion/view/filter_view/filter_view_iterator.hpp index 14aaa460..d407c9da 100644 --- a/include/boost/fusion/view/filter_view/filter_view_iterator.hpp +++ b/include/boost/fusion/view/filter_view/filter_view_iterator.hpp @@ -67,6 +67,15 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::filter_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/view/flatten_view/flatten_view_iterator.hpp b/include/boost/fusion/view/flatten_view/flatten_view_iterator.hpp index dfe613ac..e47868c1 100644 --- a/include/boost/fusion/view/flatten_view/flatten_view_iterator.hpp +++ b/include/boost/fusion/view/flatten_view/flatten_view_iterator.hpp @@ -194,6 +194,15 @@ namespace boost { namespace fusion { namespace extension }; }}} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::flatten_view_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/view/joint_view/joint_view_iterator.hpp b/include/boost/fusion/view/joint_view/joint_view_iterator.hpp index 98584740..d73a24fd 100644 --- a/include/boost/fusion/view/joint_view/joint_view_iterator.hpp +++ b/include/boost/fusion/view/joint_view/joint_view_iterator.hpp @@ -56,6 +56,15 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::joint_view_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/view/nview/nview_iterator.hpp b/include/boost/fusion/view/nview/nview_iterator.hpp index c614cbbb..b1111e84 100644 --- a/include/boost/fusion/view/nview/nview_iterator.hpp +++ b/include/boost/fusion/view/nview/nview_iterator.hpp @@ -54,6 +54,15 @@ namespace boost { namespace fusion }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::nview_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/view/repetitive_view/repetitive_view_iterator.hpp b/include/boost/fusion/view/repetitive_view/repetitive_view_iterator.hpp index b9f45d0c..ea9e491e 100644 --- a/include/boost/fusion/view/repetitive_view/repetitive_view_iterator.hpp +++ b/include/boost/fusion/view/repetitive_view/repetitive_view_iterator.hpp @@ -53,5 +53,14 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::repetitive_view_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/view/reverse_view/reverse_view_iterator.hpp b/include/boost/fusion/view/reverse_view/reverse_view_iterator.hpp index 9de2169e..b773f15d 100644 --- a/include/boost/fusion/view/reverse_view/reverse_view_iterator.hpp +++ b/include/boost/fusion/view/reverse_view/reverse_view_iterator.hpp @@ -54,5 +54,14 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::reverse_view_iterator > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/view/single_view/single_view_iterator.hpp b/include/boost/fusion/view/single_view/single_view_iterator.hpp index 128c1cae..50c15466 100644 --- a/include/boost/fusion/view/single_view/single_view_iterator.hpp +++ b/include/boost/fusion/view/single_view/single_view_iterator.hpp @@ -50,6 +50,15 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::single_view_iterator > + { }; +} +#endif + #if defined (BOOST_MSVC) # pragma warning(pop) #endif diff --git a/include/boost/fusion/view/transform_view/transform_view_iterator.hpp b/include/boost/fusion/view/transform_view/transform_view_iterator.hpp index 0762228f..19310fe1 100644 --- a/include/boost/fusion/view/transform_view/transform_view_iterator.hpp +++ b/include/boost/fusion/view/transform_view/transform_view_iterator.hpp @@ -76,5 +76,17 @@ namespace boost { namespace fusion }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::transform_view_iterator > + { }; + template + struct iterator_traits< ::boost::fusion::transform_view_iterator2 > + { }; +} +#endif + #endif diff --git a/include/boost/fusion/view/zip_view/zip_view_iterator.hpp b/include/boost/fusion/view/zip_view/zip_view_iterator.hpp index fec50e6f..16b2ca74 100644 --- a/include/boost/fusion/view/zip_view/zip_view_iterator.hpp +++ b/include/boost/fusion/view/zip_view/zip_view_iterator.hpp @@ -46,4 +46,13 @@ namespace boost { namespace fusion { }; }} +#ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 +namespace std +{ + template + struct iterator_traits< ::boost::fusion::zip_view_iterator > + { }; +} +#endif + #endif From 960ccf5d2c16b09a9559d220cdb3dd18ac48c0f4 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Sat, 21 Feb 2015 19:15:49 +0900 Subject: [PATCH 97/99] Fix dead links: caused by pull-request #51. --- doc/container.qbk | 12 ++++++------ doc/fusion.qbk | 2 +- doc/notes.qbk | 2 +- doc/support.qbk | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/container.qbk b/doc/container.qbk index 571c7f0a..427b6284 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -730,7 +730,7 @@ before including any Fusion header to change the default. Example: [heading See also] -__note_boost_ref__ +__note_ref_wrappers__ [endsect] @@ -778,7 +778,7 @@ __result_of_make_cons__`::type` [heading See also] -__note_boost_ref__ +__note_ref_wrappers__ [endsect] @@ -828,7 +828,7 @@ default. Example: [heading See also] -__note_boost_ref__ +__note_ref_wrappers__ [endsect] @@ -880,7 +880,7 @@ Fusion header to change the default. Example: [heading See also] -__note_boost_ref__ +__note_ref_wrappers__ [endsect] @@ -932,7 +932,7 @@ default. Example: [heading See also] -__note_boost_ref__ +__note_ref_wrappers__ [endsect] @@ -990,7 +990,7 @@ default. Example: [heading See also] -__note_boost_ref__, __fusion_pair__ +__note_ref_wrappers__, __fusion_pair__ [endsect] diff --git a/doc/fusion.qbk b/doc/fusion.qbk index 829979e6..0ca7919c 100644 --- a/doc/fusion.qbk +++ b/doc/fusion.qbk @@ -331,7 +331,7 @@ [def __tag_dispatching__ [link fusion.notes.tag_dispatching /tag dispatching/]] [def __element_conversion__ [link fusion.notes.element_conversion /element conversion/]] [def __see_element_conversion__ [link fusion.notes.element_conversion /see element conversion/]] -[def __note_boost_ref__ [link fusion.notes.boost__ref `boost::ref`]] +[def __note_ref_wrappers__ [link fusion.notes.reference_wrappers `Reference Wrappers`]] [def __quick_start__ [link fusion.quick_start Quick Start]] [def __organization__ [link fusion.organization Organization]] diff --git a/doc/notes.qbk b/doc/notes.qbk index 0377023c..02b1437f 100644 --- a/doc/notes.qbk +++ b/doc/notes.qbk @@ -100,7 +100,7 @@ Array arguments are deduced to reference to const types. For example [footnote Note that the type of a string literal is an array of const characters, not `const char*`. To get __make_list__ to create a __list__ with an element of a non-const array type one must use the `ref` wrapper -(see __note_boost_ref__).]: +(see __note_ref_wrappers__).]: __make_list__("Donald", "Daisy") diff --git a/doc/support.qbk b/doc/support.qbk index 1a473819..3e7b7a70 100644 --- a/doc/support.qbk +++ b/doc/support.qbk @@ -254,7 +254,7 @@ Metafunction to apply __element_conversion__ to the full argument type. It removes references to `const`, references to array types are kept, even if the array is `const`. Reference wrappers are removed (see -__note_boost_ref__)[footnote Since C++11, the standard reference wrappers +__note_ref_wrappers__)[footnote Since C++11, the standard reference wrappers are also removed.]. [heading Header] From 06428298bbb5180979f8e658dc896702c1b7e92d Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Sat, 21 Feb 2015 19:16:13 +0900 Subject: [PATCH 98/99] Add docs for std::tuple adaptation. --- doc/adapted.qbk | 33 +++++++++++++++++++++++++++++++-- doc/fusion.qbk | 1 + doc/html/index.html | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/doc/adapted.qbk b/doc/adapted.qbk index 9fd6c24a..a370e373 100644 --- a/doc/adapted.qbk +++ b/doc/adapted.qbk @@ -89,6 +89,35 @@ __std_pair_doc__, __tr1_tuple_pair__ [endsect] +[section std::tuple] + +This module provides adapters for `std::tuple`. Including the module header +makes `std::tuple` a fully conforming __random_access_sequence__. + +[important To be fully conforming, compiler should support C++11 Variadic Templates.] + +[heading Header] + + #include + #include + +[heading Model of] + +* __random_access_sequence__ + +[heading Example] + + std::tuple p(123, "Hola!!!", 456.f); + std::cout << __at_c__<0>(p) << std::endl; + std::cout << __at_c__<1>(p) << std::endl; + std::cout << p << std::endl; + +[heading See also] + +__std_tuple_doc__ + +[endsect] + [section mpl sequence] This module provides adapters for __mpl__ sequences. Including the module @@ -168,8 +197,8 @@ header makes `boost::tuple` a fully conforming __forward_sequence__. [heading Example] boost::tuple example_tuple(101, "hello"); - std::cout << *boost::fusion::begin(example_tuple) << '\n'; - std::cout << *boost::fusion::next(boost::fusion::begin(example_tuple)) << '\n'; + std::cout << *__begin__(example_tuple) << '\n'; + std::cout << *__next__(__begin__(example_tuple)) << '\n'; [heading See also] diff --git a/doc/fusion.qbk b/doc/fusion.qbk index 0ca7919c..d47fc9cd 100644 --- a/doc/fusion.qbk +++ b/doc/fusion.qbk @@ -55,6 +55,7 @@ [def __boost_func_factory__ [@http://www.boost.org/libs/functional/factory/doc/html/index.html Boost.Functional/Factory]] [def __boost_func_hash__ [@http://www.boost.org/doc/html/hash.html Boost.Functional/Hash]] [def __std_pair_doc__ [@http://www.sgi.com/tech/stl/pair.html `std::pair`]] +[def __std_tuple_doc__ [@http://en.cppreference.com/w/cpp/utility/tuple `std::tuple`]] [def __std_plus_doc__ [@http://www.sgi.com/tech/stl/plus.html `std::plus`]] [def __std_minus_doc__ [@http://www.sgi.com/tech/stl/minus.html `std::minus`]] diff --git a/doc/html/index.html b/doc/html/index.html index 03b417ee..0fd880b6 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -167,6 +167,7 @@
Array
std::pair
+
std::tuple
mpl sequence
boost::array
boost::tuple
From 197792ac538262edb7ff2165ffd4fc7e77b02d7f Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Sat, 21 Feb 2015 19:58:15 +0900 Subject: [PATCH 99/99] Conforming admonitions style to quickbook. http://www.boost.org/doc/libs/1_57_0/doc/html/quickbook/syntax/block.html#quickbook.syntax.block.admonitions --- doc/container.qbk | 14 +++++++------- doc/functional.qbk | 4 ++-- doc/fusion.qbk | 5 ----- doc/html/images/alert.png | Bin 603 -> 0 bytes doc/html/images/caution.png | Bin 1250 -> 0 bytes doc/html/images/home.png | Bin 358 -> 0 bytes doc/html/images/important.png | Bin 722 -> 0 bytes doc/html/images/next.png | Bin 336 -> 0 bytes doc/html/images/note.png | Bin 658 -> 0 bytes doc/html/images/prev.png | Bin 334 -> 0 bytes doc/html/images/smiley.png | Bin 867 -> 0 bytes doc/html/images/tip.png | Bin 640 -> 0 bytes doc/html/images/up.png | Bin 370 -> 0 bytes doc/html/images/warning.png | Bin 1241 -> 0 bytes doc/preface.qbk | 15 +++++---------- doc/sequence.qbk | 4 ++-- 16 files changed, 16 insertions(+), 26 deletions(-) delete mode 100755 doc/html/images/alert.png delete mode 100644 doc/html/images/caution.png delete mode 100755 doc/html/images/home.png delete mode 100644 doc/html/images/important.png delete mode 100755 doc/html/images/next.png delete mode 100755 doc/html/images/note.png delete mode 100755 doc/html/images/prev.png delete mode 100755 doc/html/images/smiley.png delete mode 100755 doc/html/images/tip.png delete mode 100755 doc/html/images/up.png delete mode 100644 doc/html/images/warning.png diff --git a/doc/container.qbk b/doc/container.qbk index 427b6284..270b184b 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -191,7 +191,7 @@ defined in __forward_sequence__. [[`__at__(l)`] [The Nth element from the beginning of the sequence; see __at__.]] ] -[blurb __note__ `__at__(l)` is provided for convenience and compatibility +[note `__at__(l)` is provided for convenience and compatibility with the original __tuple__ library, despite `cons` being a __forward_sequence__ only (`at` is supposed to be a __random_access_sequence__ requirement). The runtime complexity of __at__ is @@ -276,7 +276,7 @@ defined in __forward_sequence__. [[`__at__(l)`] [The Nth element from the beginning of the sequence; see __at__.]] ] -[blurb __note__ `__at__(l)` is provided for convenience and compatibility +[note `__at__(l)` is provided for convenience and compatibility with the original __tuple__ library, despite `list` being a __forward_sequence__ only (__at__ is supposed to be a __random_access_sequence__ requirement). The runtime complexity of __at__ is @@ -363,7 +363,7 @@ defined in __bidirectional_sequence__. [[`__at__(d)`] [The Nth element from the beginning of the sequence; see __at__.]] ] -[blurb __note__ `__at__(d)` is provided for convenience, despite +[note `__at__(d)` is provided for convenience, despite `deque` being a __bidirectional_sequence__ only (`at` is supposed to be a __random_access_sequence__ requirement). The runtime complexity of __at__ is constant (see __recursive_inline__). `deque` element access @@ -406,7 +406,7 @@ the same properties as the __deque__. [[`T`] [Element type] [ ]] ] -[blurb __note__ `Deque` can be a __deque__, a __front_extended_deque__ or a +[note `Deque` can be a __deque__, a __front_extended_deque__ or a __back_extended_deque__] [heading Model of] @@ -430,7 +430,7 @@ not defined in __bidirectional_sequence__. [[`__at__(d)`] [The Nth element from the beginning of the sequence; see __at__.]] ] -[blurb __note__ See __deque__ for further details.] +[note See __deque__ for further details.] [heading Example] @@ -467,7 +467,7 @@ the same properties as the __deque__. [[`T`] [Element type] [ ]] ] -[blurb __note__ `Deque` can be a __deque__, a __back_extended_deque__ or a +[note `Deque` can be a __deque__, a __back_extended_deque__ or a __back_extended_deque__] [heading Model of] @@ -491,7 +491,7 @@ not defined in __bidirectional_sequence__. [[`__at__(d)`] [The Nth element from the beginning of the sequence; see __at__.]] ] -[blurb __note__ See __deque__ for further details.] +[note See __deque__ for further details.] [heading Example] diff --git a/doc/functional.qbk b/doc/functional.qbk index 9bfdaa63..4a8e3d81 100644 --- a/doc/functional.qbk +++ b/doc/functional.qbk @@ -931,11 +931,11 @@ reference. Const qualification is preserved and propagated appropriately the target function object is const - or, in case the target function object is held by value, the adapter is const). -[blurb __note__ For Microsoft Visual C++ 7.1 (Visual Studio 2003) the detection +[note For Microsoft Visual C++ 7.1 (Visual Studio 2003) the detection of the Function Object's const qualification easily causes an internal error. Therefore the adapter is always treated as if it was const. ] -[blurb __tip__ If the type sequence passed to this template contains +[tip If the type sequence passed to this template contains non-reference elements, the element is copied only once - the call operator's signature is optimized automatically to avoid by-value parameters.] diff --git a/doc/fusion.qbk b/doc/fusion.qbk index d47fc9cd..81542f02 100644 --- a/doc/fusion.qbk +++ b/doc/fusion.qbk @@ -20,11 +20,6 @@ ] ] -[def __note__ [$images/note.png]] -[def __alert__ [$images/alert.png]] -[def __tip__ [$images/tip.png]] -[def __caution__ [$images/caution.png]] - [def __spirit__ [@http://spirit.sourceforge.net Spirit]] [def __phoenix__ [@http://www.boost.org/libs/phoenix/index.html Phoenix]] [def __mpl__ [@http://www.boost.org/libs/mpl/index.html MPL]] diff --git a/doc/html/images/alert.png b/doc/html/images/alert.png deleted file mode 100755 index b4645bc7e7cd81f2818bf22aa898e95f89f7b154..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 603 zcmeAS@N?(olHy`uVBq!ia0y~yV31^BU=ZVAW?*1oN<7}ez`(#Bl2vQw%VQUVy#($c(b7<_!Z&&*`7 zwYIFTuIA!kP?6(!`t<3^g$y0J3{Q73WQH(YSjJ#(AQj-}VXe>LZ_gkv$q?hiVP&Xj ztS4or%^)MjpsB?1|Nnp9pi5p13=F0vL4Lvi$p8#BTQ7jZgtNdSvY3H^>jMZgI;}C8 z!N9FSxfgB=H7N+NC77H_+N#nawR{=RqTMBX)(LXL|IjinhDSdCyWWZ3S$0kBOZbahGm>{cU3L4X z*xaKNrl+L*2&>`tT{GF}sK6TCoSy58@94C>csZ@3se0z)OD!J`ePg?KNk!eRu!nuZ zwIuy5g5`UyU*2!`JMiPV^UIVvmW1t{f1*^~1#9h_jDIZO*R6JmbN8&QBXd?)zY=(& z`HG+Mis#k2-hNM1nwI_8efYU@yAuCZhY42|Be;Juo!svFUA16}A_D^hgQu&X%Q~lo FCIA+53ZVc1 diff --git a/doc/html/images/caution.png b/doc/html/images/caution.png deleted file mode 100644 index 5b7809ca4a9c8d778087522e5ce04b6e90099595..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1250 zcmeAS@N?(olHy`uVBq!ia0y~yV2}V|4rT@hhU+WOo?>8NW(e>Jab;j&;NV~o5MYpy zU{F+KFf?Rva$<;zVn|MA$j)XcE@r5%W@u?)XlW_#>0#*UDemd%nKFf8%9P?MQ>y38 zVVEwkZjIWyHF@jSt$X(}?A@Du?i|Cp zbLXyIW4Lzh+_h`h?%iX!chB(NJdh*`E$$X&!4}4&+z{J`|sZwzJC|^ z{$1kxcf;@BzyJTw@c+NS|Nj#IN5NBISn~R-X--a%afBxQ|J!3zMjr_SU zk_iHr)f*lf{$5^Qz}I)@3FlWvw(w~u=1P@VsTP+$RNGvxbHL-(%M6nc6`{zlU zjGQJeveps+!&Jb&mD)L@hA} z1_tL6*NBqf{Irtt#G+IN2MuLS&)mfHRNut(%;anZ6Fnn63k6F{eFF=914D)6qRirw zN{8Ia;*!i{z0_j8l+uFyyb`_S{M?DV6n8K%Fld2|%S_KpEGaEYWk@zRFt#waFg8d` zG)YZPF-fe)lBATd3a!N{b-$VA&f+n^|#(~yCI Ofx*+&&t;ucLK6T%G-N*j diff --git a/doc/html/images/home.png b/doc/html/images/home.png deleted file mode 100755 index 5584aacb097a80e66a5320312b6e4eb017af1a06..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 358 zcmeAS@N?(olHy`uVBq!ia0y~yU=Rjj7G?$phK4%r{|pQa%*9TgAsieWw;%dHU|?WS z3GfMV6&Dfg?(A@OuseF>a6(*+nzF*onKLh6zO-%YmOy{sw6wJU|Nk%gvq74Hfq|za z$S?Rm0x$^OKX;CSfq}EYBeIx*fm;ZK886+f`@_J%pjzS@Q4*Y=R#Ki=l*-_nm|T>f zo0^iDsNj}alvU8YOY t9}F9JU6`43jMG5vNQA&8NcoN_f;wr$vARr(hAt9lu zscC6x>EvV>6{VS+EaBwj6ciMco$ZvI98_E!l$@NLot<4>UER|o(bHqOcQ41TYc{y!?kM?_wFg)yJvXsp5^oB z9Pi&Vyniq7|3Ab3{~Z7S3p{_W`TV)z`}cpO z$(;G%_wGG* z?AW<;=dNA5cJJQ3=g*(NfB*jb_wWDz|6hCQ@I3|w2F4_BcNgdM3%p4T42R|DNig) zWpL0?*7VFxOi%SqOwUZtRxr^s(z8&owA44S&^IttNG{4OE~#|Ltt>9dOx8;+)=McZ z$j>X$OU}=oxJz*d0|SE=*tpE}yu^~yqEv=t diff --git a/doc/html/images/next.png b/doc/html/images/next.png deleted file mode 100755 index 59800b4e87f60c0e3383ede2b384b9be0f5ffe8d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 336 zcmeAS@N?(olHy`uVBq!ia0y~yU=Rjj7G?$phK4%r{|pQa%*9TgAsieWw;%dHU|?WS z3GfMV6&Dfg?(8r&Hr}>%OQ656nzF)*4nJa0`Jj)#l9-t%+}PK^d+g590~2^trx_V+aGYt)W#Kgko@Q{~>i6>w}LxPb)_bi1gN;4a>^d{wcURt*495hZOYc8|NsA=8=F$dz`$Tq666>BpLD?B9j=thz`(#+;1OBOz`*qZgc+UI zn9N{cU{Eb_jVKAuPb(=;EJ|hYO-wGz&rMCqOjK~oEJ`iUFUl@f@QqL~GB7Y{FI#h- zfq_xR)5S5QVovU)+hxrP02oy7clOl(|F;(fCx<^{O+3$d{!GJf zAT>%@)+Kac%o^ zm8~at%dZNSg`XDA>HpujeRb(tA@xWH1+`xhu}_a!eJ{ORYJcMi$Ma>cBHv0)HBxa4 zSGC~^nY{G5@1(nj{7!xJ-s1V$LbWCK_xDFLe3_MRf4msHv}xJrfBaF7=BYjUcQ!FF PFfe$!`njxgN@xNAS|c%7 diff --git a/doc/html/images/prev.png b/doc/html/images/prev.png deleted file mode 100755 index d88a40f923e3c554125f01cd366707c60cfcad04..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 334 zcmeAS@N?(olHy`uVBq!ia0y~yU=Rjj7G?$phK4%r{|pQa%*9TgAsieWw;%dHU|?WS z3GfMV6&DdqOG`60Hr}>%%ZlYo1O0u~loc*tzSP~>;p||S5Et|R|Noh1c$yg)73T~N2spa`a*~JRJ5eh~I1}5!gYtAz;Fo=OPI2WZRmSpDVDTHL^rZN~B=o=X8 z8<-ql-^0nkz!2u?;uumfC;0|1OPoRyGxLNShYX~Tl_Wf9G1_imu)%RA9}mw<0X2^e zQioc&m}WXSvRw^OFi2qFa&lm1W^U?K=~^Ook|m{hVvche^Q6-g?(V)Vn8U=toEqFE UkjD9gfq{X+)78&qol`;+00?PtqyPW_ diff --git a/doc/html/images/smiley.png b/doc/html/images/smiley.png deleted file mode 100755 index 30a77f71ce16872d046a1a5d6fd698a2f65a3f62..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 867 zcmeAS@N?(olHy`uVBq!ia0y~yU=U|uV36QoW?*1YTQtp`fq{X!*vT`5gM;JtL;nX1 z42*&SJ|V8+B7&<|tz5IBw4@*~EXexT*H!m!O?Pp!sH>^CckiyDuKJ|Dl+(w%CQay1 zOYu8%=FGd73zHKgmoF}|u{3I~kKDVXVbQ_`9c`_Fz7{iQrl~4QMTGi1fByW=jcKLD z*?C#s*_rWAAIx@f)c16=+qAB-t1T`u&hzVsWjnTSn>lml<@5cSX&!B@jUfSci{|F_ z_w^KKXB!)+#6)_3`t<4gwQEt~&MzL%J+!ao-_JD<@64PzGws6Z-hv$8-Me=7btN{` zl~t96rKP3$c$&I9TcsogXQl?mL%y{W;-5&-92C)*?h!W?b)Wnj^{5*w_%-mE4Lj!$7BYguC zr{Y6*7#J8-K`Mgt(@M${i&7bU6O)Vbb5m0?6BXPti&D$;i?WLqd?OT$3=B-#%hsG{ zU|`huba4!+n3FrHHoVC|#v<-Y&ynX`2+ z)ci{*-@n^>-frGI_MA-9eHCQCFMs-NiTvCzJ8a&6h<9#D<(d3(^{E}JLTitR9GSK2 z$*O4*8tU!OHS*&Yg~mSMD)7~hd93j+u`cf5MM<4*zJ;yfFKhYEn9bv3Xeg3g;K-G= z;q?Q<5Qk-d*rznCncd{p+umG~t-YZ3L%_f9;YyrSd?k7nE}0j~xg-T!p1r_pXw_8J z^q9XtRP=q)pSk7_!?YePxacL!`8E4~v$oZii_iB4y^t?YSBana!LlH(Q{_whcc+EB z6^^opPM-68`QEg&=hc<^;brIeKBf1+k=uTZ@Aa)4^R8_EExPXM@|~g)-OB%bBP#i` ie0$=QHXfdLO8@!p%oni+1)dBH3=E#GelF{r5}E*N2(Kal diff --git a/doc/html/images/tip.png b/doc/html/images/tip.png deleted file mode 100755 index 9f596b0b88eb42562b2d0b0e30d054509be42af2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 640 zcmeAS@N?(olHy`uVBq!ia0y~yV2}V|4rT@hhU+WOo?>8NU@ms@4B_D5xc$)o0Rsa= zZ-7sTtD>UflSfBq&1}s`kJ`U?skgWH)2B~oOmF`E^TxIg4+D?5M~H-?Y?- zI&~E<1_lQGk|4j}{|LZEaktF(-D? z%Sp`&0xgDm?d}|!0v)M>{a+K-KKU!3@9L8LOa5Z1>0OX+j1SY)GfWc?{l8U z$2VD9PtNu%kvS~%Xw8E;=95FN9-q3V{gPE~*|fjR%QkDRKeb=t2Ll5GgQu&X%Q~lo FCIFO8ExiB$ diff --git a/doc/html/images/up.png b/doc/html/images/up.png deleted file mode 100755 index 17d9c3ec491ae1ba22188ce85985623c92ffa9be..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 370 zcmeAS@N?(olHy`uVBq!ia0y~yU=Rjj7G?$phK4%r{|pQa%*9TgAsieWw;%dHU|?X- z3h)VW6&DdqOG|Thu-mqE%ZlYoyE{8BU%nLR@2jS)FmvY2qel)W#Kk;%^zi@x|I?Un z*fKCM@RbDl1^-6|46X<6oM2#J;4JWnEM{Qf76M_$OLy!3FfcHvmbgZg1m~xflqVLY zGWaGY7v<-srer26xMdclmgg5`7c2NiC>R+Sn6#IzInThrAO_OlT$Gwvl9`{U5R#dj z%3x@qZ(yu%U~+tY4<`cyLy@P8V@SoEspmFwHW&!FJyeg_(XezvV9WvAI|r@_>dZZG zPW6aiOT!J--9O?NG0%AP;}ge|4lDQN4=-}8`?JGwx}?mMnO)OdyQdu$nQCjPRV}jm z$u!Qa8E-cQ-r3Nz>Y(YPTd#BPEH+&8GWqfD!}4*53%dA!%#3$cIv;a~fq{X+)78&q Iol`;+0POUaApigX diff --git a/doc/html/images/warning.png b/doc/html/images/warning.png deleted file mode 100644 index 1c33db8f34a8b42b373179b46a2d8d8a10e061a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1241 zcmeAS@N?(olHy`uVBq!ia0y~yV2}V|4rT@hhU+WOo?>8NW(e>JaphoO5CF?5GB9W| zFc>m0I59AIF)#!%FhnshWHT@nGcZ&$Ftji*^e`|?VPKe2T|Fl#Xiikroa*YO3=B&x zEth(EEp2I8I%UezrAyZ`FswB+TsvjTRtAQxnwndCdbZA)vvujxty{P5WnkF5cJ1D+ zTaPg?91{>YCLwX`*s*gA4Ce#{&Phm|)6~4iz;I1d^V+p*_ZS%N-Mjakf#JEL;`8Uv z-!m}0=iqq%{{43bhVS3M|7T$MKMF=efJz}yVEuRs0|NtNlDE4HLkFv@2Ll7c3r`ov zkcwNmlWOyu3izvS7ejxP>R-!INP5f(XN|IS^C^Iyp?`SUk1vQO?s(K&l| zi|Nkt0@~*ymDp65*E-HED6u(s{Mfrxmah{JrgAMTIq)Du?nC5nnYTRgThA|azEdIl zD^uvV>~q(b?>`Fd;xnAbe7so1I$-&keKN}|vNNOCvX<~g{)wp7{&hR__v^cBU*Gq* zV3YS!cBPWsl#eNWc|~nAXWMOB8tQWBuXo=4>}cytyX_5F^Az{bVJ>7~U~n#RjVKAu zPb(=;EJ|f?&`{R&%uP&B^-WCAOwLv?(KFJsP_VSrH?Yt*FjPn`$}BFabjYnNF3C*R zOD)z*DJ{s)E742N&z-nSaR&nfgBIAh%=Em(lG377hGY|?B=Z!b6jL*k#Ka_13kwTN zLrZf@a|7cv1EVApQ-8txlNlHo_&~Y>64O%|j7%zwOtcNO4T_>U4H+017(8A5T-G@y GGywozG)2h( diff --git a/doc/preface.qbk b/doc/preface.qbk index 635b3bde..2fff963a 100644 --- a/doc/preface.qbk +++ b/doc/preface.qbk @@ -49,16 +49,11 @@ and traversal routines. It was an instant /AHA!/ moment. Some icons are used to mark certain topics indicative of their relevance. These icons precede some text to indicate: -[table Icons - [[Icon] [Name] [Meaning]] - [[__note__] [Note] [Information provided is auxiliary but will - give the reader a deeper insight into a specific - topic. May be skipped.]] - [[__alert__] [Alert] [Information provided is of utmost importance.]] - [[__caution__] [Caution] [A mild warning.]] - [[__tip__] [Tip] [A potentially useful and helpful piece of - information.]] -] +[note Information provided is auxiliary but will give the reader a deeper +insight into a specific topic. May be skipped.] +[important Information provided is of utmost importance.] +[caution A mild warning.] +[tip A potentially useful and helpful piece of information.] This documentation is automatically generated by Boost QuickBook documentation tool. QuickBook can be found in the __boost_tools__. diff --git a/doc/sequence.qbk b/doc/sequence.qbk index 4722124a..5957a6e1 100644 --- a/doc/sequence.qbk +++ b/doc/sequence.qbk @@ -255,7 +255,7 @@ any Random Access Sequence the following must be met: [[`__result_of_value_at_c__::type`] [Amortized constant time]] ] -[blurb __note__ `__result_of_at__` returns the actual type returned by +[note `__result_of_at__` returns the actual type returned by `__at__(s)`. In most cases, this is a reference. Hence, there is no way to know the exact element type using `__result_of_at__`.The element at `M` may actually be a reference to begin with. For this purpose, you can use @@ -330,7 +330,7 @@ For any Associative Sequence the following expressions must be valid: [[`__result_of_value_at_key__::type`] [Amortized constant time]] ] -[blurb __note__ `__result_of_at_key__` returns the actual type returned +[note `__result_of_at_key__` returns the actual type returned by `__at_key__(s)`. In most cases, this is a reference. Hence, there is no way to know the exact element type using `__result_of_at_key__`.The element at `K` may actually be a reference to begin with. For this purpose,