5#include <userver/storages/postgres/detail/iterator_direction.hpp>
19template <
typename FinalType,
typename DataType,
20 IteratorDirection direction = IteratorDirection::kForward>
21class ConstDataIterator :
protected DataType {
22 using Iter = ConstDataIterator;
27 using value_type = DataType;
28 using difference_type = std::ptrdiff_t;
29 using reference =
const value_type&;
30 using pointer =
const value_type*;
31 using iterator_category = std::random_access_iterator_tag;
36 reference operator*()
const {
return static_cast<reference>(*
this); }
37 pointer operator->()
const {
return static_cast<pointer>(
this); }
42 explicit operator
bool()
const {
return this->IsValid(); }
43 bool operator!()
const {
return !
this->IsValid(); }
48 FinalType& operator++() {
return DoAdvance(1); }
49 FinalType operator++(
int) {
50 FinalType prev{Rebind()};
55 FinalType& operator--() {
return DoAdvance(-1); }
56 FinalType operator--(
int) {
57 FinalType prev{Rebind()};
62 FinalType operator+(difference_type distance)
const {
63 FinalType res{Rebind()};
64 res.DoAdvance(distance);
68 FinalType operator-(difference_type distance)
const {
69 FinalType res{Rebind()};
70 res.DoAdvance(-distance);
74 difference_type operator-(
const FinalType& rhs)
const {
75 return this->Distance(rhs) *
static_cast<
int>(direction);
78 FinalType operator[](difference_type index)
const {
79 return *
this + index *
static_cast<
int>(direction);
82 FinalType& operator+=(difference_type distance) {
83 return DoAdvance(distance);
85 FinalType& operator-=(difference_type distance) {
86 return DoAdvance(-distance);
92 bool operator==(
const Iter& rhs)
const {
return DoCompare(rhs) == 0; }
93 bool operator!=(
const Iter& rhs)
const {
return !(*
this == rhs); }
95 bool operator<(
const Iter& rhs)
const {
return DoCompare(rhs) < 0; }
96 bool operator<=(
const Iter& rhs)
const {
return DoCompare(rhs) <= 0; }
97 bool operator>(
const Iter& rhs)
const {
return DoCompare(rhs) > 0; }
98 bool operator>=(
const Iter& rhs)
const {
return DoCompare(rhs) >= 0; }
101 template <
typename... T>
102 ConstDataIterator(T&&... args) : value_type(std::forward<T>(args)...) {}
105 FinalType& Rebind() {
return static_cast<FinalType&>(*
this); }
106 const FinalType& Rebind()
const {
107 return static_cast<
const FinalType&>(*
this);
110 FinalType& DoAdvance(difference_type distance) {
111 this->Advance(distance *
static_cast<
int>(direction));
114 int DoCompare(
const Iter& rhs)
const {
return this->Compare(rhs); }