Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63089 - in sandbox/statistics/support: boost/assign/auto_size/detail libs/assign/doc libs/assign/example libs/assign/src
From: erwann.rogard_at_[hidden]
Date: 2010-06-18 20:15:55


Author: e_r
Date: 2010-06-18 20:15:54 EDT (Fri, 18 Jun 2010)
New Revision: 63089
URL: http://svn.boost.org/trac/boost/changeset/63089

Log:
adding experimental function repeat
Added:
   sandbox/statistics/support/boost/assign/auto_size/detail/repeat.hpp (contents, props changed)
Text files modified:
   sandbox/statistics/support/libs/assign/doc/revision_history.txt | 1 +
   sandbox/statistics/support/libs/assign/doc/speed.txt | 6 +++++-
   sandbox/statistics/support/libs/assign/example/range.cpp | 30 ++++++++++++++++++++++++++++++
   sandbox/statistics/support/libs/assign/src/main.cpp | 4 ++++
   4 files changed, 40 insertions(+), 1 deletions(-)

Added: sandbox/statistics/support/boost/assign/auto_size/detail/repeat.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/support/boost/assign/auto_size/detail/repeat.hpp 2010-06-18 20:15:54 EDT (Fri, 18 Jun 2010)
@@ -0,0 +1,102 @@
+//////////////////////////////////////////////////////////////////////////////
+// repeat.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_REPEAT_ER_2010_HPP
+#define BOOST_ASSIGN_DETAIL_AUTO_SIZE_DETAIL_REPEAT_ER_2010_HPP
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/divides.hpp>
+#include <boost/mpl/modulus.hpp>
+#include <boost/assign/auto_size/detail/csv.hpp>
+
+namespace boost{
+namespace assign{
+namespace detail{
+namespace auto_size{
+namespace repeat_aux{
+
+ template<int N,typename T>
+ struct result{
+ typedef auto_size::tag::array pol_;
+ typedef typename auto_size::csv_policy<pol_>::template
+ apply<
+ T,
+ N,
+ boost::assign::detail::auto_size::ref_copy
+ >::type type;
+ };
+
+ template<int N,typename T>
+ struct caller{};
+
+ template<typename T>
+ struct caller<1,T>
+ {
+ typedef typename auto_size::repeat_aux::result<1,T> result_;
+ typedef typename result_::type type;
+
+ static type call(T& t){
+ return boost::assign::detail::auto_size::make_first_expr_no_policy<
+ boost::assign::detail::auto_size::ref_copy,T>(t);
+ }
+
+ };
+
+ template<typename T>
+ struct caller<2,T>
+ {
+ typedef typename auto_size::repeat_aux::result<2,T> result_;
+ typedef typename result_::type type;
+
+ static type call(T& t){
+ return boost::assign::detail::auto_size::make_first_expr_no_policy<
+ boost::assign::detail::auto_size::ref_copy,T>(t)(t);
+ }
+
+ };
+
+ template<typename T>
+ struct caller<3,T>
+ {
+ typedef typename auto_size::repeat_aux::result<3,T> result_;
+ typedef typename result_::type type;
+
+ static type call(T& t){
+ return boost::assign::detail::auto_size::make_first_expr_no_policy<
+ boost::assign::detail::auto_size::ref_copy,T>(t)(t)(t);
+ }
+
+ };
+
+}// repeat_aux
+}// auto_size
+}// detail
+
+ template<unsigned K,typename T>
+ typename detail::auto_size::repeat_aux::result<K,T>::type
+ repeat(T& t){
+ namespace ns = detail::auto_size;
+ typedef ns::repeat_aux::caller<K,T> caller_;
+ return caller_::call(t);
+ }
+
+ template<unsigned K,typename T>
+ typename detail::auto_size::repeat_aux::result<K,const T>::type
+ c_repeat(const T& t){
+ namespace ns = detail::auto_size;
+ typedef ns::repeat_aux::caller<K,const T> caller_;
+ return caller_::call( t );
+ }
+
+}// assign
+}// boost
+
+#endif
+
+
+
+

Modified: sandbox/statistics/support/libs/assign/doc/revision_history.txt
==============================================================================
--- sandbox/statistics/support/libs/assign/doc/revision_history.txt (original)
+++ sandbox/statistics/support/libs/assign/doc/revision_history.txt 2010-06-18 20:15:54 EDT (Fri, 18 Jun 2010)
@@ -1,6 +1,7 @@
 // Revision history:
 //
 //
+// June 18th, 2010. Tentatively added detail/repeat.hpp
 // June 15th, 2010. The argument r in
 // Container convert( const Container*,
 // assign_detail::default_type_tag, const R& r)

Modified: sandbox/statistics/support/libs/assign/doc/speed.txt
==============================================================================
--- sandbox/statistics/support/libs/assign/doc/speed.txt (original)
+++ sandbox/statistics/support/libs/assign/doc/speed.txt 2010-06-18 20:15:54 EDT (Fri, 18 Jun 2010)
@@ -32,4 +32,8 @@
 cref_list_of(160) => 0.45 s
 cref_csv(160) => 0.82 s
 cref_list_of<>(160) => 0.12 s
-list_of(160) => 21.98 s
\ No newline at end of file
+list_of(160) => 21.98 s
+
+
+
+

Modified: sandbox/statistics/support/libs/assign/example/range.cpp
==============================================================================
--- sandbox/statistics/support/libs/assign/example/range.cpp (original)
+++ sandbox/statistics/support/libs/assign/example/range.cpp 2010-06-18 20:15:54 EDT (Fri, 18 Jun 2010)
@@ -20,6 +20,8 @@
 #include <boost/assign/auto_size/range/chain_r.hpp>
 #include <boost/assign/auto_size/range/convert_range.hpp>
 
+#include <boost/assign/auto_size/detail/repeat.hpp>
+
 #include <libs/assign/example/range.h>
 
 void example_range(std::ostream& os)
@@ -113,7 +115,12 @@
 
     std::vector<tuple_> v = cref_csv( tuple_(1, "foo", 2) , tuple_(3, "bar", 4) );
     BOOST_ASSERT( v.size() == 2 );
+ BOOST_ASSERT( boost::get<0>( v[0] ) == 1 );
+ BOOST_ASSERT( boost::get<1>( v[0] ) == "foo" );
+ BOOST_ASSERT( boost::get<2>( v[0] ) == 2 );
     BOOST_ASSERT( boost::get<0>( v[1] ) == 3 );
+ BOOST_ASSERT( boost::get<1>( v[1] ) == "bar" );
+ BOOST_ASSERT( boost::get<2>( v[1] ) == 4 );
 }
 {
     std::vector<int> vec = (list_of(1),2,3);
@@ -121,6 +128,29 @@
     BOOST_ASSERT(vec[1]==2);
     BOOST_ASSERT(vec[2]==3);
 }
+{
+ int a = 4;
+ BOOST_AUTO( tmp, repeat<3>(a) );
+ BOOST_ASSERT( tmp[0] == 4 );
+ BOOST_ASSERT( tmp[1] == 4 );
+ BOOST_ASSERT( tmp[2] == 4 );
+ BOOST_ASSERT( tmp.size() == 3 );
+ tmp[0] = 1;
+ BOOST_ASSERT( a == 1 );
+ tmp[1] = 2;
+ BOOST_ASSERT( a == 2 );
+ tmp[2] = 3;
+ BOOST_ASSERT( a == 3 );
+}
+{
+ int a = 4;
+ BOOST_AUTO( tmp, c_repeat<3>(a) );
+ BOOST_ASSERT( tmp[0] == 4 );
+ BOOST_ASSERT( tmp[1] == 4 );
+ BOOST_ASSERT( tmp[2] == 4 );
+ BOOST_ASSERT( tmp.size() == 3 );
+}
+
         os << "<- " << std::endl;
     
 }

Modified: sandbox/statistics/support/libs/assign/src/main.cpp
==============================================================================
--- sandbox/statistics/support/libs/assign/src/main.cpp (original)
+++ sandbox/statistics/support/libs/assign/src/main.cpp 2010-06-18 20:15:54 EDT (Fri, 18 Jun 2010)
@@ -4,9 +4,13 @@
 #include <boost/assign/auto_size/check/ref_csv.hpp>
 #undef BOOST_ASSIGN_CHECK_EQUAL
 #include <libs/assign/example/range.h>
+#include <libs/assign/test/speed.h>
 
 int main (int argc, char * const argv[]) {
 
+// test_speed(std::cout);
+ example_range(std::cout);
+
     example_range(std::cout);
 
     using namespace boost::assign::detail::auto_size;


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