diff --git a/Circulator/include/CGAL/circulator.h b/Circulator/include/CGAL/circulator.h index 1c111779ef8..c622fb615ad 100644 --- a/Circulator/include/CGAL/circulator.h +++ b/Circulator/include/CGAL/circulator.h @@ -698,14 +698,18 @@ typedef Iterator_from_circulator< C, const_reference, const_pointer> }; template 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 Self; - typedef typename Container::iterator container_iterator; - typedef typename Container::const_iterator container_const_iterator; - typedef std::conditional_t< - std::is_const::value, - container_const_iterator, - container_iterator - > iterator; + using iterator = decltype(begin(std::declval())); typedef std::iterator_traits 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())); 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 {