::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