1 #ifndef theplu_yat_utility_merge_iterator
2 #define theplu_yat_utility_merge_iterator
26 #include "yat/utility/yat_assert.h"
28 #include <boost/concept_check.hpp>
29 #include <boost/iterator/iterator_concepts.hpp>
30 #include <boost/iterator/iterator_facade.hpp>
31 #include <boost/iterator/iterator_traits.hpp>
62 class Compare=std::less<typename std::iterator_traits<Base>::value_type>
65 :
public boost::iterator_facade<
66 MergeIterator<Base, Compare>,
67 typename boost::iterator_value<Base>::type,
68 boost::single_pass_traversal_tag,
69 typename boost::iterator_reference<Base>::type
100 : data_(PairCompare(comp))
104 friend class boost::iterator_core_access;
108 void init(
const std::vector<std::pair<Base,Base> >& v);
109 void increment(
void);
115 PairCompare(
const Compare& c) : comp_(c) {}
116 bool operator()(
const std::pair<Base, Base>& x,
117 const std::pair<Base, Base>& y)
const
118 {
return comp_(*x.first, *y.first); }
123 std::multiset<std::pair<Base, Base>, PairCompare> data_;
131 template<
typename Base>
145 template<
typename Base,
class Compare>
157 template<
typename Base,
class Compare>
161 YAT_ASSERT(data_.size());
162 YAT_ASSERT(data_.begin()->first != data_.begin()->second);
163 return *data_.begin()->first;
167 template<
typename Base,
class Compare>
168 bool MergeIterator<Base, Compare>::equal(
const MergeIterator& other)
const
170 if (data_.empty() || other.data_.empty())
171 return data_.empty() == other.data_.empty();
172 return data_.begin()->first == other.data_.begin()->first;
176 template<
typename Base,
class Compare>
178 MergeIterator<Base,Compare>::init(
const std::vector<std::pair<Base,Base> >& v)
180 BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Base>));
181 BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<Base>));
182 for (
size_t i=0; i<v.size(); ++i)
183 if (v[i].first != v[i].second)
188 template<
typename Base,
class Compare>
189 void MergeIterator<Base, Compare>::increment(
void)
194 std::pair<Base, Base> tmp = *data_.begin();
196 data_.erase(data_.begin());
199 if (++(tmp.first) != tmp.second)
MergeIterator< Base, Compare > make_merge_iterator(const std::vector< std::pair< Base, Base > > &vec, const Compare &comp)
Definition: MergeIterator.h:147
Iterate over several ranges as if ranges have been merged.
Definition: MergeIterator.h:64
MergeIterator(const std::vector< std::pair< Base, Base > > &vec)
Create MergeIterator.
Definition: MergeIterator.h:86
MergeIterator< Base > make_merge_iterator(const std::vector< std::pair< Base, Base > > &vec)
Definition: MergeIterator.h:133
MergeIterator(const std::vector< std::pair< Base, Base > > &vec, const Compare &comp)
Creates MergeIterator using comp as compare object.
Definition: MergeIterator.h:98
MergeIterator(void)
Definition: MergeIterator.h:76