diff --git a/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/iota.html b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/iota.html new file mode 100644 index 0000000..c36f96d --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/iota.html @@ -0,0 +1,96 @@ + + + +iota + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+
+ + iota +
+
+ + Prototype +
+

+ +

+
template<class SinglePassRange, class Value>
+iota(SinglePassRange& rng, Value x);
+
+

+

+
+ + Description +
+

+ iota traverses forward + through rng, each element + y in rng + is assigned a value equivalent to x + + boost::distance(boost::begin(rng), it) +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm_ext/iota.hpp +

+
+ + Requirements +
+
    +
  1. +SinglePassRange is + a model of the Single + Pass Range Concept. +
  2. +
  3. +Value is a model of + the Incrementable Concept. +
  4. +
+
+ + Complexity +
+

+ Linear. Exactly distance(rng) assignments into rng. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/include/boost/range/adaptor/adjacent_filtered.hpp b/include/boost/range/adaptor/adjacent_filtered.hpp index 4a7a809..5f66711 100644 --- a/include/boost/range/adaptor/adjacent_filtered.hpp +++ b/include/boost/range/adaptor/adjacent_filtered.hpp @@ -30,94 +30,58 @@ namespace boost namespace range_detail { - template< class Iter, class R > + template< class Iter, class Pred, bool default_pass > class skip_iterator - : public boost::iterator_adaptor< skip_iterator, Iter > + : public boost::iterator_adaptor< + skip_iterator, + Iter, + BOOST_DEDUCED_TYPENAME std::iterator_traits::value_type, + boost::forward_traversal_tag, + BOOST_DEDUCED_TYPENAME std::iterator_traits::reference, + BOOST_DEDUCED_TYPENAME std::iterator_traits::difference_type + > + , private Pred { private: - typedef boost::iterator_adaptor< skip_iterator, Iter > - base_t; - - R* m_range; + typedef boost::iterator_adaptor< + skip_iterator, + Iter, + BOOST_DEDUCED_TYPENAME std::iterator_traits::value_type, + boost::forward_traversal_tag, + BOOST_DEDUCED_TYPENAME std::iterator_traits::reference, + BOOST_DEDUCED_TYPENAME std::iterator_traits::difference_type + > base_t; public: - typedef Iter wrapped_iter_t; + typedef Pred pred_t; + typedef Iter iter_t; - // - // The iterators are bound to the lifetime of the - // range and may not exist on their own. Hence it makes no - // sense to e.g. wrap them in reverse_iterators - // (that can OTOH be done in advance). - // - typedef std::input_iterator_tag iterator_category; + skip_iterator() : m_last() {} - explicit skip_iterator( R* r, Iter i ) - : base_t(i), m_range(r) {} - - template< class OtherIter, class R2> - skip_iterator( const skip_iterator& other ) - : base_t( other.base() ), m_range(other.m_range) {} - - R* get_range() const { return m_range; } - - private: - friend class boost::iterator_core_access; - - void increment() - { - BOOST_ASSERT( m_range != 0 ); - m_range->increment_impl( this->base_reference() ); - } - - // - // Not needed ... just apply a reverse_iterator - // - void decrement() + skip_iterator(iter_t it, iter_t last, const Pred& pred) + : base_t(it) + , pred_t(pred) + , m_last(last) { - BOOST_ASSERT( false && "you can't decrement an adjacent_filter_iterator" ); + move_to_next_valid(); } - template< class D > - void advance( D n ) - { - BOOST_ASSERT( false ); - } + template + skip_iterator( const skip_iterator& other ) + : base_t(other.base()) + , pred_t(other) + , m_last(other.m_last) {} - }; - - template< class P, class R > - struct adjacent_filter_range - : iterator_range< skip_iterator< - BOOST_DEDUCED_TYPENAME range_iterator::type, - adjacent_filter_range - > - > - { - private: - typedef skip_iterator< - BOOST_DEDUCED_TYPENAME range_iterator::type, - adjacent_filter_range - > - skip_iter; - typedef iterator_range - base_range; - - typedef BOOST_DEDUCED_TYPENAME range_iterator::type raw_iterator; - - P m_bi_pred; - - // Get the first element in the half-open range that - // passes the filter predicate. - // The adjacent_filter_range must only contain values that pass - // through the filter. - static raw_iterator to_valid(raw_iterator it, raw_iterator last, const P& bi_pred, bool default_pass) + void move_to_next_valid() { - if (it != last) + iter_t& it = this->base_reference(); + pred_t& bi_pred = *this; + if (it != m_last) { if (default_pass) { - raw_iterator nxt = ::boost::next(it); - while (nxt != last && !bi_pred(*it, *nxt)) + iter_t nxt = ::boost::next(it); + while (nxt != m_last && !bi_pred(*it, *nxt)) { ++it; ++nxt; @@ -125,41 +89,61 @@ namespace boost } else { - raw_iterator nxt = ::boost::next(it); - for(; nxt != last; ++it, ++nxt) + iter_t nxt = ::boost::next(it); + for(; nxt != m_last; ++it, ++nxt) { if (bi_pred(*it, *nxt)) { break; } } - if (nxt == last) + if (nxt == m_last) { - it = last; + it = m_last; } } } - return it; } + void increment() + { + iter_t& it = this->base_reference(); + BOOST_ASSERT( it != m_last ); + ++it; + move_to_next_valid(); + } + + iter_t m_last; + }; + + template< class P, class R, bool default_pass > + struct adjacent_filter_range + : iterator_range< skip_iterator< + BOOST_DEDUCED_TYPENAME range_iterator::type, + P, + default_pass + > + > + { + private: + typedef skip_iterator< + BOOST_DEDUCED_TYPENAME range_iterator::type, + P, + default_pass + > + skip_iter; + + typedef iterator_range + base_range; + + typedef BOOST_DEDUCED_TYPENAME range_iterator::type raw_iterator; + public: - adjacent_filter_range( const P& p, R& r, bool default_pass ) - : base_range( skip_iter( this, to_valid(boost::begin(r), boost::end(r), p, default_pass)), - skip_iter( this, boost::end(r) ) ), - m_bi_pred( p ), - m_default_pass(default_pass) + adjacent_filter_range( const P& p, R& r ) + : base_range( skip_iter( boost::begin(r), boost::end(r), p), + skip_iter( boost::end(r), boost::end(r), p) ) { } - - void increment_impl( raw_iterator& current ) - { - BOOST_ASSERT( current != this->end().base() ); - - current = to_valid(::boost::next(current), this->end().base(), m_bi_pred, m_default_pass); - } - - private: - bool m_default_pass; }; template< class T > @@ -177,37 +161,37 @@ namespace boost }; template< class ForwardRng, class BinPredicate > - inline adjacent_filter_range + inline adjacent_filter_range operator|( ForwardRng& r, const adjacent_holder& f ) { - return adjacent_filter_range( f.val, r, true ); + return adjacent_filter_range( f.val, r ); } template< class ForwardRng, class BinPredicate > - inline adjacent_filter_range + inline adjacent_filter_range operator|( const ForwardRng& r, const adjacent_holder& f ) { return adjacent_filter_range( f.val, r, true ); + const ForwardRng, true>( f.val, r ); } template< class ForwardRng, class BinPredicate > - inline adjacent_filter_range + inline adjacent_filter_range operator|( ForwardRng& r, const adjacent_excl_holder& f ) { - return adjacent_filter_range( f.val, r, false ); + return adjacent_filter_range( f.val, r ); } template< class ForwardRng, class BinPredicate > - inline adjacent_filter_range + inline adjacent_filter_range operator|( const ForwardRng& r, const adjacent_excl_holder& f ) { return adjacent_filter_range( f.val, r, false ); + const ForwardRng, false>( f.val, r ); } } // 'range_detail' @@ -231,17 +215,17 @@ namespace boost } template - inline adjacent_filter_range - adjacent_filter(ForwardRng& rng, BinPredicate filter_pred, bool default_pass = true) + inline adjacent_filter_range + adjacent_filter(ForwardRng& rng, BinPredicate filter_pred) { - return adjacent_filter_range(filter_pred, rng, default_pass); + return adjacent_filter_range(filter_pred, rng); } template - inline adjacent_filter_range - adjacent_filter(const ForwardRng& rng, BinPredicate filter_pred, bool default_pass = true) + inline adjacent_filter_range + adjacent_filter(const ForwardRng& rng, BinPredicate filter_pred) { - return adjacent_filter_range(filter_pred, rng, default_pass); + return adjacent_filter_range(filter_pred, rng); } } // 'adaptors' diff --git a/include/boost/range/adaptor/uniqued.hpp b/include/boost/range/adaptor/uniqued.hpp index 28a30f2..ddaf3fe 100755 --- a/include/boost/range/adaptor/uniqued.hpp +++ b/include/boost/range/adaptor/uniqued.hpp @@ -15,68 +15,68 @@ namespace boost { - + namespace range_detail { struct unique_forwarder { }; - + struct unique_not_equal_to { typedef bool result_type; - + template< class T > bool operator()( const T& l, const T& r ) const { return !(l == r); } }; - + template - class unique_range : public adjacent_filter_range + class unique_range : public adjacent_filter_range { - typedef adjacent_filter_range base; + typedef adjacent_filter_range base; public: explicit unique_range(ForwardRng& rng) - : base(unique_not_equal_to(), rng, true) + : base(unique_not_equal_to(), rng) { } }; - + template< class ForwardRng > - inline unique_range - operator|( ForwardRng& r, + inline unique_range + operator|( ForwardRng& r, unique_forwarder ) { return unique_range(r); } - + template< class ForwardRng > - inline unique_range - operator|( const ForwardRng& r, + inline unique_range + operator|( const ForwardRng& r, unique_forwarder ) { return unique_range(r); } - + } // 'range_detail' - + using range_detail::unique_range; - + namespace adaptors - { + { namespace { - const range_detail::unique_forwarder uniqued = + const range_detail::unique_forwarder uniqued = range_detail::unique_forwarder(); } - + template inline unique_range unique(ForwardRange& rng) { return unique_range(rng); } - + template inline unique_range unique(const ForwardRange& rng) @@ -84,7 +84,7 @@ namespace boost return unique_range(rng); } } // 'adaptors' - + } #endif