$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r59479 - in sandbox/statistics/detail/assign: boost/assign libs/assign/example
From: erwann.rogard_at_[hidden]
Date: 2010-02-04 15:15:47
Author: e_r
Date: 2010-02-04 15:15:46 EST (Thu, 04 Feb 2010)
New Revision: 59479
URL: http://svn.boost.org/trac/boost/changeset/59479
Log:
m
Text files modified: 
   sandbox/statistics/detail/assign/boost/assign/cref_list_of2.hpp        |    26 ++++++++++---                           
   sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.cpp |    75 ++++++++++++++------------------------- 
   2 files changed, 48 insertions(+), 53 deletions(-)
Modified: sandbox/statistics/detail/assign/boost/assign/cref_list_of2.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/cref_list_of2.hpp	(original)
+++ sandbox/statistics/detail/assign/boost/assign/cref_list_of2.hpp	2010-02-04 15:15:46 EST (Thu, 04 Feb 2010)
@@ -31,10 +31,17 @@
 namespace cref_list_of2_impl{
             
         typedef boost::mpl::void_ top_;
+
+	template<typename T,bool do_const>
+    struct value : boost::mpl::if_<
+    	boost::mpl::bool_<do_const>,
+        typename add_const<T>::type,
+        T
+    >{};
             
     template<typename T>
     struct ref{
-        typedef boost::assign_detail::assign_reference<const T> type;
+        typedef boost::assign_detail::assign_reference<T> type;
     };
             
     template<typename T,int N>
@@ -69,10 +76,10 @@
         // public:
         typedef next_ result_type;
                 
-        expr(const T& t):ref(t){} // only for N == 1
-        expr(E& p,const T& t):previous(p),ref(t){}
+        expr(T& t):ref(t){} // only for N == 1
+        expr(E& p,T& t):previous(p),ref(t){}
                 
-        next_ operator()(const T& t){ return next_(*this,t); }
+        next_ operator()(T& t){ return next_(*this,t); }
                 
         template<typename T1>
         operator boost::array<T1,N>(){
@@ -167,12 +174,19 @@
 }// cref_list_of2_impl        
         
     template<typename T>
-    typename cref_list_of2_impl::first<T>::type
+    typename cref_list_of2_impl::first<const T>::type
     cref_list_of2(const T& t){
+        typedef typename cref_list_of2_impl::first<const T>::type expr_;
+        return expr_(t);
+    }
+
+    template<typename T>
+    typename cref_list_of2_impl::first<T>::type
+    ref_list_of2(T& t){
         typedef typename cref_list_of2_impl::first<T>::type expr_;
         return expr_(t);
     }
-        
+    
 }// assign
 }// boost
 
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-04 15:15:46 EST (Thu, 04 Feb 2010)
@@ -16,78 +16,59 @@
 
 void example_cref_list_of2(std::ostream& os)
 {
-	os << "-> example_cref_listof2 : " << std::endl;
+	os << "-> example_cref_listof2 : ";
         using namespace boost::assign;
     
           typedef std::vector<int> ints_;
 
         {    
-    	int a=1,b=2;
+    	int a=1,b=2,c=3;
             ints_ ints;
     
             ints = cref_list_of<3>(a)(b)(3);
                 BOOST_ASSERT(ints[0] == a);    
                 BOOST_ASSERT(ints[1] == b);    
                 BOOST_ASSERT(ints[2] == 3);    
+
+		// cref_list_of2
             ints.clear();
                 ints = cref_list_of2(a)(b)(3);     
                 BOOST_ASSERT(ints[0] == a);    
                 BOOST_ASSERT(ints[1] == b);    
                 BOOST_ASSERT(ints[2] == 3);    
-		
-        ints = cref_list_of2(a)(b)(3);
 
-        BOOST_AUTO(
-        	tmp,
-            cref_list_of2(a)(b)(3)
-        );
-        ints = ints_(boost::begin(tmp),boost::end(tmp));
+		{
+    		ints.clear();
+        	BOOST_AUTO(
+        		tmp,
+            	cref_list_of2(a)(b)(3)
+        	);
+        	ints = ints_(boost::begin(tmp),boost::end(tmp));
+			BOOST_ASSERT(ints[0] == a);    
+			BOOST_ASSERT(ints[1] == b);    
+			BOOST_ASSERT(ints[2] == 3);    
+		}
 
+		// ref_list_of2
+    	ints.clear();
+		ints = ref_list_of2(a)(b)(c);     
                 BOOST_ASSERT(ints[0] == a);    
                 BOOST_ASSERT(ints[1] == b);    
-		BOOST_ASSERT(ints[2] == 3);    
+		BOOST_ASSERT(ints[2] == c);    
         
-    }
-    {
-		const int n = 100 * 1000;
-        typedef std::vector<ints_> vec_ints_;
-        ints_ a( n );
-    	ints_ b( n );
-		boost::timer t;
-
-		{
-			t.restart();    
-			vec_ints_ vec_ints = cref_list_of<3>( a )( b )( ints_( n ) );
-            double t_val = t.elapsed();
-			os << "cref_list_of : t = " << t_val << std::endl;
-            BOOST_ASSERT(vec_ints[0] == a);    
-            BOOST_ASSERT(vec_ints[1] == b);    
-            BOOST_ASSERT(vec_ints[2] == ints_( n ));    
-        }
                 {
-			t.restart();    
-			vec_ints_ vec_ints = cref_list_of2( a )( b )( ints_( n ) );
-            double t_val = t.elapsed();
-			os << "conversion cref_list_of2 : t = " << t_val << std::endl;
-            BOOST_ASSERT(vec_ints[0] == a);    
-            BOOST_ASSERT(vec_ints[1] == b);    
-            BOOST_ASSERT(vec_ints[2] == ints_( n ));    
-        }
-		{
-			t.restart();    
-            BOOST_AUTO(
+    		ints.clear();
+        	BOOST_AUTO(
                 tmp,
-                cref_list_of2( a )( b )( ints_( n ) )
+                ref_list_of2(a)(b)(c)
             );
-			vec_ints_ vec_ints(boost::begin(tmp),boost::end(tmp));
-            double t_val = t.elapsed();
-			os << "copy cref_list_of2 : t = " << t_val << std::endl;
-            BOOST_ASSERT(vec_ints[0] == a);    
-            BOOST_ASSERT(vec_ints[1] == b);    
-            BOOST_ASSERT(vec_ints[2] == ints_( n ));    
-        }
+        	ints = ints_(boost::begin(tmp),boost::end(tmp));
+			BOOST_ASSERT(ints[0] == a);    
+			BOOST_ASSERT(ints[1] == b);    
+			BOOST_ASSERT(ints[2] == 3);    
+		}
         
-	}        
+    }
 
     
         os << "<- " << std::endl;