prevent conversions from const_iterator -> iterator to resolve a c++20
compilation error with clang 13:
ceph/src/include/buffer.h:537:18: error: use of overloaded operator '==' is ambiguous (with operand types 'ceph::buffer::list::buffers_t::const_iterator' (aka 'buffers_iterator<const ceph::buffer::ptr_node>') and 'ceph::buffer::list::buffers_t::iterator' (aka 'buffers_iterator<ceph::buffer::ptr_node>'
))
_root.next = it == end() ? &item : _root.next;
~~ ^ ~~~~~
ceph/src/include/buffer.h:471:7: note: candidate function
bool operator==(const buffers_iterator& rhs) const {
^
ceph/src/include/buffer.h:471:7: note: candidate function (with reversed parameter order)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
buffers_iterator(U* const p)
: cur(p) {
}
- template <class U>
+ // copy constructor
+ buffers_iterator(const buffers_iterator<T>& other)
+ : cur(other.cur) {
+ }
+ // converting constructor, from iterator -> const_iterator only
+ template <class U, typename std::enable_if<
+ std::is_const<T>::value && !std::is_const<U>::value, int>::type = 0>
buffers_iterator(const buffers_iterator<U>& other)
: cur(other.cur) {
}
bool operator!=(const buffers_iterator& rhs) const {
return !(*this==rhs);
}
-
- using citer_t = buffers_iterator<typename std::add_const<T>::type>;
- operator citer_t() const {
- return citer_t(cur);
- }
};
typedef buffers_iterator<const ptr_node> const_iterator;