added intrusive struct generating macros

[SVN r61018]
This commit is contained in:
Christopher Schmidt
2010-04-03 13:34:20 +00:00
parent d8a40f48a6
commit 073ce9e4a3
13 changed files with 924 additions and 38 deletions

View File

@ -101,8 +101,8 @@ header makes `boost::array` a fully conforming __random_access_sequence__.
[heading Header]
#include <boost/fusion/adapted/array.hpp>
#include <boost/fusion/include/array.hpp>
#include <boost/fusion/adapted/boost_array.hpp>
#include <boost/fusion/include/boost_array.hpp>
[heading Model of]

View File

@ -0,0 +1,41 @@
/*=============================================================================
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)
==============================================================================*/
#ifndef BOOST_FUSION_ADAPTED_STRUCT_DEFINE_ASSOC_STRUCT_HPP
#define BOOST_FUSION_ADAPTED_STRUCT_DEFINE_ASSOC_STRUCT_HPP
#include <boost/fusion/adapted/struct/adapt_assoc_struct.hpp>
#include <boost/fusion/adapted/struct/detail/define_struct.hpp>
#define BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT( \
TEMPLATE_PARAMS_SEQ, NAMESPACE_SEQ, NAME, ATTRIBUTES) \
\
BOOST_FUSION_DEFINE_TPL_STRUCT_IMPL( \
TEMPLATE_PARAMS_SEQ, \
(0)NAMESPACE_SEQ, \
NAME, \
BOOST_PP_CAT(BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0 ATTRIBUTES,_END), \
3) \
\
BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( \
TEMPLATE_PARAMS_SEQ, \
(BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION((0)NAMESPACE_SEQ) NAME)\
TEMPLATE_PARAMS_SEQ, \
ATTRIBUTES)
#define BOOST_FUSION_DEFINE_ASSOC_STRUCT(NAMESPACE_SEQ, NAME, ATTRIBUTES) \
BOOST_FUSION_DEFINE_STRUCT_IMPL( \
(0)NAMESPACE_SEQ, \
NAME, \
BOOST_PP_CAT(BOOST_FUSION_ADAPT_ASSOC_STRUCT_FILLER_0 ATTRIBUTES,_END), \
3) \
\
BOOST_FUSION_ADAPT_ASSOC_STRUCT( \
BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION((0)NAMESPACE_SEQ) NAME, \
ATTRIBUTES)
#endif

View File

@ -0,0 +1,41 @@
/*=============================================================================
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)
==============================================================================*/
#ifndef BOOST_FUSION_ADAPTED_STRUCT_DEFINE_STRUCT_HPP
#define BOOST_FUSION_ADAPTED_STRUCT_DEFINE_STRUCT_HPP
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/adapted/struct/detail/define_struct.hpp>
#define BOOST_FUSION_DEFINE_TPL_STRUCT( \
TEMPLATE_PARAMS_SEQ, NAMESPACE_SEQ, NAME, ATTRIBUTES) \
\
BOOST_FUSION_DEFINE_TPL_STRUCT_IMPL( \
TEMPLATE_PARAMS_SEQ, \
(0)NAMESPACE_SEQ, \
NAME, \
BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_0 ATTRIBUTES,_END), \
2) \
\
BOOST_FUSION_ADAPT_TPL_STRUCT( \
TEMPLATE_PARAMS_SEQ, \
(BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION((0)NAMESPACE_SEQ) NAME)\
TEMPLATE_PARAMS_SEQ, \
ATTRIBUTES)
#define BOOST_FUSION_DEFINE_STRUCT(NAMESPACE_SEQ, NAME, ATTRIBUTES) \
BOOST_FUSION_DEFINE_STRUCT_IMPL( \
(0)NAMESPACE_SEQ, \
NAME, \
BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_FILLER_0 ATTRIBUTES,_END), \
2) \
\
BOOST_FUSION_ADAPT_STRUCT( \
BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION((0)NAMESPACE_SEQ) NAME, \
ATTRIBUTES)
#endif

View File

@ -0,0 +1,308 @@
/*=============================================================================
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)
==============================================================================*/
#ifndef BOOST_FUSION_ADAPTED_DETAIL_STRUCT_DEFINE_STRUCT_HPP
#define BOOST_FUSION_ADAPTED_DETAIL_STRUCT_DEFINE_STRUCT_HPP
#include <boost/config.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/iterator/advance.hpp>
#include <boost/fusion/adapted/struct/detail/adapt_base.hpp>
#include <boost/fusion/adapted/struct/detail/namespace.hpp>
#include <boost/preprocessor/inc.hpp>
#include <boost/preprocessor/if.hpp>
#include <boost/preprocessor/dec.hpp>
#include <boost/preprocessor/logical/not.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/comparison/equal.hpp>
#include <boost/preprocessor/seq/seq.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/seq/for_each_i.hpp>
#include <boost/preprocessor/seq/enum.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/preprocessor/tuple/elem.hpp>
#include <boost/preprocessor/tuple/eat.hpp>
#include <boost/call_traits.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/utility/enable_if.hpp>
#define BOOST_FUSION_DEFINE_STRUCT_COPY_CTOR_FILLER_I( \
R, ATTRIBUTE_TUPEL_SIZE, I, ATTRIBUTE) \
\
BOOST_PP_COMMA_IF(I) \
BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE,1,ATTRIBUTE)( \
other_self.BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE,1,ATTRIBUTE))
#define BOOST_FUSION_DEFINE_STRUCT_ASSIGN_FILLER_I( \
R, ATTRIBUTE_TUPEL_SIZE, I_, ATTRIBUTE) \
\
BOOST_PP_IF( \
I_, \
typedef typename \
boost::fusion::result_of::next< \
BOOST_PP_CAT(I,BOOST_PP_DEC(I_)) \
>::type \
BOOST_PP_CAT(I,I_); \
BOOST_PP_CAT(I,I_) BOOST_PP_CAT(i,I_)= \
boost::fusion::next(BOOST_PP_CAT(i,BOOST_PP_DEC(I_)));, \
BOOST_PP_EMPTY() \
) \
\
BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE,1,ATTRIBUTE)= \
boost::fusion::deref(BOOST_PP_CAT(i,I_));
#define BOOST_FUSION_DEFINE_STRUCT_ASSIGN_OP( \
ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
\
template<typename Seq> \
self_type& \
operator=(Seq const& seq) \
{ \
typedef typename \
boost::fusion::result_of::begin<Seq const>::type \
I0; \
I0 i0=boost::fusion::begin(seq); \
\
BOOST_PP_SEQ_FOR_EACH_I_R( \
1, \
BOOST_FUSION_DEFINE_STRUCT_ASSIGN_FILLER_I, \
ATTRIBUTE_TUPEL_SIZE, \
ATTRIBUTES_SEQ) \
\
return *this; \
}
#define BOOST_FUSION_DEFINE_STRUCT_ATTR_I(R, ATTRIBUTE_TUPEL_SIZE, ATTRIBUTE) \
\
BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE,0,ATTRIBUTE) \
BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE,1,ATTRIBUTE);
#define BOOST_FUSION_DEFINE_STRUCT_SEQ_CTOR_FILLER_I( \
R, ATTRIBUTE_TUPEL_SIZE, I, ATTRIBUTE) \
\
BOOST_PP_COMMA_IF(I) \
BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE,1,ATTRIBUTE)( \
boost::fusion::deref(boost::fusion::advance_c<I>(boost::fusion::begin( \
seq))))
#define BOOST_FUSION_DEFINE_STRUCT_SEQ_CTOR_DISABLER( \
ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
\
, typename boost::disable_if< \
boost::is_convertible< \
Seq const& \
, BOOST_PP_TUPLE_ELEM( \
ATTRIBUTE_TUPEL_SIZE, \
0, \
BOOST_PP_SEQ_HEAD(ATTRIBUTES_SEQ)) \
> \
>::type* =0
#define BOOST_FUSION_DEFINE_STRUCT_SEQ_DEFAULT_CTOR_FILLER_I( \
R, ATTRIBUTE_TUPEL_SIZE, I, ATTRIBUTE) \
\
BOOST_PP_COMMA_IF(I) \
BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE,1,ATTRIBUTE)()
#define BOOST_FUSION_DEFINE_STRUCT_IMPL_IMPL( \
NAME, ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
\
BOOST_PP_SEQ_FOR_EACH_R( \
1, \
BOOST_FUSION_DEFINE_STRUCT_ATTR_I, \
ATTRIBUTE_TUPEL_SIZE, \
ATTRIBUTES_SEQ) \
\
NAME() \
: BOOST_PP_SEQ_FOR_EACH_I_R( \
1, \
BOOST_FUSION_DEFINE_STRUCT_SEQ_DEFAULT_CTOR_FILLER_I, \
ATTRIBUTE_TUPEL_SIZE, \
ATTRIBUTES_SEQ) \
{} \
\
NAME(self_type const& other_self) \
: BOOST_PP_SEQ_FOR_EACH_I_R( \
1, \
BOOST_FUSION_DEFINE_STRUCT_COPY_CTOR_FILLER_I, \
ATTRIBUTE_TUPEL_SIZE, \
ATTRIBUTES_SEQ) \
{} \
\
template<typename Seq> \
NAME(Seq const& seq \
BOOST_PP_IF( \
BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(ATTRIBUTES_SEQ)), \
BOOST_PP_TUPLE_EAT(2), \
BOOST_FUSION_DEFINE_STRUCT_SEQ_CTOR_DISABLER)( \
ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
) \
: BOOST_PP_SEQ_FOR_EACH_I_R( \
1, \
BOOST_FUSION_DEFINE_STRUCT_SEQ_CTOR_FILLER_I, \
ATTRIBUTE_TUPEL_SIZE, \
ATTRIBUTES_SEQ) \
{} \
\
BOOST_FUSION_DEFINE_STRUCT_ASSIGN_OP(ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE)
#define BOOST_FUSION_DEFINE_STRUCT_CTOR_1( \
NAME, ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
\
explicit \
NAME(boost::call_traits< \
BOOST_PP_TUPLE_ELEM( \
ATTRIBUTE_TUPEL_SIZE,0,BOOST_PP_SEQ_HEAD(ATTRIBUTES_SEQ)) \
>::param_type arg) \
: BOOST_PP_TUPLE_ELEM( \
ATTRIBUTE_TUPEL_SIZE,1,BOOST_PP_SEQ_HEAD(ATTRIBUTES_SEQ))(arg) \
{}
#define BOOST_FUSION_DEFINE_TPL_STRUCT_CTOR_1( \
TEMPLATE_PARAMS_SEQ, NAME, ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
\
explicit \
NAME(typename boost::call_traits< \
typename boost::fusion::detail::get_first_arg< \
BOOST_PP_TUPLE_ELEM( \
ATTRIBUTE_TUPEL_SIZE, \
0, \
BOOST_PP_SEQ_HEAD(ATTRIBUTES_SEQ)) \
, BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ) \
>::type \
>::param_type arg) \
: BOOST_PP_TUPLE_ELEM( \
ATTRIBUTE_TUPEL_SIZE,1,BOOST_PP_SEQ_HEAD(ATTRIBUTES_SEQ))(arg) \
{}
#define BOOST_FUSION_DEFINE_STRUCT_CTOR_FILLER_I( \
R, ATTRIBUTE_TUPEL_SIZE, I, ATTRIBUTE) \
\
BOOST_PP_COMMA_IF(I) \
BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE,1,ATTRIBUTE)(BOOST_PP_CAT(_,I))
#define BOOST_FUSION_DEFINE_TPL_STRUCT_CTOR_ARG_I(R, DATA, I, ATTRIBUTE) \
\
BOOST_PP_COMMA_IF(I) \
typename boost::call_traits< \
typename boost::fusion::detail::get_first_arg< \
BOOST_PP_TUPLE_ELEM( \
BOOST_PP_TUPLE_ELEM(3,0,DATA), \
0, \
ATTRIBUTE) \
, BOOST_PP_TUPLE_ELEM(3,2,DATA) \
>::type \
>::param_type BOOST_PP_CAT(_,I)
#define BOOST_FUSION_DEFINE_TPL_STRUCT_CTOR_N( \
TEMPLATE_PARAMS_SEQ, NAME, ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
\
NAME(BOOST_PP_SEQ_FOR_EACH_I_R( \
1, \
BOOST_FUSION_DEFINE_TPL_STRUCT_CTOR_ARG_I, \
( \
ATTRIBUTE_TUPEL_SIZE, \
BOOST_PP_SEQ_SIZE(ATTRIBUTES_SEQ), \
BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ) \
), \
ATTRIBUTES_SEQ)) \
: BOOST_PP_SEQ_FOR_EACH_I_R( \
1, \
BOOST_FUSION_DEFINE_STRUCT_CTOR_FILLER_I, \
ATTRIBUTE_TUPEL_SIZE, \
ATTRIBUTES_SEQ) \
{}
#define BOOST_FUSION_DEFINE_STRUCT_CTOR_ARG_I( \
R, ATTRIBUTE_TUPEL_SIZE, I, ATTRIBUTE) \
\
BOOST_PP_COMMA_IF(I) \
boost::call_traits< \
BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE,0,ATTRIBUTE) \
>::param_type BOOST_PP_CAT(_,I)
#define BOOST_FUSION_DEFINE_STRUCT_CTOR_N( \
NAME, ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
\
NAME(BOOST_PP_SEQ_FOR_EACH_I_R( \
1, \
BOOST_FUSION_DEFINE_STRUCT_CTOR_ARG_I, \
ATTRIBUTE_TUPEL_SIZE, \
ATTRIBUTES_SEQ)) \
: BOOST_PP_SEQ_FOR_EACH_I_R( \
1, \
BOOST_FUSION_DEFINE_STRUCT_CTOR_FILLER_I, \
ATTRIBUTE_TUPEL_SIZE, \
ATTRIBUTES_SEQ) \
{}
#define BOOST_FUSION_DEFINE_STRUCT_CTOR(ATTRIBUTES_SEQ) \
BOOST_PP_IF(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(ATTRIBUTES_SEQ)), \
BOOST_FUSION_DEFINE_STRUCT_CTOR_N, \
BOOST_FUSION_DEFINE_STRUCT_CTOR_1)
#define BOOST_FUSION_DEFINE_TPL_STRUCT_CTOR(ATTRIBUTES_SEQ) \
BOOST_PP_IF(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(ATTRIBUTES_SEQ)), \
BOOST_FUSION_DEFINE_TPL_STRUCT_CTOR_N, \
BOOST_FUSION_DEFINE_TPL_STRUCT_CTOR_1)
#define BOOST_FUSION_DEFINE_STRUCT_IMPL( \
NAMESPACE_SEQ, NAME, ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
\
BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DEFINITION_BEGIN(NAMESPACE_SEQ) \
\
struct NAME \
{ \
typedef NAME self_type; \
\
BOOST_FUSION_DEFINE_STRUCT_IMPL_IMPL( \
NAME, ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
\
BOOST_FUSION_DEFINE_STRUCT_CTOR(ATTRIBUTES_SEQ)( \
NAME, ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
}; \
\
BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DEFINITION_END(NAMESPACE_SEQ)
#define BOOST_FUSION_DEFINE_TPL_STRUCT_IMPL( \
TEMPLATE_PARAMS_SEQ, \
NAMESPACE_SEQ, \
NAME, \
ATTRIBUTES_SEQ, \
ATTRIBUTE_TUPEL_SIZE) \
\
BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DEFINITION_BEGIN(NAMESPACE_SEQ) \
\
template< \
BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS_IMPL( \
(0)TEMPLATE_PARAMS_SEQ) \
> \
struct NAME \
{ \
typedef NAME self_type; \
\
BOOST_FUSION_DEFINE_STRUCT_IMPL_IMPL( \
NAME, ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
\
BOOST_FUSION_DEFINE_TPL_STRUCT_CTOR(ATTRIBUTES_SEQ)( \
TEMPLATE_PARAMS_SEQ, NAME, ATTRIBUTES_SEQ, ATTRIBUTE_TUPEL_SIZE) \
}; \
\
BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DEFINITION_END(NAMESPACE_SEQ)
namespace boost { namespace fusion { namespace detail
{
template<typename A1, typename A2>
struct get_first_arg
{
typedef A1 type;
};
}}}
#endif

View File

@ -0,0 +1,51 @@
/*=============================================================================
Copyright (c) 2009-2010 Hartmut Kaiser
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)
==============================================================================*/
#ifndef BOOST_FUSION_ADAPTED_DETAIL_STRUCT_NAMESPACE_HPP
#define BOOST_FUSION_ADAPTED_DETAIL_STRUCT_NAMESPACE_HPP
#include <boost/preprocessor/dec.hpp>
#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/seq/seq.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/tuple/eat.hpp>
#define BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_BEGIN_I(R,DATA,ELEM) \
namespace ELEM {
#define BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_END_I(Z,I,DATA) }
#define BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION_I(Z,I,ELEM) ELEM::
#define BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DEFINITION_BEGIN(NAMESPACE_SEQ) \
BOOST_PP_IF( \
BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(NAMESPACE_SEQ)), \
BOOST_PP_SEQ_FOR_EACH_R, \
BOOST_PP_TUPLE_EAT(4))( \
1, \
BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_BEGIN_I, \
_, \
BOOST_PP_SEQ_TAIL(NAMESPACE_SEQ))
#define BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DEFINITION_END(NAMESPACE_SEQ) \
BOOST_PP_REPEAT_1( \
BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(NAMESPACE_SEQ)), \
BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_END_I, \
_)
#define BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION(NAMESPACE_SEQ) \
BOOST_PP_IF( \
BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(NAMESPACE_SEQ)), \
BOOST_PP_SEQ_FOR_EACH_R, \
BOOST_PP_TUPLE_EAT(4))( \
1, \
BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION_I, \
_, \
BOOST_PP_SEQ_TAIL(NAMESPACE_SEQ))
#endif

View File

@ -6,33 +6,15 @@
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#ifndef BOOST_FUSION_ADAPTED_STRUCT_DETAIL_PROXY_TYPE_HPP
#define BOOST_FUSION_ADAPTED_STRUCT_DETAIL_PROXY_TYPE_HPP
#ifndef BOOST_FUSION_ADAPTED_DETAIL_STRUCT_PROXY_TYPE_HPP
#define BOOST_FUSION_ADAPTED_DETAIL_STRUCT_PROXY_TYPE_HPP
#include <boost/preprocessor/dec.hpp>
#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/seq/seq.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#define BOOST_FUSION_ADAPT_STRUCT_PROXY_DUMMY4(A,B,C,D)
#define BOOST_FUSION_ADAPT_STRUCT_PROXY_TYPE_NS_BEGIN(R,DATA,ELEM) \
namespace ELEM {
#define BOOST_FUSION_ADAPT_STRUCT_PROXY_TYPE_NS_END(Z,I,DATA) }
#define BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION_I(Z,I,ELEM) ELEM::
#include <boost/fusion/adapted/struct/detail/namespace.hpp>
#define BOOST_FUSION_ADAPT_STRUCT_DEFINE_PROXY_TYPE( \
WRAPPED_TYPE,NAMESPACE_SEQ,NAME) \
\
BOOST_PP_IF( \
BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(NAMESPACE_SEQ)), \
BOOST_PP_SEQ_FOR_EACH_R, \
BOOST_FUSION_ADAPT_STRUCT_PROXY_DUMMY4)( \
1, \
BOOST_FUSION_ADAPT_STRUCT_PROXY_TYPE_NS_BEGIN, \
_, \
BOOST_PP_SEQ_TAIL(NAMESPACE_SEQ)) \
BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DEFINITION_BEGIN(NAMESPACE_SEQ) \
\
struct NAME \
{ \
@ -43,19 +25,6 @@
WRAPPED_TYPE& obj; \
}; \
\
BOOST_PP_REPEAT_1( \
BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(NAMESPACE_SEQ)), \
BOOST_FUSION_ADAPT_STRUCT_PROXY_TYPE_NS_END, \
_)
#define BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION(NAMESPACE_SEQ) \
BOOST_PP_IF( \
BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(NAMESPACE_SEQ)), \
BOOST_PP_SEQ_FOR_EACH_R, \
BOOST_FUSION_ADAPT_STRUCT_PROXY_DUMMY4)( \
1, \
BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DECLARATION_I, \
_, \
BOOST_PP_SEQ_TAIL(NAMESPACE_SEQ))
BOOST_FUSION_ADAPT_STRUCT_NAMESPACE_DEFINITION_END(NAMESPACE_SEQ)
#endif

View File

@ -0,0 +1,13 @@
/*=============================================================================
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)
==============================================================================*/
#ifndef BOOST_FUSION_INCLUDE_DEFINE_ASSOC_STRUCT_HPP
#define BOOST_FUSION_INCLUDE_DEFINE_ASSOC_STRUCT_HPP
#include <boost/fusion/adapted/struct/define_assoc_struct.hpp>
#endif

View File

@ -0,0 +1,13 @@
/*=============================================================================
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)
==============================================================================*/
#ifndef BOOST_FUSION_INCLUDE_DEFINE_STRUCT_HPP
#define BOOST_FUSION_INCLUDE_DEFINE_STRUCT_HPP
#include <boost/fusion/adapted/struct/define_struct.hpp>
#endif

View File

@ -120,6 +120,10 @@ import testing ;
[ run sequence/adapt_struct.cpp : : : : ]
[ run sequence/adapt_tpl_class.cpp : : : : ]
[ run sequence/adapt_tpl_struct.cpp : : : : ]
[ run sequence/define_struct.cpp : : : : ]
[ run sequence/define_assoc_struct.cpp : : : : ]
[ run sequence/define_tpl_struct.cpp : : : : ]
[ run sequence/define_assoc_tpl_struct.cpp : : : : ]
[ run functional/fused.cpp : : : : ]
[ run functional/fused_function_object.cpp : : : : ]

View File

@ -0,0 +1,114 @@
/*=============================================================================
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 <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence.hpp>
#include <boost/fusion/container.hpp>
#include <boost/fusion/support.hpp>
#include <boost/fusion/adapted/struct/define_assoc_struct.hpp>
#include <boost/preprocessor/empty.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/static_assert.hpp>
#include <iostream>
namespace ns
{
struct x_member;
struct y_member;
struct z_member;
}
BOOST_FUSION_DEFINE_ASSOC_STRUCT(
(ns),
point,
(int, x, ns::x_member)
(int, 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_NOT((traits::is_view<ns::point>));
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(result_of::size<ns::point>::value == 2);
BOOST_STATIC_ASSERT(!result_of::empty<ns::point>::value);
BOOST_TEST(front(p) == 6);
BOOST_TEST(back(p) == 9);
}
{
vector<int, float> v1(4, 2);
ns::point v2(5, 3);
vector<long, double> 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);
vector<int, short> v(p);
v = p;
}
{
// conversion from ns::point to list
ns::point p(5, 3);
list<int, short> l(p);
l = p;
}
{
// assoc stuff
BOOST_MPL_ASSERT((result_of::has_key<ns::point, ns::x_member>));
BOOST_MPL_ASSERT((result_of::has_key<ns::point, ns::y_member>));
BOOST_MPL_ASSERT((boost::mpl::not_<result_of::has_key<ns::point, ns::z_member> >));
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<ns::point, ns::x_member>::type, int>));
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<ns::point, ns::y_member>::type, int>));
ns::point p(5, 3);
BOOST_TEST(at_key<ns::x_member>(p) == 5);
BOOST_TEST(at_key<ns::y_member>(p) == 3);
}
{
ns::point p = make_list(5,3);
BOOST_TEST(p == make_vector(5,3));
p = make_list(3,5);
BOOST_TEST(p == make_vector(3,5));
}
return boost::report_errors();
}

View File

@ -0,0 +1,118 @@
/*=============================================================================
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 <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence.hpp>
#include <boost/fusion/container.hpp>
#include <boost/fusion/support.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/adapted/struct/define_assoc_struct.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/static_assert.hpp>
#include <iostream>
#include <string>
namespace ns
{
struct x_member;
struct y_member;
struct z_member;
}
BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT(
(X)(Y),
(ns),
point,
(int, x, ns::x_member)
(int, y, ns::y_member)
)
int
main()
{
using namespace boost::fusion;
typedef ns::point<int,int> point;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
{
BOOST_MPL_ASSERT_NOT((traits::is_view<point>));
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(result_of::size<point>::value == 2);
BOOST_STATIC_ASSERT(!result_of::empty<point>::value);
BOOST_TEST(front(p) == 6);
BOOST_TEST(back(p) == 9);
}
{
vector<int, float> v1(4, 2);
point v2(5, 3);
vector<long, double> 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 point to vector
point p(5, 3);
vector<int, short> v(p);
v = p;
}
{
// conversion from point to list
point p(5, 3);
list<int, short> l(p);
l = p;
}
{
// assoc stuff
BOOST_MPL_ASSERT((result_of::has_key<point, ns::x_member>));
BOOST_MPL_ASSERT((result_of::has_key<point, ns::y_member>));
BOOST_MPL_ASSERT((boost::mpl::not_<result_of::has_key<point, ns::z_member> >));
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<point, ns::x_member>::type, int>));
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<point, ns::y_member>::type, int>));
point p(5, 3);
BOOST_TEST(at_key<ns::x_member>(p) == 5);
BOOST_TEST(at_key<ns::y_member>(p) == 3);
}
{
point p = make_list(5,3);
BOOST_TEST(p == make_vector(5,3));
p = make_list(3,5);
BOOST_TEST(p == make_vector(3,5));
}
return boost::report_errors();
}

View File

@ -0,0 +1,105 @@
/*=============================================================================
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 <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence.hpp>
#include <boost/fusion/container.hpp>
#include <boost/fusion/support.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/adapted/struct/define_struct.hpp>
#include <boost/preprocessor/empty.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/static_assert.hpp>
#include <iostream>
#include <string>
BOOST_FUSION_DEFINE_STRUCT(
(ns),
point,
(int, x)
(int, y)
)
BOOST_FUSION_DEFINE_STRUCT(BOOST_PP_EMPTY(), s, (int, m))
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
{
BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point>));
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(result_of::size<ns::point>::value == 2);
BOOST_STATIC_ASSERT(!result_of::empty<ns::point>::value);
BOOST_TEST(front(p) == 6);
BOOST_TEST(back(p) == 9);
}
{
vector<int, float> v1(4, 2);
ns::point v2(5, 3);
vector<long, double> 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);
vector<int, short> v(p);
v = p;
}
{
// conversion from ns::point to list
ns::point p(5, 3);
list<int, short> l(p);
l = p;
}
{ // begin/end
using namespace boost::fusion;
typedef result_of::begin<s>::type b;
typedef result_of::end<s>::type e;
// this fails
BOOST_MPL_ASSERT((boost::is_same<result_of::next<b>::type, e>));
}
{
ns::point p = make_list(5,3);
BOOST_TEST(p == make_vector(5,3));
p = make_list(3,5);
BOOST_TEST(p == make_vector(3,5));
}
return boost::report_errors();
}

View File

@ -0,0 +1,109 @@
/*=============================================================================
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 <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence.hpp>
#include <boost/fusion/container.hpp>
#include <boost/fusion/support.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/adapted/struct/define_struct.hpp>
#include <boost/preprocessor/empty.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/static_assert.hpp>
#include <iostream>
#include <string>
BOOST_FUSION_DEFINE_TPL_STRUCT(
(X)(Y),
(ns),
point,
(X, x)
(Y, y)
)
BOOST_FUSION_DEFINE_TPL_STRUCT((M), BOOST_PP_EMPTY(), s, (M, m))
int
main()
{
using namespace boost::fusion;
typedef ns::point<int, int> point;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
{
BOOST_MPL_ASSERT_NOT((traits::is_view<point>));
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(result_of::size<point>::value == 2);
BOOST_STATIC_ASSERT(!result_of::empty<point>::value);
BOOST_TEST(front(p) == 6);
BOOST_TEST(back(p) == 9);
}
{
vector<int, float> v1(4, 2);
point v2(5, 3);
vector<long, double> 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 point to vector
point p(5, 3);
vector<int, short> v(p);
v = p;
}
{
// conversion from point to list
point p(5, 3);
list<int, short> l(p);
l = p;
}
{ // begin/end
using namespace boost::fusion;
typedef result_of::begin<s<int> >::type b;
typedef result_of::end<s<int> >::type e;
// this fails
BOOST_MPL_ASSERT((boost::is_same<result_of::next<b>::type, e>));
}
{
point p = make_list(5,3);
BOOST_TEST(p == make_vector(5,3));
p = make_list(3,5);
BOOST_TEST(p == make_vector(3,5));
}
return boost::report_errors();
}