Skip to content

Commit c7f136f

Browse files
committed
Remove dependency on boost::filter_iterator
By implementing our own filter iterator.
1 parent a58a869 commit c7f136f

4 files changed

Lines changed: 67 additions & 7 deletions

File tree

.github/actions/install-windows/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ runs:
44
using: composite
55
steps:
66
- name: Install packages
7-
run: vcpkg install bzip2:x64-windows expat:x64-windows zlib:x64-windows boost-crc:x64-windows boost-iterator:x64-windows boost-variant:x64-windows sparsehash:x64-windows
7+
run: vcpkg install bzip2:x64-windows expat:x64-windows zlib:x64-windows boost-crc:x64-windows boost-variant:x64-windows sparsehash:x64-windows
88
shell: bash
99

include/osmium/memory/collection.hpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,70 @@ namespace osmium {
113113
return out;
114114
}
115115

116+
template <typename TFilter, typename TMember>
117+
class CollectionFilterIterator {
118+
119+
TFilter m_filter;
120+
CollectionIterator<TMember> m_it;
121+
CollectionIterator<TMember> m_end;
122+
123+
void advance() {
124+
while (m_it != m_end) {
125+
if (m_filter(*m_it)) {
126+
break;
127+
}
128+
++m_it;
129+
}
130+
}
131+
132+
public:
133+
134+
using iterator_category = std::forward_iterator_tag;
135+
using value_type = const TMember;
136+
using difference_type = std::ptrdiff_t;
137+
using pointer = value_type*;
138+
using reference = value_type&;
139+
140+
CollectionFilterIterator(const TFilter& filter, CollectionIterator<TMember> begin, CollectionIterator<TMember> end) :
141+
m_filter(filter),
142+
m_it(begin),
143+
m_end(end) {
144+
advance();
145+
}
146+
147+
CollectionFilterIterator& operator++() {
148+
assert(m_it != m_end);
149+
++m_it;
150+
advance();
151+
return *this;
152+
}
153+
154+
CollectionFilterIterator operator++(int) const {
155+
CollectionFilterIterator tmp{*this};
156+
operator++();
157+
return tmp;
158+
}
159+
160+
bool operator==(const CollectionFilterIterator& rhs) const noexcept {
161+
return m_it == rhs.m_it && m_end == rhs.m_end;
162+
}
163+
164+
bool operator!=(const CollectionFilterIterator& rhs) const noexcept {
165+
return !(*this == rhs);
166+
}
167+
168+
reference operator*() const noexcept {
169+
assert(m_it != m_end);
170+
return *m_it;
171+
}
172+
173+
pointer operator->() const noexcept {
174+
assert(m_it != m_end);
175+
return &*m_it;
176+
}
177+
178+
}; // class CollectionFilterIterator
179+
116180
template <typename TMember, osmium::item_type TCollectionItemType>
117181
class Collection : public Item {
118182

include/osmium/tags/filter.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ DEALINGS IN THE SOFTWARE.
3636
#include <osmium/memory/collection.hpp>
3737
#include <osmium/osm/tag.hpp>
3838

39-
#include <boost/iterator/filter_iterator.hpp>
40-
4139
#include <cstddef>
4240
#include <cstring>
4341
#include <string>
@@ -126,7 +124,7 @@ namespace osmium {
126124
using filter_type = Filter<TKey, TValue, TKeyComp, TValueComp>;
127125
using argument_type = const osmium::Tag&;
128126
using result_type = bool;
129-
using iterator = boost::filter_iterator<filter_type, osmium::TagList::const_iterator>;
127+
using iterator = osmium::memory::CollectionFilterIterator<filter_type, const osmium::Tag>;
130128

131129
explicit Filter(bool default_result = false) :
132130
m_default_result(default_result) {

include/osmium/tags/tags_filter.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ DEALINGS IN THE SOFTWARE.
3636
#include <osmium/osm/tag.hpp>
3737
#include <osmium/tags/matcher.hpp>
3838

39-
#include <boost/iterator/filter_iterator.hpp>
40-
4139
#include <utility>
4240
#include <vector>
4341

@@ -72,7 +70,7 @@ namespace osmium {
7270

7371
public:
7472

75-
using iterator = boost::filter_iterator<TagsFilterBase, osmium::TagList::const_iterator>;
73+
using iterator = osmium::memory::CollectionFilterIterator<TagsFilterBase, const osmium::Tag>;
7674

7775
/**
7876
* Constructor.

0 commit comments

Comments
 (0)