Skip to content

Commit 31b1363

Browse files
agrenottlonvia
authored andcommitted
Compatibility with recent pybind versions
Work-around false positive added by pybind/pybind11@f701654 change: ItemIterator/CollectionIterator ARE copy/move constructible, even if their template parameter is not. Enabled for pybind version >= 2.11.
1 parent 135801d commit 31b1363

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lib/osm.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,38 @@ namespace py = pybind11;
1818
using TagIterator = osmium::TagList::const_iterator;
1919
using MemberIterator = osmium::RelationMemberList::const_iterator;
2020

21+
#if PYBIND11_VERSION_MINOR >= 11 || PYBIND11_VERSION_MAJOR > 2
22+
/*
23+
Work-around false positive added by pybind/pybind11@f701654 change:
24+
ItemIterator/CollectionIterator ARE copy/move constructible, even if their template
25+
parameter is not. Indeed, those iterators iterate over low-level memory representation
26+
of the objects, without relying on their constructors.
27+
28+
For eg.
29+
// static_assert(std::is_move_constructible<osmium::memory::CollectionIterator<osmium::RelationMember const>>::value);
30+
// static_assert(!std::is_copy_constructible<osmium::RelationMember>::value);
31+
32+
The work-around relies on officially exposed pybind11::detail::is_copy_constructible/is_copy_constructible:
33+
https://github.com/pybind/pybind11/pull/4631
34+
*/
35+
namespace pybind11 {
36+
namespace detail {
37+
template <typename T>
38+
struct is_copy_constructible<osmium::memory::CollectionIterator<T>>
39+
: std::true_type {};
40+
template <typename T>
41+
struct is_move_constructible<osmium::memory::CollectionIterator<T>>
42+
: std::true_type {};
43+
template <typename T>
44+
struct is_copy_constructible<osmium::memory::ItemIterator<T>>
45+
: std::true_type {};
46+
template <typename T>
47+
struct is_move_constructible<osmium::memory::ItemIterator<T>>
48+
: std::true_type {};
49+
} // namespace detail
50+
} // namespace pybind11
51+
#endif
52+
2153
static py::object tag_iterator_next(TagIterator &it, TagIterator const &cend)
2254
{
2355
if (it == cend)

0 commit comments

Comments
 (0)