make Circulator_from_container somewhat compatible with C++20 ranges

This commit is contained in:
Laurent Rineau 2024-04-24 11:08:35 +02:00
parent 3095a5b412
commit f558acab61
1 changed files with 24 additions and 20 deletions

View File

@ -698,14 +698,18 @@ typedef Iterator_from_circulator< C, const_reference, const_pointer>
};
template <class Container>
class Circulator_from_container {
static auto begin(Container* c) {
using std::begin;
return begin(*c);
}
static auto end(Container* c) {
using std::end;
return end(*c);
}
typedef Circulator_from_container<Container> Self;
typedef typename Container::iterator container_iterator;
typedef typename Container::const_iterator container_const_iterator;
typedef std::conditional_t<
std::is_const<Container>::value,
container_const_iterator,
container_iterator
> iterator;
using iterator = decltype(begin(std::declval<Container*>()));
typedef std::iterator_traits<iterator> iterator_traits;
public:
typedef typename iterator_traits::value_type value_type;
@ -717,7 +721,7 @@ public:
typename iterator_traits::iterator_category
>::iterator_category iterator_category;
typedef typename Container::size_type size_type;
using size_type = decltype(std::size(std::declval<Container&>()));
private:
Container* ctnr;
iterator i;
@ -734,27 +738,27 @@ public:
bool operator==( std::nullptr_t p) const {
CGAL_USE(p);
CGAL_assertion( p == nullptr);
return (ctnr == nullptr) || (ctnr->begin() == ctnr->end());
return (ctnr == nullptr) || (begin(ctnr) == end(ctnr));
}
bool operator!=( std::nullptr_t p) const { return !(*this == p); }
bool operator==( const Self& c) const { return i == c.i; }
bool operator!=( const Self& c) const { return !(*this == c); }
reference operator*() const {
CGAL_assertion( ctnr != nullptr);
CGAL_assertion( i != ctnr->end());
CGAL_assertion( i != end(ctnr));
return *i;
}
pointer operator->() const {
CGAL_assertion( ctnr != nullptr);
CGAL_assertion( i != ctnr->end());
CGAL_assertion( i != end(ctnr));
return i.operator->();
}
Self& operator++() {
CGAL_assertion( ctnr != nullptr);
CGAL_assertion( i != ctnr->end());
CGAL_assertion( i != end(ctnr));
++i;
if ( i == ctnr->end())
i = ctnr->begin();
if ( i == end(ctnr))
i = begin(ctnr);
return *this;
}
Self operator++(int) {
@ -764,9 +768,9 @@ public:
}
Self& operator--() {
CGAL_assertion( ctnr != nullptr);
CGAL_assertion( i != ctnr->end());
if ( i == ctnr->begin())
i = ctnr->end();
CGAL_assertion( i != end(ctnr));
if ( i == begin(ctnr))
i = end(ctnr);
--i;
return *this;
}
@ -777,15 +781,15 @@ public:
}
Self& operator+=( difference_type n) {
CGAL_assertion( ctnr != nullptr);
CGAL_assertion( i != ctnr->end());
typename Container::difference_type j = i - ctnr->begin();
CGAL_assertion( i != end(ctnr));
typename Container::difference_type j = i - begin(ctnr);
typename Container::difference_type size = ctnr->size();
CGAL_assertion( j >= 0);
CGAL_assertion( size >= 0);
j = non_negative_mod( j + n, size);
CGAL_assertion( j >= 0);
CGAL_assertion( j < size);
i = ctnr->begin() + j;
i = begin(ctnr) + j;
return *this;
}
Self operator+( difference_type n) const {