Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79711 - in trunk/boost/proto: . detail transform
From: eric_at_[hidden]
Date: 2012-07-23 21:53:11


Author: eric_niebler
Date: 2012-07-23 21:53:10 EDT (Mon, 23 Jul 2012)
New Revision: 79711
URL: http://svn.boost.org/trac/boost/changeset/79711

Log:
move transform environment-related classes into ADL-blocking namespaces
Text files modified:
   trunk/boost/proto/detail/poly_function.hpp | 4
   trunk/boost/proto/proto_fwd.hpp | 36 ++++-
   trunk/boost/proto/transform/env.hpp | 210 ++++++++++++++++++++-------------------
   trunk/boost/proto/transform/impl.hpp | 65 ++++++-----
   trunk/boost/proto/transform/when.hpp | 7
   5 files changed, 176 insertions(+), 146 deletions(-)

Modified: trunk/boost/proto/detail/poly_function.hpp
==============================================================================
--- trunk/boost/proto/detail/poly_function.hpp (original)
+++ trunk/boost/proto/detail/poly_function.hpp 2012-07-23 21:53:10 EDT (Mon, 23 Jul 2012)
@@ -108,7 +108,7 @@
 
         type operator()() const
         {
- return *this;
+ return this->value;
         }
 
     private:
@@ -132,7 +132,7 @@
 
         type operator()() const
         {
- return *this;
+ return this->value;
         }
 
     private:

Modified: trunk/boost/proto/proto_fwd.hpp
==============================================================================
--- trunk/boost/proto/proto_fwd.hpp (original)
+++ trunk/boost/proto/proto_fwd.hpp 2012-07-23 21:53:10 EDT (Mon, 23 Jul 2012)
@@ -749,16 +749,32 @@
         BOOST_PROTO_CALLABLE()
     };
 
- struct data_type;
-
- struct transforms_type;
-
- struct key_not_found;
-
- struct empty_env;
-
- template<typename Tag, typename Value, typename Base = empty_env>
- struct env;
+ namespace envns_
+ {
+ struct key_not_found;
+
+ struct empty_env;
+
+ typedef int empty_state;
+
+ template<typename Tag, typename Value, typename Base = empty_env>
+ struct env;
+
+ struct data_type;
+ extern data_type const data;
+
+ struct transforms_type;
+ extern transforms_type const transforms;
+ }
+
+ using envns_::key_not_found;
+ using envns_::empty_env;
+ using envns_::empty_state;
+ using envns_::env;
+ using envns_::data_type;
+ using envns_::data;
+ using envns_::transforms_type;
+ using envns_::transforms;
 
     struct external_transform;
 

Modified: trunk/boost/proto/transform/env.hpp
==============================================================================
--- trunk/boost/proto/transform/env.hpp (original)
+++ trunk/boost/proto/transform/env.hpp 2012-07-23 21:53:10 EDT (Mon, 23 Jul 2012)
@@ -87,57 +87,62 @@
         TAG const NAME = {} \
         /**/
 
- ////////////////////////////////////////////////////////////////////////////////////////////
- // env
- // A transform env is a slot-based storage mechanism, accessible by tag.
- template<typename Tag, typename Value, typename Base /*= empty_env*/>
- struct env
- : private Base
- {
- private:
- Value value_;
-
- public:
- typedef Value value_type;
- typedef typename add_reference<Value>::type reference;
- typedef typename add_reference<typename add_const<Value>::type>::type const_reference;
- typedef void proto_environment_; ///< INTERNAL ONLY
-
- env(const_reference value, Base const &base = Base())
- : Base(base)
- , value_(value)
- {}
-
- template<typename OtherTag, typename OtherValue = key_not_found>
- struct lookup
- : Base::template lookup<OtherTag, OtherValue>
- {};
-
- template<typename OtherValue>
- struct lookup<Tag, OtherValue>
+ namespace envns_
+ {
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ // env
+ // A transform env is a slot-based storage mechanism, accessible by tag.
+ template<typename Key, typename Value, typename Base /*= empty_env*/>
+ struct env
+ : private Base
             {
- typedef Value type;
+ private:
+ Value value_;
+
+ public:
+ typedef Value value_type;
+ typedef typename add_reference<Value>::type reference;
                 typedef typename add_reference<typename add_const<Value>::type>::type const_reference;
- };
+ typedef void proto_environment_; ///< INTERNAL ONLY
 
- // For key-based lookups not intended to fail
- using Base::operator[];
- const_reference operator[](Tag) const
- {
- return this->value_;
- }
+ explicit env(const_reference value, Base const &base = Base())
+ : Base(base)
+ , value_(value)
+ {}
 
- // For key-based lookups that can fail, use the default if key not found.
- using Base::at;
- template<typename T>
- const_reference at(Tag, T const &) const
- {
- return this->value_;
- }
- };
+ /// INTERNAL ONLY
+ template<typename OtherTag, typename OtherValue = key_not_found>
+ struct lookup
+ : Base::template lookup<OtherTag, OtherValue>
+ {};
+
+ /// INTERNAL ONLY
+ template<typename OtherValue>
+ struct lookup<Key, OtherValue>
+ {
+ typedef Value type;
+ typedef typename add_reference<typename add_const<Value>::type>::type const_reference;
+ };
 
- // define proto::data_type type and proto::data global
- BOOST_PROTO_DEFINE_ENV_VAR(data_type, data);
+ // For key-based lookups not intended to fail
+ using Base::operator[];
+ const_reference operator[](Key) const
+ {
+ return this->value_;
+ }
+
+ // For key-based lookups that can fail, use the default if key not found.
+ using Base::at;
+ template<typename T>
+ const_reference at(Key, T const &) const
+ {
+ return this->value_;
+ }
+ };
+
+ // define proto::data_type type and proto::data global
+ BOOST_PROTO_DEFINE_ENV_VAR(data_type, data);
+ }
 
         namespace functional
         {
@@ -202,9 +207,9 @@
 
             ////////////////////////////////////////////////////////////////////////////////////////
             // has_env_var
- template<typename Tag>
+ template<typename Key>
             struct has_env_var
- : detail::poly_function<has_env_var<Tag> >
+ : detail::poly_function<has_env_var<Key> >
             {
                 BOOST_PROTO_CALLABLE()
 
@@ -214,7 +219,7 @@
                     typedef
                         mpl::not_<
                             is_same<
- typename remove_reference<Env>::type::template lookup<Tag>::type
+ typename remove_reference<Env>::type::template lookup<Key>::type
                               , key_not_found
>
>
@@ -276,9 +281,9 @@
 
             ////////////////////////////////////////////////////////////////////////////////////////
             // env_var
- template<typename Tag>
+ template<typename Key>
             struct env_var
- : detail::poly_function<env_var<Tag> >
+ : detail::poly_function<env_var<Key> >
             {
                 BOOST_PROTO_CALLABLE()
 
@@ -286,12 +291,12 @@
                 struct impl
                 {
                     typedef
- typename remove_reference<Env>::type::template lookup<Tag>::type
+ typename remove_reference<Env>::type::template lookup<Key>::type
                     result_type;
 
                     result_type operator()(detail::arg<Env> e) const
                     {
- return e()[Tag()];
+ return e()[Key()];
                     }
                 };
             };
@@ -335,14 +340,14 @@
               : boost::result_of<functional::as_env(T)>
             {};
 
- template<typename Env, typename Tag>
+ template<typename Env, typename Key>
             struct has_env_var
- : boost::result_of<functional::has_env_var<Tag>(Env)>::type
+ : boost::result_of<functional::has_env_var<Key>(Env)>::type
             {};
 
- template<typename Env, typename Tag>
+ template<typename Env, typename Key>
             struct env_var
- : boost::result_of<functional::env_var<Tag>(Env)>
+ : boost::result_of<functional::env_var<Key>(Env)>
             {};
         }
 
@@ -362,73 +367,76 @@
 
         ////////////////////////////////////////////////////////////////////////////////////////////
         // has_env_var
- template<typename Tag, typename Env>
- typename proto::result_of::has_env_var<Env &, Tag>::type has_env_var(Env &e BOOST_PROTO_DISABLE_IF_IS_CONST(Env))
+ template<typename Key, typename Env>
+ typename proto::result_of::has_env_var<Env &, Key>::type has_env_var(Env &e BOOST_PROTO_DISABLE_IF_IS_CONST(Env))
         {
- return functional::has_env_var<Tag>()(e);
+ return functional::has_env_var<Key>()(e);
         }
 
- template<typename Tag, typename Env>
- typename proto::result_of::has_env_var<Env const &, Tag>::type has_env_var(Env const &e)
+ template<typename Key, typename Env>
+ typename proto::result_of::has_env_var<Env const &, Key>::type has_env_var(Env const &e)
         {
- return functional::has_env_var<Tag>()(e);
+ return functional::has_env_var<Key>()(e);
         }
 
         ////////////////////////////////////////////////////////////////////////////////////////////
         // env_var
- template<typename Tag, typename Env>
- typename proto::result_of::env_var<Env &, Tag>::type env_var(Env &e BOOST_PROTO_DISABLE_IF_IS_CONST(Env))
+ template<typename Key, typename Env>
+ typename proto::result_of::env_var<Env &, Key>::type env_var(Env &e BOOST_PROTO_DISABLE_IF_IS_CONST(Env))
         {
- return functional::env_var<Tag>()(e);
+ return functional::env_var<Key>()(e);
         }
 
- template<typename Tag, typename Env>
- typename proto::result_of::env_var<Env const &, Tag>::type env_var(Env const &e)
+ template<typename Key, typename Env>
+ typename proto::result_of::env_var<Env const &, Key>::type env_var(Env const &e)
         {
- return functional::env_var<Tag>()(e);
+ return functional::env_var<Key>()(e);
         }
 
- ////////////////////////////////////////////////////////////////////////////////////////////
- // env operator,
- template<typename T, typename T1, typename V1>
- inline typename disable_if_c<
- is_const<T>::value
- , env<T1, V1, BOOST_PROTO_UNCVREF(typename result_of::as_env<T &>::type)>
- >::type const operator,(T &t, env<T1, V1> const &head)
- {
- return env<T1, V1, BOOST_PROTO_UNCVREF(typename result_of::as_env<T &>::type)>(
- head[T1()]
- , proto::as_env(t)
- );
- }
+ namespace envns_
+ {
+ ////////////////////////////////////////////////////////////////////////////////////////
+ // env operator,
+ template<typename T, typename T1, typename V1>
+ inline typename disable_if_c<
+ is_const<T>::value
+ , env<T1, V1, BOOST_PROTO_UNCVREF(typename result_of::as_env<T &>::type)>
+ >::type const operator,(T &t, env<T1, V1> const &head)
+ {
+ return env<T1, V1, BOOST_PROTO_UNCVREF(typename result_of::as_env<T &>::type)>(
+ head[T1()]
+ , proto::as_env(t)
+ );
+ }
 
- template<typename T, typename T1, typename V1>
- inline env<T1, V1, BOOST_PROTO_UNCVREF(typename result_of::as_env<T const &>::type)> const
- operator,(T const &t, env<T1, V1> const &head)
- {
- return env<T1, V1, BOOST_PROTO_UNCVREF(typename result_of::as_env<T const &>::type)>(
- head[T1()]
- , proto::as_env(t)
- );
+ template<typename T, typename T1, typename V1>
+ inline env<T1, V1, BOOST_PROTO_UNCVREF(typename result_of::as_env<T const &>::type)> const
+ operator,(T const &t, env<T1, V1> const &head)
+ {
+ return env<T1, V1, BOOST_PROTO_UNCVREF(typename result_of::as_env<T const &>::type)>(
+ head[T1()]
+ , proto::as_env(t)
+ );
+ }
         }
 
         ////////////////////////////////////////////////////////////////////////////////////////////
         // _env_var
- template<typename Tag>
+ template<typename Key>
         struct _env_var
- : proto::transform<_env_var<Tag> >
+ : proto::transform<_env_var<Key> >
         {
             template<typename Expr, typename State, typename Data>
             struct impl
               : transform_impl<Expr, State, Data>
             {
- typedef typename impl::data::template lookup<Tag>::type result_type;
+ typedef typename impl::data::template lookup<Key>::type result_type;
                 BOOST_MPL_ASSERT_NOT((is_same<result_type, key_not_found>)); // lookup failed
 
                 #ifdef BOOST_PROTO_STRICT_RESULT_OF
                 result_type
                 #else
- typename impl::data::template lookup<Tag>::const_reference
+ typename impl::data::template lookup<Key>::const_reference
                 #endif
                 operator ()(
                     typename impl::expr_param
@@ -436,7 +444,7 @@
                   , typename impl::data_param d
                 ) const
                 {
- return d[Tag()];
+ return d[Key()];
                 }
             };
         };
@@ -467,20 +475,20 @@
         };
 
         /// INTERNAL ONLY
- template<typename Tag>
- struct is_callable<_env_var<Tag> >
+ template<typename Key>
+ struct is_callable<_env_var<Key> >
           : mpl::true_
         {};
 
         /// INTERNAL ONLY
- template<typename Tag>
- struct is_callable<functional::has_env_var<Tag> >
+ template<typename Key>
+ struct is_callable<functional::has_env_var<Key> >
           : mpl::true_
         {};
 
         /// INTERNAL ONLY
- template<typename Tag>
- struct is_callable<functional::env_var<Tag> >
+ template<typename Key>
+ struct is_callable<functional::env_var<Key> >
           : mpl::true_
         {};
     }

Modified: trunk/boost/proto/transform/impl.hpp
==============================================================================
--- trunk/boost/proto/transform/impl.hpp (original)
+++ trunk/boost/proto/transform/impl.hpp 2012-07-23 21:53:10 EDT (Mon, 23 Jul 2012)
@@ -24,36 +24,39 @@
 
 namespace boost { namespace proto
 {
- ////////////////////////////////////////////////////////////////////////////////////////////
- struct key_not_found
- {};
-
- ////////////////////////////////////////////////////////////////////////////////////////////
- // empty_env
- struct empty_env
+ namespace envns_
     {
- typedef void proto_environment_;
-
- template<typename OtherTag, typename OtherValue = key_not_found>
- struct lookup
- {
- typedef OtherValue type;
- typedef
- typename add_reference<typename add_const<OtherValue>::type>::type
- const_reference;
- };
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ struct key_not_found
+ {};
 
- key_not_found operator[](detail::any) const
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ // empty_env
+ struct empty_env
         {
- return key_not_found();
- }
+ typedef void proto_environment_;
 
- template<typename T>
- T const &at(detail::any, T const &t) const
- {
- return t;
- }
- };
+ template<typename OtherTag, typename OtherValue = key_not_found>
+ struct lookup
+ {
+ typedef OtherValue type;
+ typedef
+ typename add_reference<typename add_const<OtherValue>::type>::type
+ const_reference;
+ };
+
+ key_not_found operator[](detail::any) const
+ {
+ return key_not_found();
+ }
+
+ template<typename T>
+ T const &at(detail::any, T const &t) const
+ {
+ return t;
+ }
+ };
+ }
 
     ////////////////////////////////////////////////////////////////////////////////////////////
     // is_env
@@ -92,9 +95,9 @@
     typename boost::proto::detail::apply_transform<transform_type(Expr &)>::result_type \
     operator ()(Expr &e) const \
     { \
- int i = 0; \
+ boost::proto::empty_state s = 0; \
         boost::proto::empty_env d; \
- return boost::proto::detail::apply_transform<transform_type(Expr &)>()(e, i, d); \
+ return boost::proto::detail::apply_transform<transform_type(Expr &)>()(e, s, d); \
     } \
                                                                                                                 \
     template<typename Expr, typename State> \
@@ -152,9 +155,9 @@
     typename boost::proto::detail::apply_transform<transform_type(Expr const &)>::result_type \
     operator ()(Expr &&e) const \
     { \
- int i = 0; \
+ boost::proto::empty_state s = 0; \
         boost::proto::empty_env d; \
- return boost::proto::detail::apply_transform<transform_type(Expr const &)>()(e, i, d); \
+ return boost::proto::detail::apply_transform<transform_type(Expr const &)>()(e, s, d); \
     } \
                                                                                                                 \
     template<typename Expr, typename State> \
@@ -188,7 +191,7 @@
 
         template<typename PrimitiveTransform, typename Expr>
         struct apply_transform<PrimitiveTransform(Expr)>
- : PrimitiveTransform::template impl<Expr, int, empty_env>
+ : PrimitiveTransform::template impl<Expr, empty_state, empty_env>
         {};
 
         template<typename PrimitiveTransform, typename Expr, typename State>

Modified: trunk/boost/proto/transform/when.hpp
==============================================================================
--- trunk/boost/proto/transform/when.hpp (original)
+++ trunk/boost/proto/transform/when.hpp 2012-07-23 21:53:10 EDT (Mon, 23 Jul 2012)
@@ -157,8 +157,11 @@
       : when<_, Fun>
     {};
 
- // Define the transforms global
- BOOST_PROTO_DEFINE_ENV_VAR(transforms_type, transforms);
+ namespace envns_
+ {
+ // Define the transforms global
+ BOOST_PROTO_DEFINE_ENV_VAR(transforms_type, transforms);
+ }
 
     /// \brief This specialization uses the Data parameter as a collection
     /// of transforms that can be indexed by the specified rule.


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