$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r55852 - sandbox/statistics/matrix_view/boost/matrix_view/algorithm
From: erwann.rogard_at_[hidden]
Date: 2009-08-28 20:46:49
Author: e_r
Date: 2009-08-28 20:46:49 EDT (Fri, 28 Aug 2009)
New Revision: 55852
URL: http://svn.boost.org/trac/boost/changeset/55852
Log:
modif
Text files modified: 
   sandbox/statistics/matrix_view/boost/matrix_view/algorithm/transform_column.hpp |    80 ++++++++++++++++++++++++++++++++++++----
   1 files changed, 72 insertions(+), 8 deletions(-)
Modified: sandbox/statistics/matrix_view/boost/matrix_view/algorithm/transform_column.hpp
==============================================================================
--- sandbox/statistics/matrix_view/boost/matrix_view/algorithm/transform_column.hpp	(original)
+++ sandbox/statistics/matrix_view/boost/matrix_view/algorithm/transform_column.hpp	2009-08-28 20:46:49 EDT (Fri, 28 Aug 2009)
@@ -10,6 +10,8 @@
 #include <iterator>
 #include <boost/utility.hpp>
 #include <boost/lambda/lambda.hpp>
+#include <boost/concept_check.hpp>
+#include <boost/iterator/iterator_concepts.hpp>
 
 namespace boost{
 namespace matrix_view{
@@ -23,38 +25,100 @@
     // A k-step iterator + algorithm would be more general, but until then...
     template<unsigned k,typename F,typename It,typename ItO>
     ItO transform_column(
+        It b,   // first matrix elem
+        It e,   // last matrix elem
+        unsigned offset,
+        F f, 
+        ItO i_o // column 
+    );
+
+    template<unsigned k,typename F,typename It,typename ItO>
+    ItO transform_to_column(
+        It b,   // first of column
+        It e,   // end of column
+        unsigned offset,
+        F f, 
+        ItO i_o // first matrix elem
+    );
+
+    template<unsigned k,typename It,typename ItO>
+    ItO copy_column(
+        It b,
+        It e,
+        unsigned offset,
+        ItO i_o
+    ){
+        return transform_column<k>(b, e, offset, boost::lambda::_1, i_o);
+    }
+
+
+    template<unsigned k,typename It,typename ItO>
+    ItO copy_to_column(
+        It b,
+        It e,
+        unsigned offset,
+        ItO i_o
+    ){
+        return transform_to_column<k>(b, e, offset, boost::lambda::_1, i_o);
+    }
+
+
+    // Implementation //
+
+    template<unsigned k,typename F,typename It,typename ItO>
+    ItO transform_column(
         It b,
         It e,
         unsigned offset,
         F f, 
         ItO i_o
     ){
+        BOOST_CONCEPT_ASSERT((boost_concepts::IncrementableIterator<It>));
+        BOOST_CONCEPT_ASSERT((boost_concepts::IncrementableIterator<ItO>));
+        BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<It>));
+    
         typedef typename iterator_difference<It>::type diff_;
-        diff_ d = std::distance(b,e);
+        diff_ d = std::distance( b, e );
         BOOST_ASSERT(d>=0);
         if(d<offset){
             return i_o;
         }
-        b = next(b,offset);
+        b = boost::next( b, offset );
         diff_ n = d / k;
-        i_o = f(*b);                         
+        *i_o = f(*b);
+        ++i_o;
         for(unsigned i = 1; i<n; ++i){
-            std::advance(b,k);            
-            i_o = f(*b);
+            b = boost::next( b, k );            
+            *i_o = f(*b);
             ++i_o;
         }
         return i_o;
     }
 
 
-    template<unsigned k,typename It,typename ItO>
-    ItO copy_column(
+    template<unsigned k,typename F,typename It,typename ItO>
+    ItO transform_to_column(
         It b,
         It e,
         unsigned offset,
+        F f, 
         ItO i_o
     ){
-        return transform_column<k>(b, e, offset, boost::lambda::_1, i_o);
+        BOOST_CONCEPT_ASSERT((boost_concepts::IncrementableIterator<It>));
+        BOOST_CONCEPT_ASSERT((boost_concepts::IncrementableIterator<ItO>));
+        BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<It>));
+    
+        typedef typename iterator_difference<It>::type diff_;
+        i_o = boost::next( i_o, offset );
+        diff_ n = std::distance(b, e);
+        *i_o = f( *b );
+        ++b;
+        for(unsigned i = 1; i<n; ++i){
+            i_o = boost::next( i_o, k );            
+            *i_o = f( *b );
+            ++b;
+        }
+        return ++i_o;
     }
 
 }// algorithm