|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59963 - in sandbox/statistics/detail/assign: boost/assign/auto_size boost/assign/auto_size/detail libs/assign/example libs/assign/src
From: erwann.rogard_at_[hidden]
Date: 2010-02-27 17:34:42
Author: e_r
Date: 2010-02-27 17:34:41 EST (Sat, 27 Feb 2010)
New Revision: 59963
URL: http://svn.boost.org/trac/boost/changeset/59963
Log:
m
Added:
sandbox/statistics/detail/assign/boost/assign/auto_size/detail/csv.hpp (contents, props changed)
Text files modified:
sandbox/statistics/detail/assign/boost/assign/auto_size/detail/auto_size.hpp | 142 +++++++++++++++++++++++++--------------
sandbox/statistics/detail/assign/boost/assign/auto_size/ref_list_of.hpp | 27 +++++-
sandbox/statistics/detail/assign/boost/assign/auto_size/ref_rebind_list_of.hpp | 10 +-
sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.cpp | 29 +++++++
sandbox/statistics/detail/assign/libs/assign/src/main.cpp | 2
5 files changed, 143 insertions(+), 67 deletions(-)
Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/detail/auto_size.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/detail/auto_size.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/detail/auto_size.hpp 2010-02-27 17:34:41 EST (Sat, 27 Feb 2010)
@@ -8,12 +8,15 @@
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_ASSIGN_AUTO_SIZE_DETAIL_AUTO_SIZE_ER_2010_HPP
#define BOOST_ASSIGN_AUTO_SIZE_DETAIL_AUTO_SIZE_ER_2010_HPP
+#include <iostream> // TODO remove
#include <boost/mpl/void.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/equal_to.hpp>
+#include <boost/utility/enable_if.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/type_traits.hpp>
+#include <boost/type_traits/is_same.hpp>
#include <boost/array.hpp>
#include <boost/range.hpp>
#include <boost/assign/list_of.hpp> // needed for assign_referene
@@ -71,52 +74,47 @@
typedef expr<E,T,N,Ref> expr_;
typedef expr<expr_,T,N+1,Ref> type;
};
-
+
+ template<typename T,int N,template<typename> class Ref,typename D>
+ struct array_wrapper;
+
template<typename E,typename T,int N,template<typename> class Ref>
- class expr{
+ class expr : public array_wrapper<T,N,Ref,expr<E,T,N,Ref> >{
typedef boost::mpl::int_<N> int_n_;
typedef boost::mpl::int_<1> int_1_;
typedef typename Ref<T>::type ref_;
+ typedef array_wrapper<T,N,Ref,expr<E,T,N,Ref> > super_;
+
public:
- typedef typename boost::mpl::equal_to<int_n_,int_1_>::type is_first_;
- typedef typename boost::mpl::if_<is_first_,E,E&>::type previous_;
- typedef typename ref_array<T,N,Ref>::type ref_array_;
+ typedef typename
+ boost::mpl::equal_to<int_n_,int_1_>::type is_first_;
+ typedef typename
+ boost::mpl::if_<is_first_,E,const E&>::type previous_;
typedef typename next<E,T,N,Ref>::type next_;
- expr(T& t):ref(t){} // only for N == 1
- expr(E& p,T& t):previous(p),ref(t){}
-
+ expr(const E& p,T& t):previous(p),ref(t){}
+
typedef next_ result_type;
- next_ operator()(T& t){ return next_(*this,t); }
-
- template<typename T1>
- operator boost::array<T1,N>()const{
- boost::array<T1,N> ar;
- std::copy(
- boost::begin(this->ref_array()),
- boost::end(this->ref_array()),
- boost::begin(ar)
- );
- return ar;
- }
-
- template<typename C>
- operator C()const
- {
- return C(
- boost::begin(this->ref_array()),
- boost::end(this->ref_array())
- );
- }
-
- // ---- boost::array interface ---- //
-
+ next_ operator()(T& t)const{ return next_(*this,t); }
+
+ mutable previous_ previous;
+ mutable ref_ ref;
+
+ };
+
+ template<typename T,int N,template<typename> class Ref,typename D>
+ struct array_wrapper{
+ typedef typename Ref<T>::type ref_;
+ typedef typename ref_array<T,N,Ref>::type ref_array_;
+
typedef ref_ value_type;
- typedef typename boost::range_iterator<ref_array_>::type iterator;
+ typedef typename
+ boost::range_iterator<ref_array_>::type iterator;
typedef typename boost::range_iterator<
const ref_array_>::type const_iterator;
- typedef typename boost::range_size<ref_array_>::type size_type;
+ typedef typename
+ boost::range_size<ref_array_>::type size_type;
typedef typename boost::range_difference<
ref_array_>::type difference_type;
@@ -148,7 +146,8 @@
}
typedef typename ref_array_::reference reference;
- typedef typename ref_array_::const_reference const_reference;
+ typedef typename
+ ref_array_::const_reference const_reference;
reference operator[](size_type i){ return (this->ref_array())[i]; }
const_reference operator[](size_type i)const{
@@ -161,15 +160,32 @@
void swap(ref_array_& other){ return (this->ref_array()).swap(other); }
void assign(const T& val){ return (this->ref_array()).assign(val); }
-
- mutable previous_ previous;
- mutable ref_ ref;
- private:
+ template<typename T1>
+ operator boost::array<T1,N>()const{
+ boost::array<T1,N> ar;
+ std::copy(
+ boost::begin(this->ref_array()),
+ boost::end(this->ref_array()),
+ boost::begin(ar)
+ );
+ return ar;
+ }
+
+ template<typename C>
+ operator C ()const
+ {
+ return C(
+ boost::begin(this->ref_array()),
+ boost::end(this->ref_array())
+ );
+ }
+ private:
+
void alloc()const{
this->ptr = smart_ptr_(new ref_array_);
- write_to_array(*this->ptr,*this);
+ write_to_array(*this->ptr,static_cast<const D&>(*this));
}
void alloc_if()const{
@@ -178,6 +194,8 @@
}
}
+ protected:
+
ref_array_& ref_array(){
this->alloc_if();
return (*this->ptr);
@@ -188,13 +206,16 @@
return (*this->ptr);
}
+ private:
typedef boost::shared_ptr<ref_array_> smart_ptr_;
// Only the last of N expressions needs to instantiate an array,
// hence a pointer.
mutable smart_ptr_ ptr;
- };
-
+ };
+
+ // ---- write_to_array ---- //
+
typedef boost::mpl::bool_<false> false_;
typedef boost::mpl::bool_<true> true_;
@@ -218,18 +239,37 @@
void write_to_array(A& a,const expr<E,T,N,Ref>& e,true_ /*exit*/){
a[N-1] = e.ref;
}
-
- template<typename T>
- struct copy_first{
- typedef detail::auto_size::expr<
- detail::auto_size::top_,T,1,ref_copy> type;
+
+ // ---- first expr ---- //
+
+ template<typename T,template<typename> class Ref>
+ struct first_expr{
+ typedef detail::auto_size::expr<detail::auto_size::top_,T,1,Ref> type;
+ static type call(T& a){ return type(top_(),a); }
};
- template<typename T>
- struct rebind_first{
- typedef detail::auto_size::expr<
- detail::auto_size::top_,T,1,ref_rebind> type;
+ template<typename T>
+ struct first_copy : first_expr<T,ref_copy>{};
+
+ template<typename T>
+ struct first_rebind : first_expr<T,ref_rebind>{};
+
+ // ---- result_of ---- //
+
+ template<typename T,int N,template<typename> class Ref>
+ struct result_of{
+ typedef typename result_of<T,N-1,Ref>::type previous;
+ typedef expr<previous,T,N,Ref> type;
};
+
+ template<typename T,template<typename> class Ref>
+ struct result_of<T,1,Ref> : first_expr<T,Ref>{};
+
+ template<typename T,int N>
+ struct result_of_copy : result_of<T,N,ref_copy>{};
+
+ template<typename T,int N>
+ struct result_of_rebind : result_of<T,N,ref_rebind>{};
}// auto_size
}// detail
Added: sandbox/statistics/detail/assign/boost/assign/auto_size/detail/csv.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/detail/csv.hpp 2010-02-27 17:34:41 EST (Sat, 27 Feb 2010)
@@ -0,0 +1,38 @@
+//////////////////////////////////////////////////////////////////////////////
+// assign::detail::csv.hpp //
+// //
+// (C) Copyright 2010 Erwann Rogard //
+// Use, modification and distribution are subject to 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_ASSIGN_DETAIL_AUTO_SIZE_DETAIL_CSV_ER_2010_HPP
+#define BOOST_ASSIGN_DETAIL_AUTO_SIZE_DETAIL_CSV_ER_2010_HPP
+#include <boost/preprocessor/cat.hpp>
+#include <boost/preprocessor/repetition/enum.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_binary_params.hpp>
+#include <boost/assign/auto_size/detail/auto_size.hpp>
+
+// Warning : currently buggy
+
+#define BOOST_ASSIGN_LIST_OF_CSV_tmp(z,n,unused) (BOOST_PP_CAT(_,n))
+#define BOOST_ASSIGN_LIST_OF_CSV_rec(fun,N) \
+ boost::assign::fun BOOST_PP_ENUM(N,BOOST_ASSIGN_LIST_OF_CSV_tmp,~) \
+/**/
+#define BOOST_ASSIGN_LIST_OF_CSV_ITER(fun,N) \
+namespace boost{ \
+namespace assign{ \
+ template<typename T> \
+ typename assign::detail::auto_size::result_of_copy<const T,N>::type \
+ fun(BOOST_PP_ENUM_PARAMS(N, const T& _)){ \
+ return BOOST_ASSIGN_LIST_OF_CSV_rec(fun,N); \
+ } \
+} \
+} \
+/**/
+
+
+// TODO BOOST_PP_REPEAT and parameterize for const-qual/Ref
+
+#endif
Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/ref_list_of.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/ref_list_of.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/ref_list_of.hpp 2010-02-27 17:34:41 EST (Sat, 27 Feb 2010)
@@ -9,6 +9,7 @@
#ifndef BOOST_ASSIGN_AUTO_SIZE_REF_LIST_OF_ER_2010_HPP
#define BOOST_ASSIGN_AUTO_SIZE_REF_LIST_OF_ER_2010_HPP
#include <boost/assign/auto_size/detail/auto_size.hpp>
+#include <boost/assign/auto_size/detail/csv.hpp>
// Creates a collection of references exposing the boost::array interface and
// convertible to a range that is constructible from a pair of iterators. It can
@@ -20,20 +21,34 @@
namespace assign{
template<typename T>
- typename detail::auto_size::copy_first<const T>::type
+ typename detail::auto_size::first_copy<const T>::type
cref_list_of(const T& t){
- typedef typename detail::auto_size::copy_first<const T>::type expr_;
- return expr_(t);
+ return detail::auto_size::first_copy<const T>::call(t);
}
template<typename T>
- typename detail::auto_size::copy_first<T>::type
+ typename detail::auto_size::first_copy<T>::type
ref_list_of(T& t){
- typedef typename detail::auto_size::copy_first<T>::type expr_;
- return expr_(t);
+ return detail::auto_size::first_copy<T>::call(t);
+ }
+
+ // Temporary manual overloads. A is MACRO needed. See csv.hpp
+
+ template<typename T>
+ typename assign::detail::auto_size::result_of_copy<const T,2>::type
+ cref_list_of(const T& a,const T& b){
+ return cref_list_of(a)(b);
+ }
+
+ template<typename T>
+ typename assign::detail::auto_size::result_of_copy<const T,3>::type
+ cref_list_of(const T& a,const T& b,const T& c){
+ return cref_list_of(a)(b)(c);
}
}// assign
}// boost
+//BOOST_ASSIGN_LIST_OF_CSV_ITER(cref_list_of,3)
+
#endif
Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/ref_rebind_list_of.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/ref_rebind_list_of.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/ref_rebind_list_of.hpp 2010-02-27 17:34:41 EST (Sat, 27 Feb 2010)
@@ -21,17 +21,15 @@
namespace assign{
template<typename T>
- typename detail::auto_size::rebind_first<const T>::type
+ typename detail::auto_size::first_rebind<const T>::type
cref_rebind_list_of(const T& t){
- typedef typename detail::auto_size::rebind_first<const T>::type expr_;
- return expr_(t);
+ return detail::auto_size::first_rebind<const T>::call(t);
}
template<typename T>
- typename detail::auto_size::rebind_first<T>::type
+ typename detail::auto_size::first_rebind<T>::type
ref_rebind_list_of(T& t){
- typedef typename detail::auto_size::rebind_first<T>::type expr_;
- return expr_(t);
+ return detail::auto_size::first_rebind<T>::call(t);
}
}// assign
Modified: sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.cpp
==============================================================================
--- sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.cpp (original)
+++ sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.cpp 2010-02-27 17:34:41 EST (Sat, 27 Feb 2010)
@@ -24,7 +24,7 @@
typedef boost::array<int,3> array_;
array_ array;
- // Since operator= calls begin(), end(), no need to test these separately
+ // Since operator= calls begin() and end(), no need to test these separately
{
// cref_list_of
@@ -32,6 +32,30 @@
int a=1, b=2, c=3;
ints_ ints;
+ { os << "->Testing work in progress : csv " << std::endl;
+ typedef detail::auto_size::result_of_copy<const int,2>::type res_;
+ {
+ BOOST_AUTO(tmp, cref_list_of(a)(b)(3));
+// res_ res1(tmp); //calls copy constructor
+// BOOST_ASSERT(res1[0] == a);
+// BOOST_ASSERT(res1[1] == b);
+// BOOST_ASSERT(res1[2] == c);
+ }
+ {
+// res_ res2= ( cref_list_of(a)(b)(3) ); // what constructor?!
+// BOOST_ASSERT(res2[0] == a);
+// BOOST_ASSERT(res2[1] == b);
+// BOOST_ASSERT(res2[2] == 3);
+ }
+ {
+ BOOST_AUTO(res3,cref_list_of(a,b,c)); // what contructor is called?!
+ BOOST_ASSERT(res3[0] != a); //wrong
+ BOOST_ASSERT(res3[1] != b); //wrong
+ BOOST_ASSERT(res3[2] == c); //correct
+ }
+ os << "<-" << std::endl;
+ }
+/*
{
ints.clear();
ints = cref_list_of(a)(b)(3);
@@ -77,9 +101,8 @@
BOOST_ASSERT(ints[2] == d);
}
}
-
+*/
}
-
os << "<- " << std::endl;
};
Modified: sandbox/statistics/detail/assign/libs/assign/src/main.cpp
==============================================================================
--- sandbox/statistics/detail/assign/libs/assign/src/main.cpp (original)
+++ sandbox/statistics/detail/assign/libs/assign/src/main.cpp 2010-02-27 17:34:41 EST (Sat, 27 Feb 2010)
@@ -6,7 +6,7 @@
int main (int argc, char * const argv[]) {
example_cref_list_of(std::cout);
- test_cref_copy_list_of_speed(std::cout);
+// test_cref_copy_list_of_speed(std::cout);
// check_static_list_of_auto_size();
return 0;
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