[SVN r79958]
This commit is contained in:
Joel de Guzman
2012-08-11 02:36:08 +00:00
parent 5a51e5d9aa
commit 9cceb79cf8
9 changed files with 182 additions and 120 deletions

View File

@ -658,7 +658,7 @@ __random_access_sequence__.
[heading Synopsis] [heading Synopsis]
BOOST_FUSION_ADAPT_ADT( BOOST_FUSION_ADAPT_TPL_ADT(
(template_param0)(template_param1)..., (template_param0)(template_param1)...,
(type_name) (specialization_param0)(specialization_param1)..., (type_name) (specialization_param0)(specialization_param1)...,
(attribute_type0, attribute_const_type0, get_expr0, set_expr0) (attribute_type0, attribute_const_type0, get_expr0, set_expr0)
@ -1115,6 +1115,100 @@ defined in __random_access_sequence__.
[endsect] [endsect]
[section:define_struct_inline BOOST_FUSION_DEFINE_STRUCT_INLINE]
[heading Description]
BOOST_FUSION_DEFINE_STRUCT_INLINE is a macro that can be used to generate all
the necessary boilerplate to define and adapt an arbitrary struct as a model of
__random_access_sequence__. Unlike BOOST_FUSION_DEFINE_STRUCT, it can be used
at class or namespace scope.
[heading Synopsis]
BOOST_FUSION_DEFINE_STRUCT_INLINE(
struct_name,
(member_type0, member_name0)
(member_type1, member_name1)
...
)
[heading Expression Semantics]
The semantics of BOOST_FUSION_DEFINE_STRUCT_INLINE are identical to those of
BOOST_FUSION_DEFINE_STRUCT, with two differences:
# BOOST_FUSION_DEFINE_STRUCT_INLINE can be used at class or namespace scope, and
thus does not take a namespace list parameter.
# The structure generated by BOOST_FUSION_DEFINE_STRUCT_INLINE has a base class,
and is thus not POD in C++03.
[heading Header]
#include <boost/fusion/adapted/struct/define_struct_inline.hpp>
#include <boost/fusion/include/define_struct_inline.hpp>
[heading Example]
// enclosing::employee is a Fusion sequence
class enclosing
{
BOOST_FUSION_DEFINE_STRUCT_INLINE(
employee,
(std::string, name)
(int, age))
};
[endsect]
[section:define_tpl_struct_inline BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE]
[heading Description]
BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE is a macro that can be used to generate
all the necessary boilerplate to define and adapt an arbitrary template struct
as a model of __random_access_sequence__. Unlike BOOST_FUSION_DEFINE_TPL_STRUCT,
it can be used at class or namespace scope.
[heading Synopsis]
BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE(
(template_param0)(template_param1)...,
struct_name,
(member_type0, member_name0)
(member_type1, member_name1)
...
)
[heading Expression Semantics]
The semantics of BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE are identical to those of
BOOST_FUSION_DEFINE_TPL_STRUCT, with two differences:
# BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE can be used at class or namespace scope,
and thus does not take a namespace list parameter.
# The structure generated by BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE has a base
class, and is thus not POD in C++03.
[heading Header]
#include <boost/fusion/adapted/struct/define_struct_inline.hpp>
#include <boost/fusion/include/define_struct_inline.hpp>
[heading Example]
// Any instantiated enclosing::employee is a Fusion sequence
class enclosing
{
BOOST_FUSION_DEFINE_TPL_STRUCT(
(Name)(Age), employee,
(Name, name)
(Age, age))
};
[endsect]
[section:define_assoc_struct BOOST_FUSION_DEFINE_ASSOC_STRUCT] [section:define_assoc_struct BOOST_FUSION_DEFINE_ASSOC_STRUCT]
[heading Description] [heading Description]

View File

@ -29,6 +29,27 @@
#define BOOST_FUSION_MAKE_DEFAULT_INIT_LIST_ENTRY(R, DATA, N, ATTRIBUTE) \ #define BOOST_FUSION_MAKE_DEFAULT_INIT_LIST_ENTRY(R, DATA, N, ATTRIBUTE) \
BOOST_PP_COMMA_IF(N) BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE)() BOOST_PP_COMMA_IF(N) BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE)()
#define BOOST_FUSION_MAKE_DEFAULT_INIT_LIST(ATTRIBUTES_SEQ) \
: BOOST_PP_SEQ_FOR_EACH_I( \
BOOST_FUSION_MAKE_DEFAULT_INIT_LIST_ENTRY, \
~, \
ATTRIBUTES_SEQ) \
#define BOOST_FUSION_IGNORE_1(ARG1)
#define BOOST_FUSION_IGNORE_2(ARG1, ARG2)
#define BOOST_FUSION_MAKE_COPY_CONSTRUCTOR(NAME, ATTRIBUTES_SEQ) \
NAME(BOOST_PP_SEQ_FOR_EACH_I( \
BOOST_FUSION_MAKE_CONST_REF_PARAM, \
~, \
ATTRIBUTES_SEQ)) \
: BOOST_PP_SEQ_FOR_EACH_I( \
BOOST_FUSION_MAKE_INIT_LIST_ENTRY, \
~, \
ATTRIBUTES_SEQ) \
{ \
} \
#define BOOST_FUSION_MAKE_CONST_REF_PARAM(R, DATA, N, ATTRIBUTE) \ #define BOOST_FUSION_MAKE_CONST_REF_PARAM(R, DATA, N, ATTRIBUTE) \
BOOST_PP_COMMA_IF(N) \ BOOST_PP_COMMA_IF(N) \
BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE) const& \ BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE) const& \
@ -162,23 +183,19 @@
NAME, ATTRIBUTES_SEQ, ATTRIBUTES_SEQ_SIZE) \ NAME, ATTRIBUTES_SEQ, ATTRIBUTES_SEQ_SIZE) \
\ \
NAME() \ NAME() \
: BOOST_PP_SEQ_FOR_EACH_I( \ BOOST_PP_IF( \
BOOST_FUSION_MAKE_DEFAULT_INIT_LIST_ENTRY, \ BOOST_PP_SEQ_SIZE(ATTRIBUTES_SEQ), \
~, \ BOOST_FUSION_MAKE_DEFAULT_INIT_LIST, \
ATTRIBUTES_SEQ) \ BOOST_FUSION_IGNORE_1) \
(ATTRIBUTES_SEQ) \
{ \ { \
} \ } \
\ \
NAME(BOOST_PP_SEQ_FOR_EACH_I( \ BOOST_PP_IF( \
BOOST_FUSION_MAKE_CONST_REF_PARAM, \ BOOST_PP_SEQ_SIZE(ATTRIBUTES_SEQ), \
~, \ BOOST_FUSION_MAKE_COPY_CONSTRUCTOR, \
ATTRIBUTES_SEQ)) \ BOOST_FUSION_IGNORE_2) \
: BOOST_PP_SEQ_FOR_EACH_I( \ (NAME, ATTRIBUTES_SEQ) \
BOOST_FUSION_MAKE_INIT_LIST_ENTRY, \
~, \
ATTRIBUTES_SEQ) \
{ \
} \
\ \
template <typename boost_fusion_uglified_Seq> \ template <typename boost_fusion_uglified_Seq> \
NAME(const boost_fusion_uglified_Seq& rhs) \ NAME(const boost_fusion_uglified_Seq& rhs) \

View File

@ -1,102 +0,0 @@
/*=============================================================================
Copyright (c) 2005-2011 Joel de Guzman
Copyright (c) 2005-2006 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)
==============================================================================*/
#if !defined(BOOST_FUSION_DEQUE_DETAIL_DEQUE_KEYED_VALUES_26112006_1330)
#define BOOST_FUSION_DEQUE_DETAIL_DEQUE_KEYED_VALUES_26112006_1330
#include <boost/fusion/container/deque/limits.hpp>
#include <boost/fusion/container/deque/detail/keyed_element.hpp>
#include <boost/preprocessor/iterate.hpp>
#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/print.hpp>
#define FUSION_VOID(z, n, _) void_
namespace boost { namespace fusion
{
struct void_;
}}
#if !defined(BOOST_FUSION_DONT_USE_PREPROCESSED_FILES)
#include <boost/fusion/container/deque/detail/preprocessed/deque_keyed_values.hpp>
#else
#if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(preserve: 2, line: 0, output: "preprocessed/deque_keyed_values" FUSION_MAX_DEQUE_SIZE_STR ".hpp")
#endif
/*=============================================================================
Copyright (c) 2001-2011 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)
This is an auto-generated file. Do not edit!
==============================================================================*/
#if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(preserve: 1)
#endif
namespace boost { namespace fusion { namespace detail
{
template<typename Key, typename Value, typename Rest>
struct keyed_element;
struct nil_keyed_element;
template<typename N, BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(FUSION_MAX_DEQUE_SIZE, typename T, void_)>
struct deque_keyed_values_impl;
template<typename N>
struct deque_keyed_values_impl<N, BOOST_PP_ENUM(FUSION_MAX_DEQUE_SIZE, FUSION_VOID, _)>
{
typedef nil_keyed_element type;
static type call()
{
return type();
}
};
template<typename N, BOOST_PP_ENUM_PARAMS(FUSION_MAX_DEQUE_SIZE, typename T)>
struct deque_keyed_values_impl
{
typedef mpl::int_<mpl::plus<N, mpl::int_<1> >::value> next_index;
typedef typename deque_keyed_values_impl<
next_index,
BOOST_PP_ENUM_SHIFTED_PARAMS(FUSION_MAX_DEQUE_SIZE, T)>::type tail;
typedef keyed_element<N, T0, tail> type;
#include <boost/fusion/container/deque/detail/deque_keyed_values_call.hpp>
};
template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(FUSION_MAX_DEQUE_SIZE, typename T, void_)>
struct deque_keyed_values
: deque_keyed_values_impl<mpl::int_<0>, BOOST_PP_ENUM_PARAMS(FUSION_MAX_DEQUE_SIZE, T)>
{};
}}}
#if defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(output: null)
#endif
#endif // BOOST_FUSION_DONT_USE_PREPROCESSED_FILES
#undef FUSION_VOID
#endif

View File

@ -18,4 +18,4 @@
#include <boost/fusion/tuple/detail/preprocessed/make_tuple50.hpp> #include <boost/fusion/tuple/detail/preprocessed/make_tuple50.hpp>
#else #else
#error "FUSION_MAX_VECTOR_SIZE out of bounds for preprocessed headers" #error "FUSION_MAX_VECTOR_SIZE out of bounds for preprocessed headers"
#endif #endif

View File

@ -18,4 +18,4 @@
#include <boost/fusion/tuple/detail/preprocessed/tuple50_fwd.hpp> #include <boost/fusion/tuple/detail/preprocessed/tuple50_fwd.hpp>
#else #else
#error "FUSION_MAX_VECTOR_SIZE out of bounds for preprocessed headers" #error "FUSION_MAX_VECTOR_SIZE out of bounds for preprocessed headers"
#endif #endif

View File

@ -18,4 +18,4 @@
#include <boost/fusion/tuple/detail/preprocessed/tuple_tie50.hpp> #include <boost/fusion/tuple/detail/preprocessed/tuple_tie50.hpp>
#else #else
#error "FUSION_MAX_VECTOR_SIZE out of bounds for preprocessed headers" #error "FUSION_MAX_VECTOR_SIZE out of bounds for preprocessed headers"
#endif #endif

View File

@ -71,6 +71,24 @@ namespace ns
int y; int y;
}; };
#endif #endif
// A sequence that has data members defined in an unrelated namespace
// (std, in this case). This allows testing ADL issues.
class name
{
public:
name() {}
name(const std::string& last, const std::string& first)
: last(last), first(first) {}
const std::string& get_last() const { return last; }
const std::string& get_first() const { return first; }
void set_last(const std::string& last_) { last = last_; }
void set_first(const std::string& first_) { first = first_; }
private:
std::string last;
std::string first;
};
} }
BOOST_FUSION_ADAPT_ADT( BOOST_FUSION_ADAPT_ADT(
@ -87,6 +105,12 @@ BOOST_FUSION_ADAPT_ADT(
) )
#endif #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 int
main() main()
{ {
@ -131,6 +155,20 @@ main()
BOOST_TEST(v3 >= v2); BOOST_TEST(v3 >= v2);
} }
{
fusion::vector<std::string, std::string> v1("Lincoln", "Abraham");
ns::name v2("Roosevelt", "Franklin");
ns::name v3("Roosevelt", "Theodore");
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 // conversion from ns::point to vector
ns::point p(5, 3); ns::point p(5, 3);

View File

@ -67,6 +67,7 @@ main()
using namespace boost::fusion; using namespace boost::fusion;
typedef ns::point<int, int> point; typedef ns::point<int, int> point;
typedef ns::point<std::string, std::string> name;
std::cout << tuple_open('['); std::cout << tuple_open('[');
std::cout << tuple_close(']'); std::cout << tuple_close(']');
@ -106,6 +107,20 @@ main()
BOOST_TEST(v3 >= v2); BOOST_TEST(v3 >= v2);
} }
{
boost::fusion::vector<std::string, std::string> v1("Lincoln", "Abraham");
name v2("Roosevelt", "Franklin");
name v3("Roosevelt", "Theodore");
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 // conversion from point to vector
point p(5, 3); point p(5, 3);