Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57796 - branches/release/boost/proto
From: eric_at_[hidden]
Date: 2009-11-19 18:05:20


Author: eric_niebler
Date: 2009-11-19 18:05:20 EST (Thu, 19 Nov 2009)
New Revision: 57796
URL: http://svn.boost.org/trac/boost/changeset/57796

Log:
fix const correctness issues with proto::flatten and friends
Text files modified:
   branches/release/boost/proto/fusion.hpp | 176 ++++++++++++++++++++-------------------
   1 files changed, 90 insertions(+), 86 deletions(-)

Modified: branches/release/boost/proto/fusion.hpp
==============================================================================
--- branches/release/boost/proto/fusion.hpp (original)
+++ branches/release/boost/proto/fusion.hpp 2009-11-19 18:05:20 EST (Thu, 19 Nov 2009)
@@ -9,14 +9,10 @@
 #ifndef BOOST_PROTO_FUSION_HPP_EAN_11_04_2006
 #define BOOST_PROTO_FUSION_HPP_EAN_11_04_2006
 
-#include <boost/proto/detail/prefix.hpp>
 #include <boost/config.hpp>
-#include <boost/version.hpp>
-#include <boost/type_traits/remove_reference.hpp>
 #include <boost/mpl/if.hpp>
 #include <boost/mpl/long.hpp>
 #include <boost/mpl/sequence_tag_fwd.hpp>
-#if BOOST_VERSION >= 103500
 #include <boost/fusion/include/is_view.hpp>
 #include <boost/fusion/include/tag_of_fwd.hpp>
 #include <boost/fusion/include/category_of.hpp>
@@ -30,21 +26,9 @@
 #include <boost/fusion/sequence/intrinsic/ext_/segments.hpp>
 #include <boost/fusion/sequence/intrinsic/ext_/size_s.hpp>
 #include <boost/fusion/view/ext_/segmented_iterator.hpp>
-#else
-#include <boost/spirit/fusion/sequence/is_sequence.hpp>
-#include <boost/spirit/fusion/sequence/begin.hpp>
-#include <boost/spirit/fusion/sequence/end.hpp>
-#include <boost/spirit/fusion/sequence/at.hpp>
-#include <boost/spirit/fusion/sequence/value_at.hpp>
-#include <boost/spirit/fusion/sequence/single_view.hpp>
-#include <boost/spirit/fusion/sequence/transform_view.hpp>
-#include <boost/proto/detail/reverse.hpp>
-#include <boost/proto/detail/pop_front.hpp>
-#endif
 #include <boost/proto/proto_fwd.hpp>
 #include <boost/proto/traits.hpp>
 #include <boost/proto/eval.hpp>
-#include <boost/proto/detail/suffix.hpp>
 
 #if BOOST_MSVC
 #pragma warning(push)
@@ -56,10 +40,6 @@
 namespace boost { namespace proto
 {
 
-/// INTERNAL ONLY
-///
-#define UNREF(x) typename boost::remove_reference<x>::type
-
     namespace detail
     {
 
@@ -70,8 +50,8 @@
             typedef Expr expr_type;
             typedef typename Expr::proto_tag proto_tag;
             BOOST_STATIC_CONSTANT(long, index = Pos);
- BOOST_PROTO_FUSION_DEFINE_CATEGORY(fusion::random_access_traversal_tag)
- BOOST_PROTO_FUSION_DEFINE_TAG(tag::proto_expr_iterator)
+ typedef fusion::random_access_traversal_tag category;
+ typedef tag::proto_expr_iterator fusion_tag;
 
             expr_iterator(Expr const &e)
               : expr(e)
@@ -85,8 +65,8 @@
         {
             typedef Expr expr_type;
             typedef typename Expr::proto_tag proto_tag;
- BOOST_PROTO_FUSION_DEFINE_CATEGORY(fusion::forward_traversal_tag)
- BOOST_PROTO_FUSION_DEFINE_TAG(tag::proto_flat_view)
+ typedef fusion::forward_traversal_tag category;
+ typedef tag::proto_flat_view fusion_tag;
 
             explicit flat_view(Expr &e)
               : expr_(e)
@@ -103,15 +83,27 @@
 
             template<typename This, typename Expr>
             struct result<This(Expr)>
+ : result<This(Expr const &)>
+ {};
+
+ template<typename This, typename Expr>
+ struct result<This(Expr &)>
               : mpl::if_c<
- is_same<Tag, UNREF(Expr)::proto_tag>::value
- , flat_view<UNREF(Expr) const>
- , fusion::single_view<UNREF(Expr) const &>
+ is_same<Tag, typename Expr::proto_tag>::value
+ , flat_view<Expr>
+ , fusion::single_view<Expr &>
>
             {};
 
             template<typename Expr>
- typename result<as_element(Expr const &)>::type
+ typename result<as_element(Expr &)>::type const
+ operator ()(Expr &e) const
+ {
+ return typename result<as_element(Expr &)>::type(e);
+ }
+
+ template<typename Expr>
+ typename result<as_element(Expr const &)>::type const
             operator ()(Expr const &e) const
             {
                 return typename result<as_element(Expr const &)>::type(e);
@@ -123,14 +115,13 @@
     {
         template<typename Expr>
         struct flatten
- {
- typedef detail::flat_view<Expr const> type;
- };
+ : flatten<Expr const &>
+ {};
 
         template<typename Expr>
         struct flatten<Expr &>
         {
- typedef detail::flat_view<Expr const> type;
+ typedef detail::flat_view<Expr> type;
         };
     }
 
@@ -157,12 +148,24 @@
 
             template<typename This, typename Expr>
             struct result<This(Expr)>
+ : result<This(Expr const &)>
+ {};
+
+ template<typename This, typename Expr>
+ struct result<This(Expr &)>
             {
- typedef proto::detail::flat_view<UNREF(Expr) const> type;
+ typedef proto::detail::flat_view<Expr> type;
             };
 
             template<typename Expr>
- proto::detail::flat_view<Expr const>
+ proto::detail::flat_view<Expr> const
+ operator ()(Expr &e) const
+ {
+ return proto::detail::flat_view<Expr>(e);
+ }
+
+ template<typename Expr>
+ proto::detail::flat_view<Expr const> const
             operator ()(Expr const &e) const
             {
                 return proto::detail::flat_view<Expr const>(e);
@@ -188,14 +191,23 @@
 
             template<typename This, typename Expr>
             struct result<This(Expr)>
+ : result<This(Expr const &)>
+ {};
+
+ template<typename This, typename Expr>
+ struct result<This(Expr &)>
+ : fusion::result_of::pop_front<Expr>
+ {};
+
+ template<typename Expr>
+ typename fusion::result_of::pop_front<Expr>::type
+ operator ()(Expr &e) const
             {
- typedef
- typename fusion::BOOST_PROTO_FUSION_RESULT_OF::pop_front<UNREF(Expr) const>::type
- type;
- };
+ return fusion::pop_front(e);
+ }
 
             template<typename Expr>
- typename fusion::BOOST_PROTO_FUSION_RESULT_OF::pop_front<Expr const>::type
+ typename fusion::result_of::pop_front<Expr const>::type
             operator ()(Expr const &e) const
             {
                 return fusion::pop_front(e);
@@ -219,14 +231,23 @@
 
             template<typename This, typename Expr>
             struct result<This(Expr)>
+ : result<This(Expr const &)>
+ {};
+
+ template<typename This, typename Expr>
+ struct result<This(Expr &)>
+ : fusion::result_of::reverse<Expr>
+ {};
+
+ template<typename Expr>
+ typename fusion::result_of::reverse<Expr>::type
+ operator ()(Expr &e) const
             {
- typedef
- typename fusion::BOOST_PROTO_FUSION_RESULT_OF::reverse<UNREF(Expr) const>::type
- type;
- };
+ return fusion::reverse(e);
+ }
 
             template<typename Expr>
- typename fusion::BOOST_PROTO_FUSION_RESULT_OF::reverse<Expr const>::type
+ typename fusion::result_of::reverse<Expr const>::type
             operator ()(Expr const &e) const
             {
                 return fusion::reverse(e);
@@ -246,7 +267,16 @@
     /// [a, b, c], even though the tree is grouped as
     /// <tt>((a | b) | c)</tt>.
     template<typename Expr>
- proto::detail::flat_view<Expr const>
+ proto::detail::flat_view<Expr> const
+ flatten(Expr &e)
+ {
+ return proto::detail::flat_view<Expr>(e);
+ }
+
+ /// \overload
+ ///
+ template<typename Expr>
+ proto::detail::flat_view<Expr const> const
     flatten(Expr const &e)
     {
         return proto::detail::flat_view<Expr const>(e);
@@ -287,11 +317,13 @@
 
         template<typename This, typename Expr>
         struct result<This(Expr)>
- {
- typedef
- typename proto::result_of::eval<UNREF(Expr), Context>::type
- type;
- };
+ : result<This(Expr const &)>
+ {};
+
+ template<typename This, typename Expr>
+ struct result<This(Expr &)>
+ : proto::result_of::eval<Expr, Context>
+ {};
 
         template<typename Expr>
         typename proto::result_of::eval<Expr, Context>::type
@@ -300,31 +332,21 @@
             return proto::eval(e, this->ctx_);
         }
 
+ template<typename Expr>
+ typename proto::result_of::eval<Expr const, Context>::type
+ operator ()(Expr const &e) const
+ {
+ return proto::eval(e, this->ctx_);
+ }
+
     private:
         Context &ctx_;
     };
 }}
 
-// Don't bother emitting all this into the Doxygen-generated
-// reference section. It's enough to say that Proto expressions
-// are valid Fusion sequence without showing all this gunk.
-#ifndef BOOST_PROTO_BUILDING_DOCS
-
 namespace boost { namespace fusion
 {
- #if BOOST_VERSION < 103500
- template<typename Tag, typename Args, long Arity>
- struct is_sequence<proto::expr<Tag, Args, Arity> >
- : mpl::true_
- {};
-
- template<typename Tag, typename Args, long Arity>
- struct is_sequence<proto::expr<Tag, Args, Arity> const>
- : mpl::true_
- {};
- #endif
-
- namespace BOOST_PROTO_FUSION_EXTENSION
+ namespace extension
     {
 
         template<typename Tag>
@@ -379,16 +401,6 @@
             };
         };
 
- #if BOOST_VERSION < 103500
- template<typename Tag>
- struct value_impl;
-
- template<>
- struct value_impl<proto::tag::proto_expr_iterator>
- : value_of_impl<proto::tag::proto_expr_iterator>
- {};
- #endif
-
         template<typename Tag>
         struct deref_impl;
 
@@ -489,7 +501,6 @@
             {};
         };
 
- #if BOOST_VERSION >= 103500
         template<typename Tag>
         struct category_of_impl;
 
@@ -502,7 +513,6 @@
                 typedef random_access_traversal_tag type;
             };
         };
- #endif
 
         template<typename Tag>
         struct size_impl;
@@ -631,7 +641,6 @@
             };
         };
 
- #if BOOST_VERSION >= 103500
         template<typename Tag>
         struct is_segmented_impl;
 
@@ -703,7 +712,6 @@
               : fusion::segmented_size<Sequence>
             {};
         };
- #endif
 
     }
 
@@ -718,10 +726,6 @@
     };
 }}
 
-#endif // BOOST_PROTO_BUILDING_DOCS
-
-#undef UNREF
-
 #if BOOST_MSVC
 #pragma warning(pop)
 #endif


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