mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-16 05:42:20 +02:00
refactored extension::struct_member to extension::access::struct_member
[SVN r64490]
This commit is contained in:
@ -37,7 +37,7 @@
|
||||
template< \
|
||||
BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \
|
||||
> \
|
||||
struct class_member_proxy< \
|
||||
struct access::class_member_proxy< \
|
||||
BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \
|
||||
, I \
|
||||
> \
|
||||
@ -71,9 +71,14 @@
|
||||
template< \
|
||||
BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \
|
||||
> \
|
||||
struct struct_member<BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ), I> \
|
||||
struct access::struct_member< \
|
||||
BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \
|
||||
, I \
|
||||
> \
|
||||
{ \
|
||||
typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) lvalue; \
|
||||
BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \
|
||||
TEMPLATE_PARAMS_SEQ) \
|
||||
\
|
||||
typedef \
|
||||
BOOST_PP_IF( \
|
||||
@ -87,7 +92,7 @@
|
||||
struct apply \
|
||||
{ \
|
||||
typedef \
|
||||
class_member_proxy< \
|
||||
access::class_member_proxy< \
|
||||
BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \
|
||||
, I \
|
||||
> \
|
||||
|
@ -13,21 +13,12 @@
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
namespace boost { namespace fusion { namespace detail
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template <typename T, typename Dummy>
|
||||
struct get_identity
|
||||
: remove_const<typename remove_reference<T>::type>
|
||||
{};
|
||||
}
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template <typename T, int N>
|
||||
struct class_member_proxy;
|
||||
}
|
||||
}}
|
||||
}}}
|
||||
|
||||
#endif
|
||||
|
@ -87,15 +87,41 @@
|
||||
I, \
|
||||
ATTRIBUTE)
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# define BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAM(R,_,ELEM) \
|
||||
typedef ELEM ELEM;
|
||||
# define BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS_IMPL(SEQ) \
|
||||
BOOST_PP_SEQ_FOR_EACH( \
|
||||
BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAM, \
|
||||
_, \
|
||||
BOOST_PP_SEQ_TAIL(SEQ))
|
||||
# define BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS(SEQ) \
|
||||
BOOST_PP_IF( \
|
||||
BOOST_PP_SEQ_HEAD(SEQ), \
|
||||
BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS_IMPL, \
|
||||
BOOST_PP_TUPLE_EAT(1))(SEQ)
|
||||
#else
|
||||
# define BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS(SEQ)
|
||||
#endif
|
||||
|
||||
#define BOOST_FUSION_ADAPT_STRUCT_C_BASE( \
|
||||
TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,PREFIX,ATTRIBUTE,ATTRIBUTE_TUPEL_SIZE) \
|
||||
\
|
||||
template< \
|
||||
BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \
|
||||
> \
|
||||
struct struct_member<BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ), I> \
|
||||
struct access::struct_member< \
|
||||
BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \
|
||||
, I \
|
||||
> \
|
||||
{ \
|
||||
typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) type; \
|
||||
typedef \
|
||||
BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) \
|
||||
attribute_type; \
|
||||
BOOST_FUSION_ADAPT_STRUCT_MSVC_REDEFINE_TEMPLATE_PARAMS( \
|
||||
TEMPLATE_PARAMS_SEQ) \
|
||||
\
|
||||
typedef attribute_type type; \
|
||||
\
|
||||
template<typename Seq> \
|
||||
struct apply \
|
||||
@ -104,12 +130,8 @@
|
||||
add_reference< \
|
||||
typename mpl::eval_if< \
|
||||
is_const<Seq> \
|
||||
, add_const<BOOST_PP_TUPLE_ELEM( \
|
||||
ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) \
|
||||
> \
|
||||
, mpl::identity<BOOST_PP_TUPLE_ELEM( \
|
||||
ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) \
|
||||
> \
|
||||
, add_const<attribute_type> \
|
||||
, mpl::identity<attribute_type> \
|
||||
>::type \
|
||||
>::type \
|
||||
type; \
|
||||
|
@ -22,7 +22,7 @@ namespace boost { namespace fusion { namespace extension
|
||||
{
|
||||
template <typename Seq, typename N>
|
||||
struct apply
|
||||
: extension::struct_member<
|
||||
: access::struct_member<
|
||||
typename remove_const<Seq>::type
|
||||
, N::value
|
||||
>::template apply<Seq>
|
||||
|
@ -20,7 +20,7 @@ namespace boost { namespace fusion { namespace extension
|
||||
struct apply
|
||||
{
|
||||
typedef typename
|
||||
extension::struct_member<
|
||||
access::struct_member<
|
||||
typename remove_const<typename It::seq_type>::type
|
||||
, It::index::value
|
||||
>::template apply<typename It::seq_type>
|
||||
|
@ -27,9 +27,15 @@ namespace boost { namespace fusion
|
||||
{
|
||||
struct no_such_member;
|
||||
|
||||
struct access
|
||||
{
|
||||
template<typename Seq, int N>
|
||||
struct struct_member;
|
||||
|
||||
template <typename T, int N>
|
||||
struct class_member_proxy;
|
||||
};
|
||||
|
||||
template<typename Seq, int N>
|
||||
struct struct_member_name;
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace boost { namespace fusion { namespace extension
|
||||
{
|
||||
template <typename Seq, typename N>
|
||||
struct apply
|
||||
: struct_member<typename remove_const<Seq>::type, N::value>
|
||||
: access::struct_member<typename remove_const<Seq>::type, N::value>
|
||||
{};
|
||||
};
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace boost { namespace fusion { namespace extension
|
||||
{
|
||||
template <typename It>
|
||||
struct apply
|
||||
: extension::struct_member<
|
||||
: access::struct_member<
|
||||
typename remove_const<typename It::seq_type>::type
|
||||
, It::index::value
|
||||
>
|
||||
|
@ -50,6 +50,26 @@ namespace ns
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
#if !BOOST_WORKAROUND(__GNUC__,<4)
|
||||
class point_with_private_members
|
||||
{
|
||||
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:
|
||||
int get_x() const { return x; }
|
||||
int get_y() const { return y; }
|
||||
void set_x(int x_) { x = x_; }
|
||||
void set_y(int y_) { y = y_; }
|
||||
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOST_FUSION_ADAPT_CLASS(
|
||||
@ -58,6 +78,14 @@ BOOST_FUSION_ADAPT_CLASS(
|
||||
(int, int, obj.get_y(), obj.set_y(val))
|
||||
)
|
||||
|
||||
#if !BOOST_WORKAROUND(__GNUC__,<4)
|
||||
BOOST_FUSION_ADAPT_CLASS(
|
||||
ns::point_with_private_members,
|
||||
(int, int, obj.get_x(), obj.set_x(val))
|
||||
(int, int, obj.get_y(), obj.set_y(val))
|
||||
)
|
||||
#endif
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
@ -124,6 +152,28 @@ main()
|
||||
, mpl::front<ns::point>::type>));
|
||||
}
|
||||
|
||||
#if !BOOST_WORKAROUND(__GNUC__,<4)
|
||||
{
|
||||
BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point_with_private_members>));
|
||||
ns::point_with_private_members 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_with_private_members>::value == 2);
|
||||
BOOST_STATIC_ASSERT(!result_of::empty<ns::point_with_private_members>::value);
|
||||
|
||||
BOOST_TEST(front(p) == 6);
|
||||
BOOST_TEST(back(p) == 9);
|
||||
}
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <boost/mpl/front.hpp>
|
||||
#include <boost/mpl/is_sequence.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
@ -38,6 +39,21 @@ namespace ns
|
||||
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_ADAPT_STRUCT(
|
||||
@ -46,6 +62,14 @@ BOOST_FUSION_ADAPT_STRUCT(
|
||||
(int, y)
|
||||
)
|
||||
|
||||
#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))
|
||||
|
||||
@ -118,7 +142,6 @@ main()
|
||||
BOOST_MPL_ASSERT((is_same<result_of::next<b>::type, e>));
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
BOOST_MPL_ASSERT((mpl::is_sequence<ns::point>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<
|
||||
@ -126,6 +149,17 @@ main()
|
||||
, mpl::front<ns::point>::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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user