Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-12-20 15:44:09


Author: eric_niebler
Date: 2007-12-20 15:44:09 EST (Thu, 20 Dec 2007)
New Revision: 42213
URL: http://svn.boost.org/trac/boost/changeset/42213

Log:
PP loop-unroll arg_c and friends
Added:
   branches/proto/v3/boost/xpressive/proto/detail/arg_c.hpp (contents, props changed)
Text files modified:
   branches/proto/v3/boost/xpressive/proto/traits.hpp | 92 ---------------------------------------
   1 files changed, 1 insertions(+), 91 deletions(-)

Added: branches/proto/v3/boost/xpressive/proto/detail/arg_c.hpp
==============================================================================
--- (empty file)
+++ branches/proto/v3/boost/xpressive/proto/detail/arg_c.hpp 2007-12-20 15:44:09 EST (Thu, 20 Dec 2007)
@@ -0,0 +1,109 @@
+#ifndef BOOST_PP_IS_ITERATING
+ ///////////////////////////////////////////////////////////////////////////////
+ /// \file arg_c.hpp
+ /// Definintion of the arg_c trait, and friends
+ //
+ // Copyright 2007 Eric Niebler. 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)
+
+ #ifndef BOOST_PROTO_DETAIL_ARG_C_HPP_EAN_11_07_2007
+ #define BOOST_PROTO_DETAIL_ARG_C_HPP_EAN_11_07_2007
+
+ #include <boost/xpressive/proto/proto_fwd.hpp>
+ #include <boost/xpressive/proto/detail/define.hpp>
+
+ namespace boost { namespace proto { namespace result_of
+ {
+ namespace detail
+ {
+
+ template<typename Cons, long N>
+ struct arg_c;
+
+ template<typename Cons, long N>
+ struct arg_cv;
+
+ template<typename Cons, long N>
+ struct value_at_c;
+
+ #define CDR_TYPE(Z, N, DATA) ::cdr_type
+ #define CDR(Z, N, DATA) .cdr
+
+ #ifdef BOOST_HAS_VARIADIC_TMPL
+ template<typename Cons, long N>
+ struct arg_c
+ {
+ typedef arg_c<typename Cons BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, CDR_TYPE, ~), N-BOOST_PROTO_MAX_ARITY> base_type;
+ typedef typename base_type::type type;
+
+ static type call(Cons &args)
+ {
+ return base_type::call(args BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, CDR, ~));
+ }
+ };
+
+ template<typename Cons, long N>
+ struct arg_cv
+ {
+ typedef arg_c<typename Cons BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, CDR_TYPE, ~), N-BOOST_PROTO_MAX_ARITY> base_type;
+ typedef typename base_type::type type;
+
+ static type call(Cons const &args)
+ {
+ return base_type::call(args BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, CDR, ~));
+ }
+ };
+
+ template<typename Cons, long N>
+ struct value_at_c
+ : value_at_c<typename Cons BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, CDR_TYPE, ~), N-BOOST_PROTO_MAX_ARITY>
+ {};
+ #endif
+
+ #define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PROTO_MAX_ARITY, <boost/xpressive/proto/detail/arg_c.hpp>))
+ #include BOOST_PP_ITERATE()
+
+ #undef CDR_TYPE
+ #undef CDR
+ }
+ }}}
+
+ #include <boost/xpressive/proto/detail/undef.hpp>
+ #endif
+
+#else
+
+ #define N BOOST_PP_ITERATION()
+
+ template<typename Cons>
+ struct arg_c<Cons, N>
+ {
+ typedef REF(typename Cons BOOST_PP_REPEAT(N, CDR_TYPE, ~) ::car_type) type;
+
+ static type call(Cons &args)
+ {
+ return args BOOST_PP_REPEAT(N, CDR, ~) .car;
+ }
+ };
+
+ template<typename Cons>
+ struct arg_cv<Cons, N>
+ {
+ typedef CVREF(typename Cons BOOST_PP_REPEAT(N, CDR_TYPE, ~) ::car_type) type;
+
+ static type call(Cons const &args)
+ {
+ return args BOOST_PP_REPEAT(N, CDR, ~) .car;
+ }
+ };
+
+ template<typename Cons>
+ struct value_at_c<Cons, N>
+ {
+ typedef typename Cons BOOST_PP_REPEAT(N, CDR_TYPE, ~) ::car_type type;
+ };
+
+ #undef N
+
+#endif

Modified: branches/proto/v3/boost/xpressive/proto/traits.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/traits.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/traits.hpp 2007-12-20 15:44:09 EST (Thu, 20 Dec 2007)
@@ -16,6 +16,7 @@
 #include <boost/xpressive/proto/detail/apply_args.hpp>
 #include <boost/xpressive/proto/detail/nary_expr.hpp>
 #include <boost/xpressive/proto/detail/is_callable.hpp>
+#include <boost/xpressive/proto/detail/arg_c.hpp>
 #include <boost/xpressive/proto/detail/define.hpp>
 
 namespace boost { namespace proto
@@ -156,97 +157,6 @@
     namespace result_of
     {
 
- namespace detail
- {
- // TODO completely unroll these to BOOST_PROTO_MAX_ARITY
- template<typename Cons, long N>
- struct arg_c
- {
- typedef arg_c<typename Cons::cdr_type::cdr_type, N-2> base_type;
- typedef typename base_type::type type;
-
- static type call(Cons &args)
- {
- return base_type::call(args.cdr.cdr);
- }
- };
-
- template<typename Cons>
- struct arg_c<Cons, 0>
- {
- typedef REF(typename Cons::car_type) type;
-
- static type call(Cons &args)
- {
- return args.car;
- }
- };
-
- template<typename Cons>
- struct arg_c<Cons, 1>
- {
- typedef REF(typename Cons::cdr_type::car_type) type;
-
- static type call(Cons &args)
- {
- return args.cdr.car;
- }
- };
-
-
- template<typename Cons, long N>
- struct arg_cv
- {
- typedef arg_cv<typename Cons::cdr_type::cdr_type, N-2> base_type;
- typedef typename base_type::type type;
-
- static type call(Cons const &args)
- {
- return base_type::call(args.cdr.cdr);
- }
- };
-
- template<typename Cons>
- struct arg_cv<Cons, 0>
- {
- typedef CVREF(typename Cons::car_type) type;
-
- static type call(Cons const &args)
- {
- return args.car;
- }
- };
-
- template<typename Cons>
- struct arg_cv<Cons, 1>
- {
- typedef CVREF(typename Cons::cdr_type::car_type) type;
-
- static type call(Cons const &args)
- {
- return args.cdr.car;
- }
- };
-
- template<typename Cons, long N>
- struct value_at_c
- : value_at_c<typename Cons::cdr_type::cdr_type, N-2>
- {};
-
- template<typename Cons>
- struct value_at_c<Cons, 0>
- {
- typedef typename Cons::car_type type;
- };
-
- template<typename Cons>
- struct value_at_c<Cons, 1>
- {
- typedef typename Cons::cdr_type::car_type type;
- };
-
- } // namespace detail
-
         template<typename Expr, long N>
         struct value_at_c
           : detail::value_at_c<typename Expr::proto_args::cons_type, N>


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