Skip to content

Commit

Permalink
Compatibility with recent pybind versions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agrenott authored and lonvia committed Jul 15, 2023
1 parent 135801d commit 31b1363
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/osm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,38 @@ namespace py = pybind11;
using TagIterator = osmium::TagList::const_iterator;
using MemberIterator = osmium::RelationMemberList::const_iterator;

#if PYBIND11_VERSION_MINOR >= 11 || PYBIND11_VERSION_MAJOR > 2
/*
Work-around false positive added by pybind/pybind11@f701654 change:
ItemIterator/CollectionIterator ARE copy/move constructible, even if their template
parameter is not. Indeed, those iterators iterate over low-level memory representation
of the objects, without relying on their constructors.
For eg.
// static_assert(std::is_move_constructible<osmium::memory::CollectionIterator<osmium::RelationMember const>>::value);
// static_assert(!std::is_copy_constructible<osmium::RelationMember>::value);
The work-around relies on officially exposed pybind11::detail::is_copy_constructible/is_copy_constructible:
https://github.com/pybind/pybind11/pull/4631
*/
namespace pybind11 {
namespace detail {
template <typename T>
struct is_copy_constructible<osmium::memory::CollectionIterator<T>>
: std::true_type {};
template <typename T>
struct is_move_constructible<osmium::memory::CollectionIterator<T>>
: std::true_type {};
template <typename T>
struct is_copy_constructible<osmium::memory::ItemIterator<T>>
: std::true_type {};
template <typename T>
struct is_move_constructible<osmium::memory::ItemIterator<T>>
: std::true_type {};
} // namespace detail
} // namespace pybind11
#endif

static py::object tag_iterator_next(TagIterator &it, TagIterator const &cend)
{
if (it == cend)
Expand Down

0 comments on commit 31b1363

Please sign in to comment.