Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61142 - in trunk: boost/range/adaptor libs/range/doc/html/range/reference/algorithms/range_algorithm_new_algorithms
From: neil_at_[hidden]
Date: 2010-04-07 19:40:54


Author: neilgroves
Date: 2010-04-07 19:40:53 EDT (Wed, 07 Apr 2010)
New Revision: 61142
URL: http://svn.boost.org/trac/boost/changeset/61142

Log:
Boost.Range modification in an attempt to improve the compatibility of the adjacent_filtered and uniqued adaptors.
Added:
   trunk/libs/range/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/iota.html (contents, props changed)
Text files modified:
   trunk/boost/range/adaptor/adjacent_filtered.hpp | 194 ++++++++++++++++++---------------------
   trunk/boost/range/adaptor/uniqued.hpp | 42 ++++----
   2 files changed, 110 insertions(+), 126 deletions(-)

Modified: trunk/boost/range/adaptor/adjacent_filtered.hpp
==============================================================================
--- trunk/boost/range/adaptor/adjacent_filtered.hpp (original)
+++ trunk/boost/range/adaptor/adjacent_filtered.hpp 2010-04-07 19:40:53 EDT (Wed, 07 Apr 2010)
@@ -30,94 +30,58 @@
 
         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,R>, Iter >
+ : public boost::iterator_adaptor<
+ skip_iterator<Iter,Pred,default_pass>,
+ Iter,
+ BOOST_DEDUCED_TYPENAME std::iterator_traits<Iter>::value_type,
+ boost::forward_traversal_tag,
+ BOOST_DEDUCED_TYPENAME std::iterator_traits<Iter>::reference,
+ BOOST_DEDUCED_TYPENAME std::iterator_traits<Iter>::difference_type
+ >
+ , private Pred
                 {
                 private:
- typedef boost::iterator_adaptor< skip_iterator<Iter,R>, Iter >
- base_t;
-
- R* m_range;
+ typedef boost::iterator_adaptor<
+ skip_iterator<Iter,Pred,default_pass>,
+ Iter,
+ BOOST_DEDUCED_TYPENAME std::iterator_traits<Iter>::value_type,
+ boost::forward_traversal_tag,
+ BOOST_DEDUCED_TYPENAME std::iterator_traits<Iter>::reference,
+ BOOST_DEDUCED_TYPENAME std::iterator_traits<Iter>::difference_type
+ > base_t;
 
                 public:
- typedef Iter wrapped_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;
-
- explicit skip_iterator( R* r, Iter i )
- : base_t(i), m_range(r) {}
-
- template< class OtherIter, class R2>
- skip_iterator( const skip_iterator<OtherIter,R2>& 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() );
- }
+ typedef Pred pred_t;
+ typedef Iter iter_t;
 
- //
- // Not needed ... just apply a reverse_iterator
- //
- void decrement()
- {
- BOOST_ASSERT( false && "you can't decrement an adjacent_filter_iterator" );
- }
+ skip_iterator() : m_last() {}
 
- template< class D >
- void advance( D n )
+ skip_iterator(iter_t it, iter_t last, const Pred& pred)
+ : base_t(it)
+ , pred_t(pred)
+ , m_last(last)
             {
- BOOST_ASSERT( false );
+ move_to_next_valid();
             }
 
- };
-
- template< class P, class R >
- struct adjacent_filter_range
- : iterator_range< skip_iterator<
- BOOST_DEDUCED_TYPENAME range_iterator<R>::type,
- adjacent_filter_range<P,R>
- >
- >
- {
- private:
- typedef skip_iterator<
- BOOST_DEDUCED_TYPENAME range_iterator<R>::type,
- adjacent_filter_range<P,R>
- >
- skip_iter;
- typedef iterator_range<skip_iter>
- base_range;
-
- typedef BOOST_DEDUCED_TYPENAME range_iterator<R>::type raw_iterator;
-
- P m_bi_pred;
+ template<class OtherIter>
+ skip_iterator( const skip_iterator<OtherIter, pred_t, default_pass>& other )
+ : base_t(other.base())
+ , pred_t(other)
+ , m_last(other.m_last) {}
 
- // 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 @@
                                         }
                                         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;
                         }
 
- 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)
+ void increment()
                         {
+ iter_t& it = this->base_reference();
+ BOOST_ASSERT( it != m_last );
+ ++it;
+ move_to_next_valid();
                         }
 
- 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);
- }
+ 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<R>::type,
+ P,
+ default_pass
+ >
+ >
+ {
                 private:
- bool m_default_pass;
+ typedef skip_iterator<
+ BOOST_DEDUCED_TYPENAME range_iterator<R>::type,
+ P,
+ default_pass
+ >
+ skip_iter;
+
+ typedef iterator_range<skip_iter>
+ base_range;
+
+ typedef BOOST_DEDUCED_TYPENAME range_iterator<R>::type raw_iterator;
+
+ public:
+ 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) )
+ {
+ }
                 };
 
                 template< class T >
@@ -177,37 +161,37 @@
                 };
 
                 template< class ForwardRng, class BinPredicate >
- inline adjacent_filter_range<BinPredicate, ForwardRng>
+ inline adjacent_filter_range<BinPredicate, ForwardRng, true>
                 operator|( ForwardRng& r,
                                    const adjacent_holder<BinPredicate>& f )
                 {
- return adjacent_filter_range<BinPredicate, ForwardRng>( f.val, r, true );
+ return adjacent_filter_range<BinPredicate, ForwardRng, true>( f.val, r );
                 }
 
                 template< class ForwardRng, class BinPredicate >
- inline adjacent_filter_range<BinPredicate, const ForwardRng>
+ inline adjacent_filter_range<BinPredicate, const ForwardRng, true>
                 operator|( const ForwardRng& r,
                                    const adjacent_holder<BinPredicate>& f )
                 {
                         return adjacent_filter_range<BinPredicate,
- const ForwardRng>( f.val, r, true );
+ const ForwardRng, true>( f.val, r );
                 }
 
                 template< class ForwardRng, class BinPredicate >
- inline adjacent_filter_range<BinPredicate, ForwardRng>
+ inline adjacent_filter_range<BinPredicate, ForwardRng, false>
                 operator|( ForwardRng& r,
                                    const adjacent_excl_holder<BinPredicate>& f )
                 {
- return adjacent_filter_range<BinPredicate, ForwardRng>( f.val, r, false );
+ return adjacent_filter_range<BinPredicate, ForwardRng, false>( f.val, r );
                 }
 
                 template< class ForwardRng, class BinPredicate >
- inline adjacent_filter_range<BinPredicate, ForwardRng>
+ inline adjacent_filter_range<BinPredicate, ForwardRng, false>
                 operator|( const ForwardRng& r,
                                    const adjacent_excl_holder<BinPredicate>& f )
                 {
                         return adjacent_filter_range<BinPredicate,
- const ForwardRng>( f.val, r, false );
+ const ForwardRng, false>( f.val, r );
                 }
 
         } // 'range_detail'
@@ -231,17 +215,17 @@
                 }
 
             template<class ForwardRng, class BinPredicate>
- inline adjacent_filter_range<BinPredicate, ForwardRng>
- adjacent_filter(ForwardRng& rng, BinPredicate filter_pred, bool default_pass = true)
+ inline adjacent_filter_range<BinPredicate, ForwardRng, true>
+ adjacent_filter(ForwardRng& rng, BinPredicate filter_pred)
             {
- return adjacent_filter_range<BinPredicate, ForwardRng>(filter_pred, rng, default_pass);
+ return adjacent_filter_range<BinPredicate, ForwardRng, true>(filter_pred, rng);
             }
 
             template<class ForwardRng, class BinPredicate>
- inline adjacent_filter_range<BinPredicate, const ForwardRng>
- adjacent_filter(const ForwardRng& rng, BinPredicate filter_pred, bool default_pass = true)
+ inline adjacent_filter_range<BinPredicate, const ForwardRng, true>
+ adjacent_filter(const ForwardRng& rng, BinPredicate filter_pred)
             {
- return adjacent_filter_range<BinPredicate, const ForwardRng>(filter_pred, rng, default_pass);
+ return adjacent_filter_range<BinPredicate, const ForwardRng, true>(filter_pred, rng);
             }
 
         } // 'adaptors'

Modified: trunk/boost/range/adaptor/uniqued.hpp
==============================================================================
--- trunk/boost/range/adaptor/uniqued.hpp (original)
+++ trunk/boost/range/adaptor/uniqued.hpp 2010-04-07 19:40:53 EDT (Wed, 07 Apr 2010)
@@ -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 ForwardRng>
- class unique_range : public adjacent_filter_range<unique_not_equal_to, ForwardRng>
+ class unique_range : public adjacent_filter_range<unique_not_equal_to, ForwardRng, true>
                 {
- typedef adjacent_filter_range<unique_not_equal_to, ForwardRng> base;
+ typedef adjacent_filter_range<unique_not_equal_to, ForwardRng, true> 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<ForwardRng>
- operator|( ForwardRng& r,
+ inline unique_range<ForwardRng>
+ operator|( ForwardRng& r,
                                    unique_forwarder )
                 {
                         return unique_range<ForwardRng>(r);
                 }
-
+
                 template< class ForwardRng >
- inline unique_range<const ForwardRng>
- operator|( const ForwardRng& r,
+ inline unique_range<const ForwardRng>
+ operator|( const ForwardRng& r,
                                    unique_forwarder )
                 {
                         return unique_range<const ForwardRng>(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<class ForwardRange>
                 inline unique_range<ForwardRange>
                 unique(ForwardRange& rng)
                 {
                     return unique_range<ForwardRange>(rng);
             }
-
+
             template<class ForwardRange>
             inline unique_range<const ForwardRange>
             unique(const ForwardRange& rng)
@@ -84,7 +84,7 @@
                 return unique_range<const ForwardRange>(rng);
         }
         } // 'adaptors'
-
+
 }
 
 #endif

Added: trunk/libs/range/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/iota.html
==============================================================================
--- (empty file)
+++ trunk/libs/range/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/iota.html 2010-04-07 19:40:53 EDT (Wed, 07 Apr 2010)
@@ -0,0 +1,96 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>iota</title>
+<link rel="stylesheet" href="../../../../../../../../doc/html/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
+<link rel="home" href="../../../../index.html" title="Chapter&#160;1.&#160;Range 2.0">
+<link rel="up" href="../range_algorithm_new_algorithms.html" title="New algorithms">
+<link rel="prev" href="insert.html" title="insert">
+<link rel="next" href="overwrite.html" title="overwrite">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="insert.html"><img src="../../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../range_algorithm_new_algorithms.html"><img src="../../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="overwrite.html"><img src="../../../../../../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" title="iota">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="range.reference.algorithms.range_algorithm_new_algorithms.iota"></a><a class="link" href="iota.html" title="iota">
+ iota</a>
+</h5></div></div></div>
+<a name="range.reference.algorithms.range_algorithm_new_algorithms.iota.prototype"></a><h6>
+<a name="id716034"></a>
+ <a class="link" href="iota.html#range.reference.algorithms.range_algorithm_new_algorithms.iota.prototype">Prototype</a>
+ </h6>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">SinglePassRange</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Value</span><span class="special">&gt;</span>
+<span class="identifier">iota</span><span class="special">(</span><span class="identifier">SinglePassRange</span><span class="special">&amp;</span> <span class="identifier">rng</span><span class="special">,</span> <span class="identifier">Value</span> <span class="identifier">x</span><span class="special">);</span>
+</pre>
+<p>
+ </p>
+<a name="range.reference.algorithms.range_algorithm_new_algorithms.iota.description"></a><h6>
+<a name="id716150"></a>
+ <a class="link" href="iota.html#range.reference.algorithms.range_algorithm_new_algorithms.iota.description">Description</a>
+ </h6>
+<p>
+ <code class="computeroutput"><span class="identifier">iota</span></code> traverses forward
+ through <code class="computeroutput"><span class="identifier">rng</span></code>, each element
+ <code class="computeroutput"><span class="identifier">y</span></code> in <code class="computeroutput"><span class="identifier">rng</span></code>
+ is assigned a value equivalent to <code class="computeroutput"><span class="identifier">x</span>
+ <span class="special">+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">begin</span><span class="special">(</span><span class="identifier">rng</span><span class="special">),</span> <span class="identifier">it</span><span class="special">)</span></code>
+ </p>
+<a name="range.reference.algorithms.range_algorithm_new_algorithms.iota.definition"></a><h6>
+<a name="id716288"></a>
+ <a class="link" href="iota.html#range.reference.algorithms.range_algorithm_new_algorithms.iota.definition">Definition</a>
+ </h6>
+<p>
+ Defined in the header file <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">algorithm_ext</span><span class="special">/</span><span class="identifier">iota</span><span class="special">.</span><span class="identifier">hpp</span></code>
+ </p>
+<a name="range.reference.algorithms.range_algorithm_new_algorithms.iota.requirements"></a><h6>
+<a name="id716360"></a>
+ <a class="link" href="iota.html#range.reference.algorithms.range_algorithm_new_algorithms.iota.requirements">Requirements</a>
+ </h6>
+<div class="orderedlist"><ol class="orderedlist" type="1">
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">SinglePassRange</span></code> is
+ a model of the <a class="link" href="../../../concepts/single_pass_range.html" title="Single Pass Range">Single
+ Pass Range</a> Concept.
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">Value</span></code> is a model of
+ the <code class="computeroutput"><span class="identifier">Incrementable</span></code> Concept.
+ </li>
+</ol></div>
+<a name="range.reference.algorithms.range_algorithm_new_algorithms.iota.complexity"></a><h6>
+<a name="id716434"></a>
+ <a class="link" href="iota.html#range.reference.algorithms.range_algorithm_new_algorithms.iota.complexity">Complexity</a>
+ </h6>
+<p>
+ Linear. Exactly <code class="computeroutput"><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng</span><span class="special">)</span></code> assignments into <code class="computeroutput"><span class="identifier">rng</span></code>.
+ </p>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright &#169; 2003 -2010 Thorsten Ottosen, Neil Groves<p>
+ 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)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="insert.html"><img src="../../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../range_algorithm_new_algorithms.html"><img src="../../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="overwrite.html"><img src="../../../../../../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>


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