Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-12-19 23:59:42


Author: eric_niebler
Date: 2007-12-19 23:59:41 EST (Wed, 19 Dec 2007)
New Revision: 42192
URL: http://svn.boost.org/trac/boost/changeset/42192

Log:
deep_copy and by_value_generator handle array types correctly
Text files modified:
   branches/proto/v3/boost/xpressive/proto/args.hpp | 33 +++++++++++++++++++++++++++++++++
   branches/proto/v3/boost/xpressive/proto/detail/by_value_generator.hpp | 4 ++--
   branches/proto/v3/boost/xpressive/proto/detail/deep_copy.hpp | 5 ++---
   branches/proto/v3/boost/xpressive/proto/expr.hpp | 34 ----------------------------------
   branches/proto/v3/libs/xpressive/proto/test/deep_copy.cpp | 6 +++++-
   5 files changed, 42 insertions(+), 40 deletions(-)

Modified: branches/proto/v3/boost/xpressive/proto/args.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/args.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/args.hpp 2007-12-19 23:59:41 EST (Wed, 19 Dec 2007)
@@ -99,6 +99,39 @@
         #undef CAR
         #undef CDR
 
+ namespace detail
+ {
+ template<typename Cons, typename T, std::size_t N>
+ struct make_cons_array
+ {
+ static Cons make(T (&t)[N])
+ {
+ Cons that = {t};
+ return that;
+ }
+ };
+
+ template<typename U, typename T, std::size_t N>
+ struct make_cons_array<cons<U[N]>, T, N>
+ {
+ static cons<U[N]> make(T (&t)[N])
+ {
+ cons<U[N]> that;
+ for(std::size_t i = 0; i < N; ++i)
+ {
+ that.car[i] = t[i];
+ }
+ return that;
+ }
+ };
+ }
+
+ template<typename Cons, typename T, std::size_t N>
+ inline Cons make_cons_(T (&t)[N])
+ {
+ return argsns_::detail::make_cons_array<Cons, T, N>::make(t);
+ }
+
         }
 
     }}

Modified: branches/proto/v3/boost/xpressive/proto/detail/by_value_generator.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/detail/by_value_generator.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/detail/by_value_generator.hpp 2007-12-19 23:59:41 EST (Wed, 19 Dec 2007)
@@ -25,13 +25,13 @@
             template<typename A>
             struct by_value_generator_<term<A> >
             {
+ // TODO doesn't handle reference to function
                 typedef term<UNCVREF(A)> type;
 
                 template<typename Cons>
                 static typename type::cons_type call(Cons const &a)
                 {
- typename type::cons_type that = {a.car};
- return that;
+ return argsns_::make_cons_<typename type::cons_type>(a.car);
                 }
             };
 

Modified: branches/proto/v3/boost/xpressive/proto/detail/deep_copy.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/detail/deep_copy.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/detail/deep_copy.hpp 2007-12-19 23:59:41 EST (Wed, 19 Dec 2007)
@@ -25,14 +25,13 @@
             template<typename A>
             struct deep_copy_<term<A> >
             {
+ // TODO doesn't handle reference to function
                 typedef term<UNCVREF(A)> type;
 
                 template<typename Cons>
                 static typename type::cons_type call(Cons const &a)
                 {
- // BUGBUG doesn't handle arrays and function references
- typename type::cons_type that = {a.car};
- return that;
+ return argsns_::make_cons_<typename type::cons_type>(a.car);
                 }
             };
 

Modified: branches/proto/v3/boost/xpressive/proto/expr.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/expr.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/expr.hpp 2007-12-19 23:59:41 EST (Wed, 19 Dec 2007)
@@ -35,25 +35,6 @@
             {
                 typedef Expr *type;
             };
-
- template<typename X, std::size_t N, typename Y>
- void checked_copy(X (&x)[N], Y (&y)[N])
- {
- for(std::size_t i = 0; i < N; ++i)
- {
- y[i] = x[i];
- }
- }
-
- template<typename T, std::size_t N>
- struct if_is_array
- {};
-
- template<typename T, std::size_t N>
- struct if_is_array<T[N], N>
- {
- typedef void type;
- };
         }
 
         template<typename Tag, typename Args, long Arity>
@@ -99,21 +80,6 @@
                 return that;
             }
 
- // necessary for terminals that store arrays by value
- template<typename A, std::size_t N>
- static expr make(
- A (&a)[N]
- , typename exprns_::detail::if_is_array<
- typename Args::cons_type::car_type, N
- >::type * = 0
- )
- {
- typedef char arity_is_zero[0==Arity];
- expr that;
- exprns_::detail::checked_copy(a, that.proto_args_.car);
- return that;
- }
-
         #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
 
             template<typename A>

Modified: branches/proto/v3/libs/xpressive/proto/test/deep_copy.cpp
==============================================================================
--- branches/proto/v3/libs/xpressive/proto/test/deep_copy.cpp (original)
+++ branches/proto/v3/libs/xpressive/proto/test/deep_copy.cpp 2007-12-19 23:59:41 EST (Wed, 19 Dec 2007)
@@ -23,6 +23,10 @@
     BOOST_CHECK_EQUAL(42, arg(left(r2)));
     BOOST_CHECK_EQUAL(24, arg(right(r2)));
 
+ char buf[16] = {'\0'};
+ terminal<char (&)[16]>::type t3 = {{buf}};
+ terminal<char[16]>::type r3 = deep_copy(t3);
+
     #ifdef BOOST_HAS_VARIADIC_TMPL
     function<
         terminal<int>::type
@@ -33,7 +37,7 @@
       , terminal<int>::type
       , terminal<int>::type
       , terminal<int>::type
- >::type r3 = deep_copy(t1(1,2,3,4,5,6,7));
+ >::type r4 = deep_copy(t1(1,2,3,4,5,6,7));
     #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