mirror of https://github.com/CGAL/cgal
make Circulator_from_container somewhat compatible with C++20 ranges
This commit is contained in:
parent
3095a5b412
commit
f558acab61
|
|
@ -698,14 +698,18 @@ typedef Iterator_from_circulator< C, const_reference, const_pointer>
|
||||||
};
|
};
|
||||||
template <class Container>
|
template <class Container>
|
||||||
class Circulator_from_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 Circulator_from_container<Container> Self;
|
||||||
typedef typename Container::iterator container_iterator;
|
using iterator = decltype(begin(std::declval<Container*>()));
|
||||||
typedef typename Container::const_iterator container_const_iterator;
|
|
||||||
typedef std::conditional_t<
|
|
||||||
std::is_const<Container>::value,
|
|
||||||
container_const_iterator,
|
|
||||||
container_iterator
|
|
||||||
> iterator;
|
|
||||||
typedef std::iterator_traits<iterator> iterator_traits;
|
typedef std::iterator_traits<iterator> iterator_traits;
|
||||||
public:
|
public:
|
||||||
typedef typename iterator_traits::value_type value_type;
|
typedef typename iterator_traits::value_type value_type;
|
||||||
|
|
@ -717,7 +721,7 @@ public:
|
||||||
typename iterator_traits::iterator_category
|
typename iterator_traits::iterator_category
|
||||||
>::iterator_category iterator_category;
|
>::iterator_category iterator_category;
|
||||||
|
|
||||||
typedef typename Container::size_type size_type;
|
using size_type = decltype(std::size(std::declval<Container&>()));
|
||||||
private:
|
private:
|
||||||
Container* ctnr;
|
Container* ctnr;
|
||||||
iterator i;
|
iterator i;
|
||||||
|
|
@ -734,27 +738,27 @@ public:
|
||||||
bool operator==( std::nullptr_t p) const {
|
bool operator==( std::nullptr_t p) const {
|
||||||
CGAL_USE(p);
|
CGAL_USE(p);
|
||||||
CGAL_assertion( p == nullptr);
|
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!=( 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 i == c.i; }
|
||||||
bool operator!=( const Self& c) const { return !(*this == c); }
|
bool operator!=( const Self& c) const { return !(*this == c); }
|
||||||
reference operator*() const {
|
reference operator*() const {
|
||||||
CGAL_assertion( ctnr != nullptr);
|
CGAL_assertion( ctnr != nullptr);
|
||||||
CGAL_assertion( i != ctnr->end());
|
CGAL_assertion( i != end(ctnr));
|
||||||
return *i;
|
return *i;
|
||||||
}
|
}
|
||||||
pointer operator->() const {
|
pointer operator->() const {
|
||||||
CGAL_assertion( ctnr != nullptr);
|
CGAL_assertion( ctnr != nullptr);
|
||||||
CGAL_assertion( i != ctnr->end());
|
CGAL_assertion( i != end(ctnr));
|
||||||
return i.operator->();
|
return i.operator->();
|
||||||
}
|
}
|
||||||
Self& operator++() {
|
Self& operator++() {
|
||||||
CGAL_assertion( ctnr != nullptr);
|
CGAL_assertion( ctnr != nullptr);
|
||||||
CGAL_assertion( i != ctnr->end());
|
CGAL_assertion( i != end(ctnr));
|
||||||
++i;
|
++i;
|
||||||
if ( i == ctnr->end())
|
if ( i == end(ctnr))
|
||||||
i = ctnr->begin();
|
i = begin(ctnr);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Self operator++(int) {
|
Self operator++(int) {
|
||||||
|
|
@ -764,9 +768,9 @@ public:
|
||||||
}
|
}
|
||||||
Self& operator--() {
|
Self& operator--() {
|
||||||
CGAL_assertion( ctnr != nullptr);
|
CGAL_assertion( ctnr != nullptr);
|
||||||
CGAL_assertion( i != ctnr->end());
|
CGAL_assertion( i != end(ctnr));
|
||||||
if ( i == ctnr->begin())
|
if ( i == begin(ctnr))
|
||||||
i = ctnr->end();
|
i = end(ctnr);
|
||||||
--i;
|
--i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
@ -777,15 +781,15 @@ public:
|
||||||
}
|
}
|
||||||
Self& operator+=( difference_type n) {
|
Self& operator+=( difference_type n) {
|
||||||
CGAL_assertion( ctnr != nullptr);
|
CGAL_assertion( ctnr != nullptr);
|
||||||
CGAL_assertion( i != ctnr->end());
|
CGAL_assertion( i != end(ctnr));
|
||||||
typename Container::difference_type j = i - ctnr->begin();
|
typename Container::difference_type j = i - begin(ctnr);
|
||||||
typename Container::difference_type size = ctnr->size();
|
typename Container::difference_type size = ctnr->size();
|
||||||
CGAL_assertion( j >= 0);
|
CGAL_assertion( j >= 0);
|
||||||
CGAL_assertion( size >= 0);
|
CGAL_assertion( size >= 0);
|
||||||
j = non_negative_mod( j + n, size);
|
j = non_negative_mod( j + n, size);
|
||||||
CGAL_assertion( j >= 0);
|
CGAL_assertion( j >= 0);
|
||||||
CGAL_assertion( j < size);
|
CGAL_assertion( j < size);
|
||||||
i = ctnr->begin() + j;
|
i = begin(ctnr) + j;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Self operator+( difference_type n) const {
|
Self operator+( difference_type n) const {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue