Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64490 - in trunk: boost/fusion/adapted/class/detail boost/fusion/adapted/struct/detail libs/fusion/test/sequence
From: mr.chr.schmidt_at_[hidden]
Date: 2010-07-30 20:17:38


Author: cschmidt
Date: 2010-07-30 20:17:34 EDT (Fri, 30 Jul 2010)
New Revision: 64490
URL: http://svn.boost.org/trac/boost/changeset/64490

Log:
refactored extension::struct_member to extension::access::struct_member
Text files modified:
   trunk/boost/fusion/adapted/class/detail/adapt_base.hpp | 11 ++++++--
   trunk/boost/fusion/adapted/class/detail/extension.hpp | 21 ++++------------
   trunk/boost/fusion/adapted/struct/detail/adapt_base.hpp | 38 ++++++++++++++++++++++++------
   trunk/boost/fusion/adapted/struct/detail/at_impl.hpp | 2
   trunk/boost/fusion/adapted/struct/detail/deref_impl.hpp | 2
   trunk/boost/fusion/adapted/struct/detail/extension.hpp | 10 ++++++-
   trunk/boost/fusion/adapted/struct/detail/value_at_impl.hpp | 2
   trunk/boost/fusion/adapted/struct/detail/value_of_impl.hpp | 2
   trunk/libs/fusion/test/sequence/adapt_class.cpp | 50 ++++++++++++++++++++++++++++++++++++++++
   trunk/libs/fusion/test/sequence/adapt_struct.cpp | 36 ++++++++++++++++++++++++++++
   10 files changed, 141 insertions(+), 33 deletions(-)

Modified: trunk/boost/fusion/adapted/class/detail/adapt_base.hpp
==============================================================================
--- trunk/boost/fusion/adapted/class/detail/adapt_base.hpp (original)
+++ trunk/boost/fusion/adapted/class/detail/adapt_base.hpp 2010-07-30 20:17:34 EDT (Fri, 30 Jul 2010)
@@ -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 \
> \

Modified: trunk/boost/fusion/adapted/class/detail/extension.hpp
==============================================================================
--- trunk/boost/fusion/adapted/class/detail/extension.hpp (original)
+++ trunk/boost/fusion/adapted/class/detail/extension.hpp 2010-07-30 20:17:34 EDT (Fri, 30 Jul 2010)
@@ -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;
- }
-}}
+ template <typename T, typename Dummy>
+ struct get_identity
+ : remove_const<typename remove_reference<T>::type>
+ {};
+}}}
 
 #endif

Modified: trunk/boost/fusion/adapted/struct/detail/adapt_base.hpp
==============================================================================
--- trunk/boost/fusion/adapted/struct/detail/adapt_base.hpp (original)
+++ trunk/boost/fusion/adapted/struct/detail/adapt_base.hpp 2010-07-30 20:17:34 EDT (Fri, 30 Jul 2010)
@@ -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; \

Modified: trunk/boost/fusion/adapted/struct/detail/at_impl.hpp
==============================================================================
--- trunk/boost/fusion/adapted/struct/detail/at_impl.hpp (original)
+++ trunk/boost/fusion/adapted/struct/detail/at_impl.hpp 2010-07-30 20:17:34 EDT (Fri, 30 Jul 2010)
@@ -22,7 +22,7 @@
     {
         template <typename Seq, typename N>
         struct apply
- : extension::struct_member<
+ : access::struct_member<
                 typename remove_const<Seq>::type
               , N::value
>::template apply<Seq>

Modified: trunk/boost/fusion/adapted/struct/detail/deref_impl.hpp
==============================================================================
--- trunk/boost/fusion/adapted/struct/detail/deref_impl.hpp (original)
+++ trunk/boost/fusion/adapted/struct/detail/deref_impl.hpp 2010-07-30 20:17:34 EDT (Fri, 30 Jul 2010)
@@ -20,7 +20,7 @@
         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>

Modified: trunk/boost/fusion/adapted/struct/detail/extension.hpp
==============================================================================
--- trunk/boost/fusion/adapted/struct/detail/extension.hpp (original)
+++ trunk/boost/fusion/adapted/struct/detail/extension.hpp 2010-07-30 20:17:34 EDT (Fri, 30 Jul 2010)
@@ -27,8 +27,14 @@
     {
         struct no_such_member;
 
- template<typename Seq, int N>
- struct struct_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;

Modified: trunk/boost/fusion/adapted/struct/detail/value_at_impl.hpp
==============================================================================
--- trunk/boost/fusion/adapted/struct/detail/value_at_impl.hpp (original)
+++ trunk/boost/fusion/adapted/struct/detail/value_at_impl.hpp 2010-07-30 20:17:34 EDT (Fri, 30 Jul 2010)
@@ -20,7 +20,7 @@
     {
         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>
         {};
     };
 

Modified: trunk/boost/fusion/adapted/struct/detail/value_of_impl.hpp
==============================================================================
--- trunk/boost/fusion/adapted/struct/detail/value_of_impl.hpp (original)
+++ trunk/boost/fusion/adapted/struct/detail/value_of_impl.hpp 2010-07-30 20:17:34 EDT (Fri, 30 Jul 2010)
@@ -18,7 +18,7 @@
     {
         template <typename It>
         struct apply
- : extension::struct_member<
+ : access::struct_member<
                 typename remove_const<typename It::seq_type>::type
               , It::index::value
>

Modified: trunk/libs/fusion/test/sequence/adapt_class.cpp
==============================================================================
--- trunk/libs/fusion/test/sequence/adapt_class.cpp (original)
+++ trunk/libs/fusion/test/sequence/adapt_class.cpp 2010-07-30 20:17:34 EDT (Fri, 30 Jul 2010)
@@ -50,6 +50,26 @@
         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 @@
     (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 @@
           , 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();
 }
 

Modified: trunk/libs/fusion/test/sequence/adapt_struct.cpp
==============================================================================
--- trunk/libs/fusion/test/sequence/adapt_struct.cpp (original)
+++ trunk/libs/fusion/test/sequence/adapt_struct.cpp 2010-07-30 20:17:34 EDT (Fri, 30 Jul 2010)
@@ -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 @@
         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 @@
     (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 @@
         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 @@
           , 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();
 }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk