3#include <boost/pfr/core.hpp>
5#include <userver/storages/postgres/result_set.hpp>
7#include <userver/storages/postgres/detail/iterator_direction.hpp>
13template <
typename T,
typename ExtractionTag,
14 IteratorDirection direction = IteratorDirection::kForward>
15class ConstTypedRowIterator :
private Row {
20 using difference_type = std::ptrdiff_t;
21 using reference = value_type;
22 using pointer =
const value_type*;
26 using iterator_category = std::input_iterator_tag;
28 static constexpr ExtractionTag kExtractTag{};
34 value_type operator*()
const {
return As<value_type>(kExtractTag); }
38 explicit operator
bool()
const {
return this->IsValid(); }
39 bool operator!()
const {
return !
this->IsValid(); }
44 ConstTypedRowIterator& operator++() {
return DoAdvance(1); }
45 ConstTypedRowIterator operator++(
int) {
46 ConstTypedRowIterator prev{*
this};
51 ConstTypedRowIterator& operator--() {
return DoAdvance(-1); }
52 ConstTypedRowIterator operator--(
int) {
53 ConstTypedRowIterator prev{*
this};
58 ConstTypedRowIterator operator+(difference_type distance)
const {
59 ConstTypedRowIterator res{*
this};
60 res.DoAdvance(distance);
63 ConstTypedRowIterator operator-(difference_type distance)
const {
64 ConstTypedRowIterator res{*
this};
65 res.DoAdvance(-distance);
69 difference_type operator-(
const ConstTypedRowIterator& rhs)
const {
70 return this->Distance(rhs) *
static_cast<
int>(direction);
73 ConstTypedRowIterator operator[](difference_type index)
const {
74 return *
this + index *
static_cast<
int>(direction);
77 ConstTypedRowIterator& operator+=(difference_type distance) {
78 return DoAdvance(distance);
80 ConstTypedRowIterator& operator-=(difference_type distance) {
81 return DoAdvance(-distance);
87 bool operator==(
const ConstTypedRowIterator& rhs)
const {
88 return this->Compare(rhs) == 0;
91 bool operator!=(
const ConstTypedRowIterator& rhs)
const {
92 return !(*
this == rhs);
95 bool operator<(
const ConstTypedRowIterator& rhs)
const {
96 return this->Compare(rhs) < 0;
98 bool operator<=(
const ConstTypedRowIterator& rhs)
const {
99 return this->Compare(rhs) <= 0;
101 bool operator>(
const ConstTypedRowIterator& rhs)
const {
102 return this->Compare(rhs) > 0;
104 bool operator>=(
const ConstTypedRowIterator& rhs)
const {
105 return this->Compare(rhs) >= 0;
109 friend class TypedResultSet<T, ExtractionTag>;
111 ConstTypedRowIterator(detail::ResultWrapperPtr res, size_type row)
112 : Row{std::move(res), row} {}
113 ConstTypedRowIterator& DoAdvance(difference_type distance) {
114 this->Advance(distance *
static_cast<
int>(direction));