File indexing completed on 2025-01-18 09:42:39
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_DETAIL_RESULTS_ITERATOR_HPP
0009 #define BOOST_MYSQL_DETAIL_RESULTS_ITERATOR_HPP
0010
0011 #include <boost/mysql/resultset.hpp>
0012 #include <boost/mysql/resultset_view.hpp>
0013
0014 #include <boost/mysql/detail/access.hpp>
0015 #include <boost/mysql/detail/execution_processor/results_impl.hpp>
0016
0017 namespace boost {
0018 namespace mysql {
0019 namespace detail {
0020
0021 class results_iterator
0022 {
0023 const results_impl* self_{};
0024 std::size_t index_{};
0025
0026 public:
0027 using value_type = resultset;
0028 using reference = resultset_view;
0029 using pointer = resultset_view;
0030 using difference_type = std::ptrdiff_t;
0031 using iterator_category = std::random_access_iterator_tag;
0032
0033 results_iterator() = default;
0034 results_iterator(const results_impl* self, std::size_t index) noexcept : self_(self), index_(index) {}
0035
0036 results_iterator& operator++() noexcept
0037 {
0038 ++index_;
0039 return *this;
0040 }
0041 results_iterator operator++(int) noexcept
0042 {
0043 auto res = *this;
0044 ++(*this);
0045 return res;
0046 }
0047 results_iterator& operator--() noexcept
0048 {
0049 --index_;
0050 return *this;
0051 }
0052 results_iterator operator--(int) noexcept
0053 {
0054 auto res = *this;
0055 --(*this);
0056 return res;
0057 }
0058 results_iterator& operator+=(std::ptrdiff_t n) noexcept
0059 {
0060 index_ += n;
0061 return *this;
0062 }
0063 results_iterator& operator-=(std::ptrdiff_t n) noexcept
0064 {
0065 index_ -= n;
0066 return *this;
0067 }
0068 results_iterator operator+(std::ptrdiff_t n) const noexcept
0069 {
0070 return results_iterator(self_, index_ + n);
0071 }
0072 results_iterator operator-(std::ptrdiff_t n) const noexcept { return *this + (-n); }
0073 std::ptrdiff_t operator-(results_iterator rhs) const noexcept { return index_ - rhs.index_; }
0074
0075 pointer operator->() const noexcept { return **this; }
0076 reference operator*() const noexcept { return (*this)[0]; }
0077 reference operator[](std::ptrdiff_t i) const noexcept
0078 {
0079 return access::construct<resultset_view>(*self_, index_ + i);
0080 }
0081
0082 bool operator==(results_iterator rhs) const noexcept { return index_ == rhs.index_; }
0083 bool operator!=(results_iterator rhs) const noexcept { return !(*this == rhs); }
0084 bool operator<(results_iterator rhs) const noexcept { return index_ < rhs.index_; }
0085 bool operator<=(results_iterator rhs) const noexcept { return index_ <= rhs.index_; }
0086 bool operator>(results_iterator rhs) const noexcept { return index_ > rhs.index_; }
0087 bool operator>=(results_iterator rhs) const noexcept { return index_ >= rhs.index_; }
0088
0089 std::size_t index() const noexcept { return index_; }
0090 const results_impl* obj() const noexcept { return self_; }
0091 };
0092
0093 inline results_iterator operator+(std::ptrdiff_t n, results_iterator it) noexcept { return it + n; }
0094
0095 }
0096 }
0097 }
0098
0099 #endif