diff --git a/doc/adapted.qbk b/doc/adapted.qbk index f762a049..e6adfd29 100644 --- a/doc/adapted.qbk +++ b/doc/adapted.qbk @@ -185,10 +185,20 @@ necessary boilerplate to make an arbitrary struct a model of __random_access_sequence__. [heading Synopsis] + BOOST_FUSION_ADAPT_STRUCT( + struct_name, + member_name0, + member_name1, + member_name2, + ... + ) + + // When BOOST_PP_VARIADICS is missing : BOOST_FUSION_ADAPT_STRUCT( struct_name, (member_type0, member_name0) (member_type1, member_name1) + (BOOST_FUSION_ADAPT_AUTO, member_name2) ... ) @@ -196,9 +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. + +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. @@ -208,7 +222,7 @@ namespace qualified name of the struct to be adapted. #include #include -[heading Example] +[heading Example: BOOST_FUSION_ADAPT_STRUCT ] namespace demo { struct employee @@ -221,8 +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) + + // When BOOST_PP_VARIADICS is missing : + BOOST_FUSION_ADAPT_STRUCT( + demo::employee, + (BOOST_FUSION_ADAPT_AUTO, name) + (BOOST_FUSION_ADAPT_AUTO, age) + ) [endsect] @@ -234,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 BOOST_PP_VARIADICS is missing : 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), ... ) @@ -252,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. @@ -272,6 +306,7 @@ namespace qualified name of the struct to be adapted. { Name name; Age age; + int employment_timestamp; }; } @@ -280,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] diff --git a/include/boost/fusion/adapted/struct/adapt_struct.hpp b/include/boost/fusion/adapted/struct/adapt_struct.hpp index f60ca03e..4c798518 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) @@ -10,8 +11,10 @@ #define BOOST_FUSION_ADAPTED_STRUCT_ADAPT_STRUCT_HPP #include +#include #include #include +#include #include #include #include @@ -19,6 +22,7 @@ #include #include +#include #include #include #include @@ -30,43 +34,83 @@ #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 -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_0_END -#define BOOST_FUSION_ADAPT_STRUCT_FILLER_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) + 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_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), \ - (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_AUTO BOOST_PP_EMPTY() -#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) +#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) + +# 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 + +# 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, \ + 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) + +# 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 #endif diff --git a/include/boost/fusion/adapted/struct/detail/adapt_base.hpp b/include/boost/fusion/adapted/struct/detail/adapt_base.hpp index db702ae1..c5721224 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) @@ -25,12 +26,15 @@ #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) \ BOOST_PP_EMPTY() @@ -55,6 +59,17 @@ 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)) \ + +#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 # define BOOST_FUSION_ADAPT_STRUCT_TAG_OF_SPECIALIZATION( \ MODIFIER, TEMPLATE_PARAMS_SEQ, NAME_SEQ, TAG) \ @@ -118,7 +133,9 @@ > \ { \ typedef \ - BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) \ + BOOST_PP_IF(BOOST_PP_LESS(ATTRIBUTE_TUPEL_SIZE,2), \ + BOOST_FUSION_ATTRIBUTE_TYPEOF, BOOST_FUSION_ATTRIBUTE_GIVENTYPE \ + )(NAME_SEQ, ATTRIBUTE, ATTRIBUTE_TUPEL_SIZE) \ attribute_type; \ BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \ TEMPLATE_PARAMS_SEQ) \ @@ -143,7 +160,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); \ } \ }; \ }; \ @@ -163,7 +182,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)); \ } \ }; 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 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 68240463..406030dd 100644 --- a/test/sequence/adapt_struct.cpp +++ b/test/sequence/adapt_struct.cpp @@ -38,6 +38,7 @@ namespace ns { int x; int y; + int z; }; #if !BOOST_WORKAROUND(__GNUC__,<4) @@ -48,65 +49,96 @@ 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) - (int, y) -) +#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() { using namespace boost::fusion; using namespace boost; + using ns::point; std::cout << tuple_open('['); std::cout << tuple_close(']'); 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)); + 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::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); - ns::point v2 = {5, 3}; - fusion::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); @@ -118,16 +150,16 @@ main() } { - // conversion from ns::point to vector - ns::point p = {5, 3}; - 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}; - fusion::list l(p); + // conversion from point to list + point p = {5, 3, 3}; + list l(p); l = p; } @@ -150,12 +182,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 352cf995..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), - (X, 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; }