|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r51062 - in sandbox/miscellanea_iterator_facade: . boost boost/iterator libs libs/iterator libs/iterator/doc libs/iterator/src libs/iterator/src/example
From: erwann.rogard_at_[hidden]
Date: 2009-02-06 15:24:36
Author: e_r
Date: 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
New Revision: 51062
URL: http://svn.boost.org/trac/boost/changeset/51062
Log:
Adding library miscellanea_iterator_facade
Added:
sandbox/miscellanea_iterator_facade/
sandbox/miscellanea_iterator_facade/boost/
sandbox/miscellanea_iterator_facade/boost/iterator/
sandbox/miscellanea_iterator_facade/boost/iterator/for_each_over_2_vector2matrix.hpp (contents, props changed)
sandbox/miscellanea_iterator_facade/boost/iterator/insert_element_every_n_step_iterator.hpp (contents, props changed)
sandbox/miscellanea_iterator_facade/boost/iterator/range_left.hpp (contents, props changed)
sandbox/miscellanea_iterator_facade/boost/iterator/range_middle.hpp (contents, props changed)
sandbox/miscellanea_iterator_facade/boost/iterator/range_of_known_size.hpp (contents, props changed)
sandbox/miscellanea_iterator_facade/boost/iterator/range_result.hpp (contents, props changed)
sandbox/miscellanea_iterator_facade/boost/iterator/range_result_size.hpp (contents, props changed)
sandbox/miscellanea_iterator_facade/boost/iterator/range_right.hpp (contents, props changed)
sandbox/miscellanea_iterator_facade/boost/iterator/range_same.hpp (contents, props changed)
sandbox/miscellanea_iterator_facade/boost/iterator/skip_one_step_iterator.hpp (contents, props changed)
sandbox/miscellanea_iterator_facade/boost/iterator/skip_range_iterator.hpp (contents, props changed)
sandbox/miscellanea_iterator_facade/boost/iterator/vector2matrix_iterator.hpp (contents, props changed)
sandbox/miscellanea_iterator_facade/libs/
sandbox/miscellanea_iterator_facade/libs/iterator/
sandbox/miscellanea_iterator_facade/libs/iterator/doc/
sandbox/miscellanea_iterator_facade/libs/iterator/doc/readme.txt (contents, props changed)
sandbox/miscellanea_iterator_facade/libs/iterator/src/
sandbox/miscellanea_iterator_facade/libs/iterator/src/example/
sandbox/miscellanea_iterator_facade/libs/iterator/src/example/insert_element_every_n_step_iterator.cpp (contents, props changed)
sandbox/miscellanea_iterator_facade/libs/iterator/src/example/insert_element_every_n_step_iterator.h (contents, props changed)
sandbox/miscellanea_iterator_facade/libs/iterator/src/example/main.cpp (contents, props changed)
sandbox/miscellanea_iterator_facade/libs/iterator/src/example/skip_one_step_iterator.cpp (contents, props changed)
sandbox/miscellanea_iterator_facade/libs/iterator/src/example/skip_one_step_iterator.h (contents, props changed)
sandbox/miscellanea_iterator_facade/libs/iterator/src/example/skip_range_iterator.cpp (contents, props changed)
sandbox/miscellanea_iterator_facade/libs/iterator/src/example/skip_range_iterator.h (contents, props changed)
sandbox/miscellanea_iterator_facade/libs/iterator/src/example/subset_of_range.cpp (contents, props changed)
sandbox/miscellanea_iterator_facade/libs/iterator/src/example/subset_of_range.h (contents, props changed)
sandbox/miscellanea_iterator_facade/libs/iterator/src/example/vector2matrix.cpp (contents, props changed)
sandbox/miscellanea_iterator_facade/libs/iterator/src/example/vector2matrix.h (contents, props changed)
Added: sandbox/miscellanea_iterator_facade/boost/iterator/for_each_over_2_vector2matrix.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/boost/iterator/for_each_over_2_vector2matrix.hpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,125 @@
+//////////////////////////////////////////////////////////////////////////////
+// for_each_over_2_vector2matrix.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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_ITERATOR_FOR_EACH_ZIP_VECTOR2MATRIX_HPP_ER_2009
+#define BOOST_ITERATOR_FOR_EACH_ZIP_VECTOR2MATRIX_HPP_ER_2009
+#include <algorithm>
+#include <vector>
+#include <stdexcept>
+#include <boost/type_traits/add_const.hpp>
+#include <boost/range.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/iterator/vector2matrix_iterator.hpp>
+#include <boost/iterator/zip_iterator.hpp>
+namespace boost{
+
+/// Takes two sequences, maps each to matrix, and makes each pair
+/// of rows into a tuple, to which is applied a function, T(...).
+/// F0, F1: either mpl::identity or add_const
+template<
+ typename T,
+ template<typename> class F0 = mpl::identity,
+ template<typename> class F1 = mpl::identity
+>
+class for_each_over_2_vector2matrix{
+ /// Types associated with T:
+ typedef typename T::type obj_type;
+ typedef typename T::stride0_type stride0_type; //> instance of int_
+ typedef typename T::stride1_type stride1_type; //> instance of int_
+
+ /// Valid expressions:
+ /// x and y two forward ranges,
+ /// T::type t; t(x,y)
+
+ template<typename R,template<typename> class F>
+ struct add_ref{
+ typedef typename F<R>::type inner_type;
+ typedef typename add_reference<inner_type>::type type;
+ };
+
+ public:
+ static const std::size_t stride0 = stride0_type::value;
+ static const std::size_t stride1 = stride1_type::value;
+
+ for_each_over_2_vector2matrix(obj_type& obj):obj_(obj){}
+ for_each_over_2_vector2matrix(const for_each_over_2_vector2matrix& that)
+ :obj_(that.obj_){}
+
+ template<typename R0, typename R1>
+ void operator()(const R0& r0,const R1& r1){ return call_impl(r0,r1); }
+
+ template<typename R0, typename R1>
+ void operator()(R0& r0,const R1& r1){
+ typedef typename add_ref<R0,F0>::type r0_type;
+ return call_impl(static_cast<r0_type>(r0),r1); }
+
+ template<typename R0, typename R1>
+ void operator()(const R0& r0,R1& r1){
+ typedef typename add_ref<R1,F1>::type r1_type;
+ return call_impl(r0,static_cast<r1_type>(r1)); }
+
+ template<typename R0, typename R1>
+ void operator()(R0& r0,R1& r1){
+ typedef typename add_ref<R0,F0>::type r0_type;
+ typedef typename add_ref<R1,F1>::type r1_type;
+ return call_impl(static_cast<r0_type>(r0),static_cast<r1_type>(r1)); }
+
+ private:
+ for_each_over_2_vector2matrix& operator=(
+ const for_each_over_2_vector2matrix& that);
+ template<typename R0, typename R1>
+ void call_impl(R0& r0, R1& r1){
+ typedef zip_fun<R0,R1> zip_fun_type;
+ std::for_each(
+ make_zip_iterator(
+ make_tuple(
+ make_vector2matrix_iterator(begin(r0),stride0),
+ make_vector2matrix_iterator(begin(r1),stride1)
+ )
+ ),
+ make_zip_iterator(
+ make_tuple(
+ make_end_vector2matrix_iterator(
+ begin(r0),end(r0),stride0),
+ make_end_vector2matrix_iterator(
+ begin(r1),end(r1),stride1)
+ )
+ ),
+ zip_fun_type(obj_)
+ );
+
+ }
+
+ for_each_over_2_vector2matrix();//dont implem
+
+ template<typename R0, typename R1>
+ class zip_fun{
+ public:
+
+ typedef void result_type;
+
+ zip_fun(obj_type& obj):obj_(obj){}
+ zip_fun(const zip_fun& that ):obj_(that.obj_){}
+
+
+// TODO surprisingly ADL suffices i.e. argument_type need not be specified
+// Extend to other applications of zip_iterator in other classes?
+ template<typename Tuple>
+ void operator()(const Tuple& t){
+ obj_(t.template get<0>(),t.template get<1>());
+ }
+ private:
+ zip_fun& operator=(const zip_fun& that);
+ zip_fun(); //dont implem
+ obj_type& obj_;
+ };
+
+ obj_type& obj_;
+};
+
+
+}
+#endif
Added: sandbox/miscellanea_iterator_facade/boost/iterator/insert_element_every_n_step_iterator.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/boost/iterator/insert_element_every_n_step_iterator.hpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,204 @@
+//////////////////////////////////////////////////////////////////////////////
+// insert_element_every_n_step.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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_ITERATOR_INSERT_ELEMENT_EVERY_N_STEP_HPP_ER_2009
+#define BOOST_ITERATOR_INSERT_ELEMENT_EVERY_N_STEP_HPP_ER_2009
+#include <iterator>
+#include <stdexcept>
+#include <string>
+#include <boost/iterator/iterator_adaptor.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/type_traits.hpp>
+
+namespace boost{
+
+
+/// Maps a sequence {v[i]:i=0,1,...} to
+/// {x,v[0],v[1],...,v[n-1],x,v[n],...,v[2n-1],x,...}
+template<typename BaseIter>
+class insert_element_every_n_step_iterator
+ : public iterator_adaptor<
+ insert_element_every_n_step_iterator<BaseIter>,
+ BaseIter>
+{
+ typedef iterator_adaptor<
+ insert_element_every_n_step_iterator<BaseIter>,
+ BaseIter> super_type;
+ public:
+
+ insert_element_every_n_step_iterator(){}
+
+ explicit insert_element_every_n_step_iterator(
+ BaseIter i,
+ typename iterator_value<super_type>::type x,
+ typename super_type::difference_type n
+ )
+ :base_iter(i),x_(x),n_(n),delta_(-1){}
+
+ //TODO copy constructor?
+
+ typename super_type::difference_type n()const{ return n_; }
+
+ typename iterator_value<super_type>::type element()const{ return x_; }
+
+ private:
+
+ friend class boost::iterator_core_access;
+
+ typename super_type::difference_type
+ distance_to(insert_element_every_n_step_iterator const& other) const{
+ typedef typename super_type::difference_type d_type;
+ d_type d = std::distance(this->base_iter,other.base_iter) / n();
+ d = d * (n()+1) + (other.delta_-this->delta_);
+ return d;
+ }
+
+ bool equal(insert_element_every_n_step_iterator const& other) const
+ {
+ return (
+ (this->base_iter == other.base_iter)
+ && (this->delta_ == other.delta_)
+ && (this->x_ == other.x_)
+ );
+ }
+
+ void advance(typename super_type::difference_type m)
+ {
+ //TODO simpler computations?
+ if(m>0){
+ std::size_t k = m/(n()+1);
+ std::advance(this->base_iter, k * n());
+ delta_ += m - ( k * (n()+1) );
+ if(delta_ == n()){
+ std::advance(this->base_iter, n());
+ delta_ = -1;
+ }
+ }else{
+ if(m<0){
+ std::string str = "std::advance(";
+ str += "insert_element_every_n_step_iterator,k)";
+ str += ", k<0 not implemented";
+ throw std::runtime_error(str);
+ }
+ }
+ }
+
+ typename super_type::reference dereference() const {
+ if(delta_>-1){
+ BaseIter i = base_iter;
+ std::advance(i,delta_);
+ return *i;
+ }else{
+ return x_;
+ };
+ };
+
+ void increment(){
+
+ //advance((typename super_type::difference_type)(1));
+ ++delta_;
+ if(delta_==n()){
+ std::advance(this->base_iter,n());
+ delta_ = -1;
+ }
+ }
+ //void decrement();
+
+ BaseIter base_iter;
+ mutable typename iterator_value<super_type>::type x_;
+ typename super_type::difference_type n_;
+ typename super_type::difference_type delta_;
+};
+
+template<typename BaseIter>
+insert_element_every_n_step_iterator<BaseIter>
+make_begin_insert_element_every_n_step_iterator(
+ BaseIter b,
+ typename iterator_value<
+ insert_element_every_n_step_iterator<BaseIter> >::type x,
+ typename iterator_difference<
+ insert_element_every_n_step_iterator<BaseIter> >::type n
+){
+ return insert_element_every_n_step_iterator<BaseIter>(b,x,n);
+};
+
+/// Warning:
+/// boo ooo ooo e becomes
+/// xbooxoooxooox,
+/// and not
+/// xbooxoooxoooxe
+/// Other situations follow the more logical pattern:
+/// boo ooo ooe becomes
+/// xbooxoooxooe etc.
+template<typename BaseIter>
+insert_element_every_n_step_iterator<BaseIter>
+make_end_insert_element_every_n_step_iterator(
+ BaseIter base_b,
+ BaseIter base_e,
+ typename iterator_value<
+ insert_element_every_n_step_iterator<BaseIter> >::type x,
+ typename iterator_difference<
+ insert_element_every_n_step_iterator<BaseIter> >::type n
+){
+ typedef insert_element_every_n_step_iterator<BaseIter> iter_type;
+ typedef typename iterator_difference<iter_type>::type diff_type;
+ diff_type d = std::distance(base_b,base_e);
+ std::size_t k = d/n;
+
+ BaseIter base_i = base_b;
+
+ std::advance(base_i, k * n);
+ iter_type i(base_i, x, n);
+ if(d - k * n>0){
+ //TODO maybe throw a warning
+ ++i;
+ std::advance(i, d - k * n);
+ }
+
+ return i;
+};
+
+template<typename R>
+struct result_of_make_range_insert_element_every_n_step{
+ typedef typename range_iterator<R>::type base_type;
+ typedef insert_element_every_n_step_iterator<base_type> iter_type;
+ typedef iterator_range<iter_type> type;
+};
+
+template<typename R>
+typename result_of_make_range_insert_element_every_n_step<R>::type
+make_range_insert_element_every_n_step(
+ R& range,
+ typename iterator_value<
+ insert_element_every_n_step_iterator<
+ typename range_iterator<R>::type
+ >
+ >::type x,
+ typename iterator_difference<
+ insert_element_every_n_step_iterator<
+ typename range_iterator<R>::type
+ >
+ >::type n
+){
+ typedef typename result_of_make_range_insert_element_every_n_step<R>::type
+ result_type;
+
+ return result_type(
+ make_begin_insert_element_every_n_step_iterator(
+ begin(range),
+ x,
+ n
+ ),
+ make_end_insert_element_every_n_step_iterator(
+ begin(range),end(range),
+ x,
+ n
+ )
+ );
+};
+
+}
+#endif
Added: sandbox/miscellanea_iterator_facade/boost/iterator/range_left.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/boost/iterator/range_left.hpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,34 @@
+//////////////////////////////////////////////////////////////////////////////
+// range_left.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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_ITERATOR_RANGE_LEFT_HPP_ER_2009
+#define BOOST_ITERATOR_RANGE_LEFT_HPP_ER_2009
+#include <boost/range.hpp>
+#include <boost/assert.hpp>
+#include <boost/iterator/range_result.hpp>
+#include <boost/iterator/range_of_known_size.hpp>
+
+namespace boost{
+
+//Takes a range as input and returns the left portion of it
+template<std::size_t size>
+class range_left : public range_result, public range_of_known_size<size>{
+ public:
+ range_left(){}
+
+ template<typename R>
+ typename sub_range<R>::type
+ operator()(R& range)const{
+ typedef sub_range<R> result_type;
+ result_type result(begin(range),begin(range));
+ BOOST_ASSERT(boost::size(range)-size>=0);
+ result.advance_end(size);
+ return result;
+ };
+};
+
+}
+#endif
Added: sandbox/miscellanea_iterator_facade/boost/iterator/range_middle.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/boost/iterator/range_middle.hpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,33 @@
+//////////////////////////////////////////////////////////////////////////////
+// range_middle.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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_ITERATOR_RANGE_MIDDLE_HPP_ER_2009
+#define BOOST_ITERATOR_RANGE_MIDDLE_HPP_ER_2009
+#include <boost/range.hpp>
+#include <boost/iterator/range_result.hpp>
+#include <boost/iterator/range_of_known_size.hpp>
+namespace boost{
+// Takes a range as input and returns the middle portion of it
+template<std::size_t advance_begin,std::size_t size>
+class range_middle : public range_result, public range_of_known_size<size>{
+ public:
+
+ range_middle(){}
+
+ template<typename R>
+ typename sub_range<R>::type
+ operator()(R& range)const{
+ typedef sub_range<R> result_type;
+ result_type result(begin(range),begin(range));
+ BOOST_ASSERT(boost::size(range)-(advance_begin+size)>=0);
+ result.advance_end(advance_begin+size);
+ result.advance_begin(advance_begin);
+ return result;
+ };
+};
+
+}
+#endif
Added: sandbox/miscellanea_iterator_facade/boost/iterator/range_of_known_size.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/boost/iterator/range_of_known_size.hpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,23 @@
+//////////////////////////////////////////////////////////////////////////////
+// range_of_known_size.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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_ITERATOR_RANGE_OF_KNOW_SIZE_HPP_ER_2009
+#define BOOST_ITERATOR_RANGE_OF_KNOW_SIZE_HPP_ER_2009
+#include <boost/mpl/size_t.hpp>
+
+namespace boost{
+
+ // Result of subseting a range
+ // Serves as implementation to other classes
+ template<std::size_t size>
+ struct range_of_known_size{
+ template<std::size_t in_size>
+ struct result_size{
+ typedef mpl::size_t<size> type;
+ };
+ };
+}
+#endif
Added: sandbox/miscellanea_iterator_facade/boost/iterator/range_result.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/boost/iterator/range_result.hpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,29 @@
+//////////////////////////////////////////////////////////////////////////////
+// range_result.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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_ITERATOR_RANGE_RESULT_HPP_ER_2009
+#define BOOST_ITERATOR_RANGE_RESULT_HPP_ER_2009
+#include <boost/range.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+
+namespace boost{
+
+struct range_result{
+
+ template<class Signature>
+ struct result {
+ typedef boost::function_traits<Signature> fun_traits;
+ typedef typename fun_traits::arg1_type arg1_type;
+
+ typedef typename boost::remove_reference<
+ arg1_type>::type arg_type;
+ typedef sub_range<arg_type> type;
+ };
+};
+
+}
+#endif
Added: sandbox/miscellanea_iterator_facade/boost/iterator/range_result_size.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/boost/iterator/range_result_size.hpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+// range_result_size.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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_ITERATOR_RANGE_RESULT_SIZE_HPP_ER_2009
+#define BOOST_ITERATOR_RANGE_RESULT_SIZE_HPP_ER_2009
+namespace boost{
+
+ template<typename T,std::size_t input_size>
+ struct range_result_size{
+ typedef typename T::template result_size<input_size>::type type;
+ };
+
+}
+#endif
Added: sandbox/miscellanea_iterator_facade/boost/iterator/range_right.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/boost/iterator/range_right.hpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,33 @@
+//////////////////////////////////////////////////////////////////////////////
+// range_right.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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_ITERATOR_RANGE_RIGHT_HPP_ER_2009
+#define BOOST_ITERATOR_RANGE_RIGHT_HPP_ER_2009
+#include <boost/range.hpp>
+#include <boost/iterator/range_result.hpp>
+#include <boost/iterator/range_of_known_size.hpp>
+namespace boost{
+
+// Takes a range as input and returns the right portion
+template<std::size_t size>
+class range_right : public range_result, public range_of_known_size<size>{
+ public:
+
+ range_right(){}
+
+ template<typename R>
+ typename sub_range<R>::type
+ operator()(R& range)const{
+ typedef sub_range<R> result_type;
+ result_type result(begin(range),end(range));
+ BOOST_ASSERT(boost::size(range)-size>=0);
+ result.advance_begin(boost::size(range)-size);
+ return result;
+ };
+};
+
+}
+#endif
Added: sandbox/miscellanea_iterator_facade/boost/iterator/range_same.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/boost/iterator/range_same.hpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,33 @@
+//////////////////////////////////////////////////////////////////////////////
+// range_same.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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_ITERATOR_RANGE_SAME_HPP_ER_2009
+#define BOOST_ITERATOR_RANGE_SAME_HPP_ER_2009
+#include <boost/range.hpp>
+#include <boost/iterator/range_result.hpp>
+#include <boost/mpl/size_t.hpp>
+namespace boost{
+
+// Takes a range as input and returns the entire range
+class range_same : public range_result{
+ public:
+ range_same(){}
+
+ template<std::size_t in_size>
+ struct result_size{
+ typedef mpl::size_t<in_size> type;
+ };
+
+ template<typename R>
+ typename sub_range<R>::type
+ operator()(R& range)const{
+ typedef sub_range<R> result_type;
+ return result_type (begin(range),end(range));
+ };
+};
+
+}
+#endif
Added: sandbox/miscellanea_iterator_facade/boost/iterator/skip_one_step_iterator.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/boost/iterator/skip_one_step_iterator.hpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,115 @@
+//////////////////////////////////////////////////////////////////////////////
+// skip_one_step_iterator.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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_ITERATOR_SKIP_ONE_STEP_ITERATOR_HPP_ER2009
+#define BOOST_ITERATOR_SKIP_ONE_STEP_ITERATOR_HPP_ER2009
+#include <iterator>
+#include <stdexcept>
+#include <boost/iterator/iterator_adaptor.hpp>
+#include <boost/range.hpp>
+#include <boost/assert.hpp>
+#include <boost/type_traits.hpp>
+namespace boost{
+
+/// Traverses elements of a sequences, skipping a subsequence
+template<typename BaseIter>
+class skip_one_step_iterator
+ : public iterator_adaptor<
+ skip_one_step_iterator<BaseIter>,
+ BaseIter>
+{
+ typedef iterator_adaptor<
+ skip_one_step_iterator<BaseIter>,
+ BaseIter> super_type;
+ public:
+
+ skip_one_step_iterator(){}
+
+ explicit skip_one_step_iterator(
+ BaseIter i,
+ BaseIter skip
+ )
+ :base_iter(i),skip_(skip){
+ if(base_is_skip()){
+ throw std::runtime_error(
+ "skip_one_step_iterator: base_is_skip at construction"
+ );
+ }
+ }
+
+ //TODO copy constructor?
+
+ private:
+
+ friend class boost::iterator_core_access;
+
+ typename super_type::difference_type
+ distance_to(skip_one_step_iterator const& other) const{
+ typedef typename super_type::difference_type difference_type;
+
+ difference_type d = std::distance(this->base_iter,other.base_iter);
+ difference_type dist_this
+ = std::distance(this->base_iter,skip_);
+ difference_type dist_other
+ = std::distance(other.base_iter,skip_);
+ bool same_sign = ((dist_this<0) && (dist_other<0))
+ || ((dist_this>0) && (dist_other>0));
+ if(!same_sign){
+ if(d<(difference_type)(0)){
+ d+=(difference_type)(1);
+ }else{
+ d-=(difference_type)(1);
+ }
+ }
+ return d;
+ }
+
+ bool equal(skip_one_step_iterator const& other) const
+ {
+ return this->base_iter == other.base_iter;
+ }
+
+ void advance(typename super_type::difference_type n)
+ {
+ std::advance(this->base_iter,1);
+ if(base_is_skip()){
+ std::advance(this->base_iter,1);
+ }
+ }
+
+ typename super_type::reference dereference() const {
+ return *base_iter; }
+
+ void increment(){
+ advance((typename super_type::difference_type)(1)); }
+ //void decrement();
+
+ bool base_is_skip()const{
+ return ((this->base_iter)==(this->skip_)); }
+ BaseIter base_iter;
+ BaseIter skip_;
+};
+
+template<typename Iter>
+skip_one_step_iterator<Iter>
+make_skip_one_step_begin_iterator(Iter b,Iter skip){
+ Iter new_b = b;
+ if(new_b == skip){
+ std::advance(new_b,1); }
+ return skip_one_step_iterator<Iter>(new_b,skip);
+};
+
+template<typename Iter>
+skip_one_step_iterator<Iter>
+make_skip_one_step_end_iterator(Iter e,Iter skip){
+ // constructor below will throw if skip == e
+ return skip_one_step_iterator<Iter>(e,skip);
+};
+
+
+
+}
+#endif
Added: sandbox/miscellanea_iterator_facade/boost/iterator/skip_range_iterator.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/boost/iterator/skip_range_iterator.hpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,123 @@
+//////////////////////////////////////////////////////////////////////////////
+// skip_range_iterator.hpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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_ITERATOR_SKIP_RANGE_ITERATOR_HPP_ER2009
+#define BOOST_ITERATOR_SKIP_RANGE_ITERATOR_HPP_ER2009
+#include <iterator>
+#include <stdexcept>
+#include <boost/iterator/iterator_facade.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/range.hpp>
+#include <boost/assert.hpp>
+namespace boost{
+
+/// Traverses all elements of a sequence except a specified
+/// range
+template<typename BaseIter>
+class skip_range_iterator
+ : public iterator_facade<
+ skip_range_iterator<BaseIter>
+ , typename iterator_value<BaseIter>::type
+ , typename iterator_category<BaseIter>::type
+ >
+{
+ typedef iterator_range<BaseIter> iterator_range_type;
+ typedef iterator_facade<
+ skip_range_iterator<BaseIter>
+ , typename iterator_value<BaseIter>::type
+ , typename iterator_category<BaseIter>::type
+ > super_type;
+
+ public:
+ typedef typename super_type::difference_type difference_type;
+ typedef typename super_type::reference reference;
+
+ skip_range_iterator(){}
+
+ explicit skip_range_iterator(
+ BaseIter i,
+ iterator_range_type skip_range
+ )
+ :base_iter(i),skip_range_(skip_range){
+ if(is_in_skip_range()){
+ throw std::runtime_error(
+ "skip_range_iterator: is_in_skip_range at construction"
+ );
+ }
+ }
+
+ private:
+
+ friend class boost::iterator_core_access;
+
+ void increment() { advance((difference_type)(1)); }
+
+ difference_type distance_to(skip_range_iterator const& other) const{
+ difference_type d = std::distance(this->base_iter,other.base_iter);
+ difference_type dist_this
+ = std::distance(this->base_iter,begin(skip_range_));
+ difference_type dist_other
+ = std::distance(other.base_iter,begin(skip_range_));
+ bool same_sign = ((dist_this<0) && (dist_other<0))
+ || ((dist_this>0) && (dist_other>0))
+ || (size(skip_range_)==0);
+ if(!same_sign){
+ if(d<(difference_type)(0)){
+ d+=(difference_type)(boost::size(skip_range_));
+ }else{
+ d-=(difference_type)(boost::size(skip_range_));
+ }
+ }
+ return d;
+ }
+
+ bool equal(skip_range_iterator const& other) const
+ {
+ return this->base_iter == other.base_iter;
+ }
+
+ reference dereference() const { return *base_iter; }
+
+ void advance(difference_type n)
+ {
+ difference_type dist_before
+ = std::distance(this->base_iter,begin(skip_range_));
+ std::advance(this->base_iter,n);
+
+ if(size(skip_range_)>0){
+ if(dist_before>0){
+ difference_type dist_after
+ = std::distance(this->base_iter,begin(skip_range_));
+ if(dist_after<=0){
+ std::advance(this->base_iter,size(skip_range_));
+ }
+ }
+ }
+
+ BOOST_ASSERT(!is_in_skip_range());
+ }
+
+ bool is_in_skip_range()const{
+ bool res = false;
+ if(size(skip_range_)>0){
+ difference_type d_to_first
+ = std::distance(this->base_iter,begin(skip_range_));
+ if(d_to_first<=0){
+ difference_type d_to_end
+ = std::distance(this->base_iter,end(skip_range_));
+ if(d_to_end>0){
+ res = true;
+ }
+ }
+ }
+ return res;
+ }
+ BaseIter base_iter;
+ iterator_range_type skip_range_;
+};
+
+}
+#endif
Added: sandbox/miscellanea_iterator_facade/boost/iterator/vector2matrix_iterator.hpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/boost/iterator/vector2matrix_iterator.hpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,111 @@
+//////////////////////////////////////////////////////////////////////////////
+// vector2matrix_iterator.hpp
+// (C) Copyright 2009 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_ITERATOR_VECTOR2MATRIX_ITERATOR_HPP_ER_2009
+#define BOOST_ITERATOR_VECTOR2MATRIX_ITERATOR_HPP_ER_2009
+#include <iterator>
+#include <algorithm>
+#include <cmath>
+#include <iostream>
+#include <boost/iterator/iterator_facade.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/range.hpp>
+#include <boost/assert.hpp>
+namespace boost{
+
+/// Takes an iterator to a sequence and makes it into an iterator
+/// over the rows of matrix
+/// i.e. ++vector2matrix_iterator moves on row down.
+template<
+ typename BaseIter,
+ typename Categ = typename iterator_category<BaseIter>::type,
+ typename Diff = typename iterator_difference<BaseIter>::type>
+class vector2matrix_iterator
+ : public iterator_facade<
+ vector2matrix_iterator<BaseIter>
+ , iterator_range<BaseIter>
+ , Categ
+ , iterator_range<BaseIter>
+ , Diff
+ >
+{//TODO iterator_adaptor instead of facade?
+ public:
+ vector2matrix_iterator(){}
+
+ explicit vector2matrix_iterator(BaseIter i,std::size_t stride)
+ :stride_(stride),base_iter(i){}
+ vector2matrix_iterator(const vector2matrix_iterator& that)
+ :stride_(that.stride_),base_iter(that.base_iter){}
+ vector2matrix_iterator& operator=(const vector2matrix_iterator& that){
+ if(&that!=this){
+ stride_ = that.stride_;
+ base_iter = that.base_iter;
+ }
+ return *this;
+ }
+
+ BaseIter base(){return base_iter;}
+ std::size_t stride()const{return stride_;}
+ private:
+ typedef iterator_range<BaseIter> Value;
+
+ friend class iterator_core_access;
+
+ void increment() { std::advance(this->base_iter,stride_); }
+
+ Diff distance_to(vector2matrix_iterator const& other) const{
+ Diff d = std::distance(this->base_iter,other.base_iter);
+ d/=(Diff)(stride());
+ return d;
+ };
+
+ bool equal(vector2matrix_iterator const& other) const
+ {
+ return this->base_iter == other.base_iter;
+ }
+
+ Value dereference() const {
+ //Value& inappropriate as result is local
+ BaseIter i = this->base_iter;
+ std::advance(i,stride_);
+ return make_iterator_range(this->base_iter,i);
+ }
+
+ void advance(Diff n)
+ {
+ std::advance(this->base_iter, n*stride());
+ }
+
+ std::size_t stride_;
+ BaseIter base_iter;
+};
+
+template<typename BaseIter>
+vector2matrix_iterator<BaseIter>
+make_end_vector2matrix_iterator(BaseIter b,BaseIter e,std::size_t stride){
+ //BOOST_ASSERT(std::distance(b,e)>0);
+ BOOST_ASSERT( ( std::distance(b,e)>0 ) || ( std::distance(b,e)==0 ) );
+ BaseIter ee = e;
+ //std::size_t d = (std::size_t)(std::distance(b,ee)-1)/stride;
+
+ std::size_t d = (std::size_t)(std::distance(b,ee))/stride;
+ d *= stride;
+ //ee = b; std::advance(ee,d+1);
+ ee = b; std::advance(ee,d);
+
+ return vector2matrix_iterator<BaseIter>(ee,stride);
+}
+
+template<typename BaseIter>
+vector2matrix_iterator<BaseIter>
+make_vector2matrix_iterator(BaseIter b,std::size_t stride){
+ return vector2matrix_iterator<BaseIter>(b,stride);
+}
+
+
+}
+
+#endif
Added: sandbox/miscellanea_iterator_facade/libs/iterator/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/libs/iterator/doc/readme.txt 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,216 @@
+//////////////////////////////////////////////////////////////////////////////
+// miscellanea_iterator_facade
+//
+// (C) Copyright 2009 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)
+///////////
+/ Contact /
+///////////
+
+Please send questions or suggestions to erwann.rogard_at_[hidden]
+
+/////////////
+/ Overview /
+/////////////
+
+This collection of C++ classes are iterators that derive from iterator_facade,
+ or ranges thereof.
+
+Warning: these were designed for very specific applications and have very few
+safeguards.
+
+//////////////////
+/ Requirements /
+//////////////////
+
+Compiles fine under
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490)
+
+The compiler search path must include
+boost_1_37_0
+
+////////////////////////
+/ Output from main.cpp /
+////////////////////////
+
+->example_vector2matrix
+0 1 2 3 4 5 6 7
+std::distance(b,e)=0
+std::distance(b,e)=0
+std::distance(b,e)=1
+std::distance(b,e)=1
+std::distance(b,e)=2
+std::distance(b,e)=2
+std::distance(b,e)=3
+std::distance(b,e)=3
+exited loop
+<-
+->example_skip_range_iterator
+i=1
+ j=1
+ 0 1 2 3 4 5 6 7 8 9
+ j=2
+ 0 2 3 4 5 6 7 8 9
+ j=3
+ 0 3 4 5 6 7 8 9
+ j=4
+ 0 4 5 6 7 8 9
+ j=5
+ 0 5 6 7 8 9
+ j=6
+ 0 6 7 8 9
+ j=7
+ 0 7 8 9
+ j=8
+ 0 8 9
+ j=9
+ 0 9
+ j=10
+ 0
+i=2
+ j=2
+ 0 1 2 3 4 5 6 7 8 9
+ j=3
+ 0 1 3 4 5 6 7 8 9
+ j=4
+ 0 1 4 5 6 7 8 9
+ j=5
+ 0 1 5 6 7 8 9
+ j=6
+ 0 1 6 7 8 9
+ j=7
+ 0 1 7 8 9
+ j=8
+ 0 1 8 9
+ j=9
+ 0 1 9
+ j=10
+ 0 1
+i=3
+ j=3
+ 0 1 2 3 4 5 6 7 8 9
+ j=4
+ 0 1 2 4 5 6 7 8 9
+ j=5
+ 0 1 2 5 6 7 8 9
+ j=6
+ 0 1 2 6 7 8 9
+ j=7
+ 0 1 2 7 8 9
+ j=8
+ 0 1 2 8 9
+ j=9
+ 0 1 2 9
+ j=10
+ 0 1 2
+i=4
+ j=4
+ 0 1 2 3 4 5 6 7 8 9
+ j=5
+ 0 1 2 3 5 6 7 8 9
+ j=6
+ 0 1 2 3 6 7 8 9
+ j=7
+ 0 1 2 3 7 8 9
+ j=8
+ 0 1 2 3 8 9
+ j=9
+ 0 1 2 3 9
+ j=10
+ 0 1 2 3
+i=5
+ j=5
+ 0 1 2 3 4 5 6 7 8 9
+ j=6
+ 0 1 2 3 4 6 7 8 9
+ j=7
+ 0 1 2 3 4 7 8 9
+ j=8
+ 0 1 2 3 4 8 9
+ j=9
+ 0 1 2 3 4 9
+ j=10
+ 0 1 2 3 4
+i=6
+ j=6
+ 0 1 2 3 4 5 6 7 8 9
+ j=7
+ 0 1 2 3 4 5 7 8 9
+ j=8
+ 0 1 2 3 4 5 8 9
+ j=9
+ 0 1 2 3 4 5 9
+ j=10
+ 0 1 2 3 4 5
+i=7
+ j=7
+ 0 1 2 3 4 5 6 7 8 9
+ j=8
+ 0 1 2 3 4 5 6 8 9
+ j=9
+ 0 1 2 3 4 5 6 9
+ j=10
+ 0 1 2 3 4 5 6
+i=8
+ j=8
+ 0 1 2 3 4 5 6 7 8 9
+ j=9
+ 0 1 2 3 4 5 6 7 9
+ j=10
+ 0 1 2 3 4 5 6 7
+i=9
+ j=9
+ 0 1 2 3 4 5 6 7 8 9
+ j=10
+ 0 1 2 3 4 5 6 7 8
+i=10
+ j=10
+ 0 1 2 3 4 5 6 7 8 9
+<-
+->example_skip_one_step_iterator
+i=1
+ 0 2 3 4 5 6 7 8 9
+i=2
+ 0 1 3 4 5 6 7 8 9
+i=3
+ 0 1 2 4 5 6 7 8 9
+i=4
+ 0 1 2 3 5 6 7 8 9
+i=5
+ 0 1 2 3 4 6 7 8 9
+i=6
+ 0 1 2 3 4 5 7 8 9
+i=7
+ 0 1 2 3 4 5 6 8 9
+i=8
+ 0 1 2 3 4 5 6 7 9
+i=9
+ 0 1 2 3 4 5 6 7 8
+<-
+->example_skip_one_step_iterator
+i=1
+ 0 2 3 4 5 6 7 8 9
+i=2
+ 0 1 3 4 5 6 7 8 9
+i=3
+ 0 1 2 4 5 6 7 8 9
+i=4
+ 0 1 2 3 5 6 7 8 9
+i=5
+ 0 1 2 3 4 6 7 8 9
+i=6
+ 0 1 2 3 4 5 7 8 9
+i=7
+ 0 1 2 3 4 5 6 8 9
+i=8
+ 0 1 2 3 4 5 6 7 9
+i=9
+ 0 1 2 3 4 5 6 7 8
+<-
+->example_skip_one_step_iterator
+1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 <-
+->example_subset_of_range
+<-
Added: sandbox/miscellanea_iterator_facade/libs/iterator/src/example/insert_element_every_n_step_iterator.cpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/libs/iterator/src/example/insert_element_every_n_step_iterator.cpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,72 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/insert_element_every_n_step_iterator.cpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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)
+#include <iostream>
+#include <vector>
+#include <iterator>
+#include <functional>
+#include <boost/assert.hpp>
+#include <boost/range.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/iterator/insert_element_every_n_step_iterator.hpp>
+#include <libs/iterator/src/example/insert_element_every_n_step_iterator.h>
+
+void example_insert_element_every_n_step_iterator(){
+
+ std::cout << "->example_skip_one_step_iterator" << std::endl;
+ using namespace boost;
+ typedef double value_type;
+ typedef std::vector<value_type> vector_type;
+ typedef range_iterator<vector_type>::type base_iter_type;
+ typedef vector_type::size_type size_type;
+
+ vector_type vec(10,0);
+
+ typedef boost::insert_element_every_n_step_iterator<base_iter_type>
+ iter_type;
+ value_type x = 1;
+ size_type n = 2;
+
+
+ base_iter_type base_b = begin(vec);
+ iter_type b(base_b,x,n);
+ iter_type i(b);
+ std::advance(i,n+1);
+ BOOST_ASSERT( distance(b,i) == 3);
+ BOOST_ASSERT( (*i) == 1);
+ ++i;
+ BOOST_ASSERT( distance(b,i) == 4);
+ BOOST_ASSERT( (*i) == 0);
+
+
+ vector_type out;
+ copy(
+ make_begin_insert_element_every_n_step_iterator(
+ begin(vec),
+ x, n
+ ),
+ make_end_insert_element_every_n_step_iterator(
+ begin(vec),
+ end(vec),
+ x, n
+ ),
+ back_inserter(out)
+ ); //should end in 1,0,0
+ base_iter_type base_i = end(out);
+
+ BOOST_ASSERT((*(--base_i))==0);
+ BOOST_ASSERT((*(--base_i))==0);
+ BOOST_ASSERT((*(--base_i))==1);
+
+ copy(
+ begin(out),
+ end(out),
+ std::ostream_iterator<value_type>(std::cout, " ")
+ );
+
+ std::cout << "<-" << std::endl;
+
+};
Added: sandbox/miscellanea_iterator_facade/libs/iterator/src/example/insert_element_every_n_step_iterator.h
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/libs/iterator/src/example/insert_element_every_n_step_iterator.h 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,10 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/insert_element_every_n_step.h
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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 LIBS_ITERATOR_INSERT_ELEMENT_EVERY_N_STEP_H_ER_2009
+#define LIBS_ITERATOR_INSERT_ELEMENT_EVERY_N_STEP_H_ER_2009
+void example_insert_element_every_n_step_iterator();
+#endif
Added: sandbox/miscellanea_iterator_facade/libs/iterator/src/example/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/libs/iterator/src/example/main.cpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,20 @@
+///////////////////////////////////////////////////////////////////////////////
+// main.cpp
+// (C) Copyright 2009 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)
+#include <libs/iterator/src/example/skip_range_iterator.h>
+#include <libs/iterator/src/example/vector2matrix.h>
+#include <libs/iterator/src/example/skip_one_step_iterator.h>
+#include <libs/iterator/src/example/insert_element_every_n_step_iterator.h>
+#include <libs/iterator/src/example/subset_of_range.h>
+int main(){
+ example_vector2matrix();
+ example_skip_range_iterator();
+ example_skip_one_step_iterator();
+ example_skip_one_step_iterator();
+ example_insert_element_every_n_step_iterator();
+ example_subset_of_range();
+ return 0;
+}
Added: sandbox/miscellanea_iterator_facade/libs/iterator/src/example/skip_one_step_iterator.cpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/libs/iterator/src/example/skip_one_step_iterator.cpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,57 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/skip_one_step_iterator.cpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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)
+#include <iostream>
+#include <vector>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/iterator/skip_one_step_iterator.hpp>
+#include <libs/iterator/src/example/skip_one_step_iterator.h>
+
+
+template<typename R>
+//void func(R& range,std::size_t i){//fine
+ //typedef R range_type;//fine
+void func(const R& range,std::size_t i){//fails
+ typedef const R range_type;//fails
+ typedef typename boost::range_iterator<range_type>::type iter_type;
+ typedef boost::skip_one_step_iterator<iter_type> skipr_iter_type;
+ iter_type b = boost::begin(range);
+ iter_type e = boost::end(range);
+ iter_type skip = b;
+ std::advance(skip,i);
+ skipr_iter_type sb = boost::make_skip_one_step_begin_iterator(b,skip);
+ skipr_iter_type se = boost::make_skip_one_step_end_iterator(e,skip);
+ copy(
+ sb,
+ se,
+ std::ostream_iterator<double>(std::cout<<" "," ")
+ ); std::cout << std::endl;
+};
+
+void example_skip_one_step_iterator(){
+ std::cout << "->example_skip_one_step_iterator" << std::endl;
+ using namespace boost;
+ typedef std::vector<double> vector_type;
+ typedef vector_type::size_type size_type;
+
+ vector_type vec;
+ {
+ using namespace boost::assign;
+ vec += 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0;
+ }
+
+
+ //invalid initialization of reference of type âdouble&â from expression of
+ // type âconst doubleâ|
+ //this error disappears if range_type replaced by R in definition of func
+ for(size_type i = 1; i < size(vec); i++){
+ std::cout << "i=" << i << std::endl;
+ func(vec,i);
+ }
+ std::cout << "<-" << std::endl;
+};
Added: sandbox/miscellanea_iterator_facade/libs/iterator/src/example/skip_one_step_iterator.h
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/libs/iterator/src/example/skip_one_step_iterator.h 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,10 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/skip_one_step_iterator.h
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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 LIBS_ITERATOR_SKIP_ONE_STEP_ITERATOR_H_ER2009
+#define LIBS_ITERATOR_SKIP_ONE_STEP_ITERATOR_H_ER2009
+void example_skip_one_step_iterator();
+#endif
Added: sandbox/miscellanea_iterator_facade/libs/iterator/src/example/skip_range_iterator.cpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/libs/iterator/src/example/skip_range_iterator.cpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,58 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/skip_range_iterator.cpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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)
+#include <iostream>
+#include <vector>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/iterator/skip_range_iterator.hpp>
+#include <libs/iterator/src/example/skip_range_iterator.h>
+
+
+void example_skip_range_iterator(){
+ std::cout << "->example_skip_range_iterator" << std::endl;
+ using namespace boost;
+ typedef std::vector<double> vector_type;
+ typedef vector_type::size_type size_type;
+ //TODO replacing vector_type by const vector_type
+ //causes:
+ //invalid initialization of reference of type âdouble&â
+ //from expression of type âconst doubleâ|
+ typedef range_iterator<vector_type>::type iter_type;
+ typedef iterator_range<iter_type>::type ir_type;
+ typedef skip_range_iterator<iter_type> skipr_iter_type;
+
+ vector_type vec;
+ {
+ using namespace boost::assign;
+ vec += 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0;
+ }
+
+ iter_type b = begin(vec);
+ iter_type e = end(vec);
+ vector_type::size_type sz = size(vec);
+ for(size_type i = 1; i <= sz; i++){
+ std::cout << "i=" << i << std::endl;
+ for(size_type j = i; j<=sz; j++)
+ {
+ std::cout << " j=" << j << std::endl;
+ iter_type k = b;
+ iter_type l = b;
+ std::advance(k,i);
+ std::advance(l,j);
+ ir_type ri0(k,l);
+ skipr_iter_type skipr_b(b,ri0);
+ skipr_iter_type skipr_e(e,ri0);
+ copy(
+ skipr_b,
+ skipr_e,
+ std::ostream_iterator<double>(std::cout<<" "," ")
+ ); std::cout << std::endl;
+ }
+ }
+ std::cout << "<-" << std::endl;
+};
Added: sandbox/miscellanea_iterator_facade/libs/iterator/src/example/skip_range_iterator.h
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/libs/iterator/src/example/skip_range_iterator.h 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,10 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/skip_range_iterator.h
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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 LIBS_ITERATOR_SKIP_RANGE_H_ER2009
+#define LIBS_ITERATOR_SKIP_RANGE_H_ER2009
+void example_skip_range_iterator();
+#endif
Added: sandbox/miscellanea_iterator_facade/libs/iterator/src/example/subset_of_range.cpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/libs/iterator/src/example/subset_of_range.cpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,76 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/subset_of_range.cpp
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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)
+#include <iostream>
+#include <vector>
+#include <boost/range.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/iterator/range_result.hpp>
+#include <boost/iterator/range_same.hpp>
+#include <boost/iterator/range_left.hpp>
+#include <boost/iterator/range_right.hpp>
+#include <boost/iterator/range_middle.hpp>
+#include <boost/iterator/range_result_size.hpp>
+#include <libs/iterator/src/example/subset_of_range.h>
+
+
+void example_subset_of_range(){
+ std::cout << "->example_subset_of_range " << std::endl;
+ using namespace boost;
+
+ typedef double value_type;
+ typedef std::vector<value_type> vec_type;
+ vec_type vec0;
+ const std::size_t in_size = 4;
+
+ {
+ using namespace boost::assign;
+ vec0+=0.1,-0.2, 0.3, -0.4;
+ }
+
+ const vec_type vec = vec0;
+
+ typedef mpl::size_t<2> size_2;
+ typedef mpl::size_t<3> size_3;
+ typedef mpl::size_t<4> size_4;
+
+ typedef range_same range_same_type;
+ typedef range_left<3> left_range_type;
+ typedef range_right<3> right_range_type;
+ typedef range_middle<1,2> middle_range_type;
+
+ typedef range_result_size<range_same_type,in_size>::type
+ same_result_size_type;
+ typedef range_result_size<left_range_type,in_size>::type
+ left_result_size_type;
+ typedef range_result_size<right_range_type,in_size>::type
+ right_result_size_type;
+ typedef range_result_size<middle_range_type,in_size>::type
+ middle_result_size_type;
+
+ BOOST_MPL_ASSERT((
+ is_same<same_result_size_type,size_4>
+ ));
+ BOOST_MPL_ASSERT((
+ is_same<left_result_size_type,size_3>
+ ));
+ BOOST_MPL_ASSERT((
+ is_same<right_result_size_type,size_3>
+ ));
+ BOOST_MPL_ASSERT((
+ is_same<middle_result_size_type,size_2>
+ ));
+
+ BOOST_ASSERT(size(range_same_type()(vec))==4);
+ BOOST_ASSERT(size(left_range_type()(vec))==3);
+ BOOST_ASSERT(*begin(left_range_type()(vec))==0.1);
+ BOOST_ASSERT(size(right_range_type()(vec))==3);
+ BOOST_ASSERT(*begin(right_range_type()(vec))==-0.2);
+ BOOST_ASSERT(size(middle_range_type()(vec))==2);
+ BOOST_ASSERT(*begin(middle_range_type()(vec))==-0.2);
+ std::cout << "<-" << std::endl;
+};
Added: sandbox/miscellanea_iterator_facade/libs/iterator/src/example/subset_of_range.h
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/libs/iterator/src/example/subset_of_range.h 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,10 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/subset_of_range.h
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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 LIBS_ITERATOR_EXAMPLE_SUBSET_OF_RANGE_H_ER_2009
+#define LIBS_ITERATOR_EXAMPLE_SUBSET_OF_RANGE_H_ER_2009
+void example_subset_of_range();
+#endif
Added: sandbox/miscellanea_iterator_facade/libs/iterator/src/example/vector2matrix.cpp
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/libs/iterator/src/example/vector2matrix.cpp 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,119 @@
+///////////////////////////////////////////////////////////////////////////////
+// example/vector2matrix.cpp
+// (C) Copyright 2009 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)
+#include <vector>
+#include <list>
+#include <algorithm>
+#include <iterator>
+#include <iostream>//TODO remove
+#include <boost/assign/std/vector.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/iterator/vector2matrix_iterator.hpp>
+#include <libs/iterator/src/example/vector2matrix.h>
+
+void example_vector2matrix()
+{
+ std::cout << "->example_vector2matrix" << std::endl;
+ int stride = 2;
+ typedef std::vector<int> vec_type;
+
+ {
+ typedef vec_type::const_iterator CVecIter;
+ typedef boost::vector2matrix_iterator<CVecIter> Vec2MatIter;
+ typedef boost::vector2matrix_iterator<CVecIter> Vec2MatIter;
+
+ vec_type vec;
+ vec_type vecc;
+ {using namespace boost::assign; vec+=0,1,2,3,4,5,6,7,8;}
+ //important to use the const qualifier
+ CVecIter base_b = boost::begin(vec);
+ CVecIter base_e = boost::end(vec);
+ Vec2MatIter b(base_b,stride); Vec2MatIter i = b;
+ Vec2MatIter e=boost::make_end_vector2matrix_iterator(
+ base_b,base_e,stride);
+ while(i<e){
+ Vec2MatIter::value_type r = *i;
+ copy(boost::begin(r),boost::end(r),back_inserter(vecc));
+ ++i;
+ }
+ copy(
+ boost::begin(vecc),
+ boost::end(vecc),
+ std::ostream_iterator<int>(std::cout," ")
+ );std::cout<<std::endl;//should return 0,1,...,7
+ }
+
+ {
+ typedef vec_type::const_iterator CVecIter;
+ typedef boost::vector2matrix_iterator<CVecIter> Vec2MatIter;
+ typedef boost::vector2matrix_iterator<CVecIter> Vec2MatIter;
+
+ vec_type vec,vec_a;
+ { using namespace boost::assign; vec+=0,1,2,3,4,5,6,7; }
+ CVecIter base_b = boost::begin(vec);
+ CVecIter base_e = boost::end(vec);
+ Vec2MatIter b(base_b,stride);
+ for(CVecIter base_i = base_b; base_i<base_e; base_i++){
+ Vec2MatIter e = boost::make_end_vector2matrix_iterator(
+ base_b,base_i,stride
+ );
+ std::cout << "std::distance(b,e)="
+ << std::distance(b,e) << std::endl; //TODO problem here
+ } std::cout << "exited loop" << std::endl;
+ }
+
+
+// {
+// vec_type vec,vec_a;
+// { using namespace boost::assign; vec+=0,1,2,3,4,5,6,7; vec_a+=4,5;}
+// boost::nearest_neighbor<vec_type>::result_type res
+// = boost::make_nearest_neighbor(vec)(vec_a);
+// copy(
+// boost::begin(*res),
+// boost::end(*res),
+// std::ostream_iterator<int>(std::cout," ")
+// );
+// }
+/*
+ {
+ typedef std::list<int> list_type;
+ typedef list_type::const_iterator CListIter;
+ typedef boost::vector2matrix_iterator<CListIter> List2MatIter;
+ list_type lst;
+ list_type lstc;
+ {
+ lst.push_back(0);
+ lst.push_back(1);//1
+ lst.push_back(2);
+ lst.push_back(3);//2
+ lst.push_back(4);
+ lst.push_back(5);//3
+ lst.push_back(6);
+ lst.push_back(7);//4
+ lst.push_back(8);
+ }
+
+ //important to use the const qualifier
+ CListIter base_b = boost::begin(lst);
+ CListIter base_e = boost::end(lst);
+ List2MatIter i(base_b,stride);
+ List2MatIter e=boost::make_end_vector2matrix_iterator(
+ base_b,base_e,stride);
+
+ while(i<e){
+ List2MatIter::value_type r = *i;
+ copy(boost::begin(r),boost::end(r),back_inserter(lstc));
+ ++i;
+ }
+ copy(
+ boost::begin(lstc),
+ boost::end(lstc),
+ std::ostream_iterator<int>(std::cout," ")
+ );
+ }
+*/
+ std::cout << "<-" << std::endl;
+}
Added: sandbox/miscellanea_iterator_facade/libs/iterator/src/example/vector2matrix.h
==============================================================================
--- (empty file)
+++ sandbox/miscellanea_iterator_facade/libs/iterator/src/example/vector2matrix.h 2009-02-06 15:24:34 EST (Fri, 06 Feb 2009)
@@ -0,0 +1,10 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/vector2matrix.h
+//
+// Copyright 2009 Erwann Rogard. Distributed under 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 VECTOR2MATRIX_H_ER_2009
+#define VECTOR2MATRIX_H_ER_2009
+void example_vector2matrix();
+#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