|
|
@@ -8,10 +8,12 @@
|
|
|
#pragma once
|
|
|
|
|
|
#include <iterator/detail/traits.h>
|
|
|
-#include <iterator/facade.h>
|
|
|
#include <iterator/forwards.h>
|
|
|
+#include <iterator/proxy.h>
|
|
|
#include <iterator/sentinel.h>
|
|
|
|
|
|
+#include <iterator/detail/macro.h>
|
|
|
+
|
|
|
namespace iterator {
|
|
|
/**
|
|
|
* @class end_aware_iterator
|
|
|
@@ -20,40 +22,37 @@ namespace iterator {
|
|
|
* @tparam It The underlying iterator type
|
|
|
*/
|
|
|
template <typename It>
|
|
|
-class end_aware_iterator : public facade<end_aware_iterator<It>> {
|
|
|
+class end_aware_iterator : public proxy<It, end_aware_iterator<It>> {
|
|
|
public:
|
|
|
+ using super_t = proxy<It, end_aware_iterator<It>>;
|
|
|
using sentinel_type = sentinel_t;
|
|
|
|
|
|
public:
|
|
|
end_aware_iterator() = default;
|
|
|
- end_aware_iterator(It it, It end) : curr_(it), end_(end) {}
|
|
|
+ end_aware_iterator(It it, It end) : super_t(it), end_(end) {}
|
|
|
|
|
|
- template <typename C, typename = std::enable_if_t<detail::is_container_v<C>>>
|
|
|
+ template <typename C, REQUIRES(detail::is_container_v<C>)>
|
|
|
end_aware_iterator(C && container)
|
|
|
- : curr_(std::begin(container)), end_(std::end(container)) {
|
|
|
+ : super_t(std::begin(container)), end_(std::end(container)) {
|
|
|
static_assert(std::is_reference_v<C>,
|
|
|
"Cannot access iterator of a temporary");
|
|
|
}
|
|
|
|
|
|
template <typename Ot>
|
|
|
end_aware_iterator(end_aware_iterator<Ot> const & other)
|
|
|
- : curr_(other.curr_), end_(other.end_) {}
|
|
|
-
|
|
|
- end_aware_iterator(end_aware_iterator<It> other, end_aware_iterator<It>)
|
|
|
- : curr_(other.curr_), end_(other.end_) {}
|
|
|
+ : super_t(other.impl()), end_(other.end_) {}
|
|
|
|
|
|
- decltype(auto) dereference() const { return *curr_; }
|
|
|
- void increment() {
|
|
|
- if (!at_end()) { ++curr_; }
|
|
|
- }
|
|
|
- bool at_end() const { return curr_ == end_; }
|
|
|
- bool equal_to(end_aware_iterator const & other) const {
|
|
|
- return curr_ == other.curr_;
|
|
|
+ bool at_end() const {
|
|
|
+ if constexpr (detail::is_random_access_v<It>) {
|
|
|
+ return super_t::impl() >= end_;
|
|
|
+ } else {
|
|
|
+ return super_t::impl() == end_;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
template <typename O> friend class end_aware_iterator;
|
|
|
- It curr_, end_;
|
|
|
+ It end_;
|
|
|
};
|
|
|
|
|
|
template <typename C>
|
|
|
@@ -65,3 +64,5 @@ end_aware_iterator(end_aware_iterator<It>, end_aware_iterator<It>)
|
|
|
}
|
|
|
|
|
|
MAKE_ITERATOR_FACADE_TYPEDEFS_T(::iterator::end_aware_iterator);
|
|
|
+
|
|
|
+#include <iterator/detail/undef.h>
|