24#ifndef MYSQL_ITERATORS_ITERATOR_INTERFACE_H
25#define MYSQL_ITERATORS_ITERATOR_INTERFACE_H
55 { t.get() } -> std::same_as<void>;
73 std::is_reference_v<decltype(std::declval<Type>().get())>;
82 { t.is_equal(other) } -> std::same_as<bool>;
88 { t.is_sentinel() } -> std::same_as<bool>;
98 requires(
Type t, std::ptrdiff_t x) { t.advance(x); };
103 requires(
Type t,
const Type &other) {
104 { t.distance_from(other) } -> std::same_as<std::ptrdiff_t>;
111 { t.distance_from_sentinel() } -> std::same_as<std::ptrdiff_t>;
181template <
class Value_tp>
186 template <
class... Args_t>
369template <
class Self_tp>
380 [[nodiscard]]
decltype(
auto)
operator*()
const {
384 return *
self().get_pointer();
399 return self().get_pointer();
401 decltype(
auto) ret = **
this;
402 if constexpr (std::is_reference_v<
decltype(ret)>) {
403 return std::addressof(ret);
432 if constexpr (std::copyable<Self_t>) {
471 if constexpr (std::copyable<Self_t>) {
491 self().advance(delta);
502 return (*
this += -delta);
524 return (*
this + -delta);
534 return self().distance_from(other);
541 [[nodiscard]]
decltype(
auto)
operator[](std::ptrdiff_t delta)
const
544 return *(*
this + delta);
549 [[nodiscard]]
const Self_t &
self()
const {
550 return static_cast<const Self_t &
>(*this);
563template <
class Iterator_t>
564 requires std::derived_from<Iterator_t, Iterator_interface<Iterator_t>> &&
565 detail::Has_equality_member<Iterator_t>
566[[nodiscard]]
bool operator==(
const Iterator_t &a,
const Iterator_t &b) {
568 return a.is_equal(b);
570 return a.distance_from(b) == 0;
579template <
class Iterator_t>
580 requires std::derived_from<Iterator_t, Iterator_interface<Iterator_t>> &&
582 requires { Iterator_t().distance_from_sentinel(); } ||
583 requires { Iterator_t().is_sentinel(); })
586 return it.is_sentinel();
588 return it.distance_from_sentinel() == 0;
597template <
class Iterator_t>
598 requires std::derived_from<Iterator_t, Iterator_interface<Iterator_t>> &&
599 detail::Has_member_advance<Iterator_t>
601 const Iterator_t &iterator) {
602 return iterator + delta;
610template <
class Iterator_t>
611 requires std::derived_from<Iterator_t, Iterator_interface<Iterator_t>> &&
612 requires { Iterator_t().distance_from_sentinel(); }
613[[nodiscard]] std::ptrdiff_t
operator-(
const Iterator_t &iterator,
615 return iterator.distance_from_sentinel();
623template <
class Iterator_t>
624 requires std::derived_from<Iterator_t, Iterator_interface<Iterator_t>> &&
625 requires { Iterator_t().distance_from_sentinel(); }
627 const Iterator_t &iterator) {
628 return -iterator.distance_from_sentinel();
635template <
class Iterator_t>
636 requires std::derived_from<Iterator_t, Iterator_interface<Iterator_t>> &&
637 detail::Has_member_distance_from<Iterator_t>
638[[nodiscard]] std::strong_ordering
operator<=>(
const Iterator_t &it1,
639 const Iterator_t &it2) {
640 return it1.distance_from(it2) <=> 0;
647template <
class Iterator_t>
648 requires std::derived_from<Iterator_t, Iterator_interface<Iterator_t>> &&
649 detail::Has_member_distance_from_sentinel<Iterator_t>
650[[nodiscard]] std::strong_ordering
operator<=>(
const Iterator_t &it1,
652 return it1.distance_from_sentinel() <=> 0;
669template <
class Iterator_t>
670 requires std::derived_from<
677struct std::iterator_traits<Iterator_t> {
678 using reference =
decltype(*std::declval<Iterator_t>());
679 using pointer =
decltype(std::declval<Iterator_t>().operator->());
693 using iterator_category =
decltype([] {
696 return std::contiguous_iterator_tag{};
699 return std::random_access_iterator_tag{};
702 return std::bidirectional_iterator_tag{};
705 return std::forward_iterator_tag{};
708 return std::input_iterator_tag{};
738 return std::contiguous_iterator_tag{};
740 return std::random_access_iterator_tag{};
748template <
class Iterator_t>
749 requires std::derived_from<
756struct std::pointer_traits<Iterator_t> {
757 using pointer =
decltype(std::declval<Iterator_t>().operator->());
760 template <
class Other>
782template <
class Iterator_t>
783 requires std::derived_from<Iterator_t,
790struct indirectly_readable_traits<Iterator_t> {
791 using value_type = std::remove_cvref_t<decltype(*std::declval<Iterator_t>())>;
794template <
class Iterator_t>
795 requires std::derived_from<Iterator_t,
802struct incrementable_traits<Iterator_t> {
Used like std::default_sentinel_t / std::default_sentinel.
Definition: iterator_interface.h:212
auto operator<=>(const Default_sentinel &) const =default
bool operator==(const Default_sentinel &) const =default
CRTP base class (mixin) that makes your class a standard-compliant iterator, given only a minimal set...
Definition: iterator_interface.h:370
auto operator++(int)
Post-increment operator, which advances the position one step.
Definition: iterator_interface.h:431
Self_t operator-(std::ptrdiff_t delta) const
Subtraction-of-integer operator, which returns a new iterator that is the given number of steps behin...
Definition: iterator_interface.h:521
auto operator->() const
Arrow operator, return a pointer (possibly a fancy pointer) to the current element.
Definition: iterator_interface.h:397
Self_t & operator++()
Pre-increment operator, which advances the position one step and returns a reference to the iterator ...
Definition: iterator_interface.h:416
Self_tp Self_t
Definition: iterator_interface.h:372
std::ptrdiff_t operator-(const Self_t &other) const
Subtraction-of-iterator operator, which returns the number of steps from other this.
Definition: iterator_interface.h:531
Self_t & operator--()
Pre-decrement iterator, which moves one step back and returns a reference to the iterator itself.
Definition: iterator_interface.h:450
auto operator--(int)
Post-decrement operator, which moves one step back and returns a copy of the iterator before the decr...
Definition: iterator_interface.h:467
Self_t & operator-=(std::ptrdiff_t delta)
Subtraction assignment operator, which moves the iterator backward by the given number of steps,...
Definition: iterator_interface.h:499
Self_t & operator+=(std::ptrdiff_t delta)
Addition assignment operator, which moves the iterator forward by the given number of steps,...
Definition: iterator_interface.h:488
Self_t operator+(std::ptrdiff_t delta) const
Addition operator, which returns a new iterator that is the given number of steps ahead of the curren...
Definition: iterator_interface.h:509
Auxiliary object that holds a value internally, and operator-> returns a pointer to the value.
Definition: iterator_interface.h:182
Value_t m_value
Definition: iterator_interface.h:195
Value_t * operator->()
Definition: iterator_interface.h:192
Value_tp Value_t
Definition: iterator_interface.h:184
Dereferenceable_wrapper(Args_t &&...args)
Definition: iterator_interface.h:189
true if Type has the members required for Iterator_interface<Type> to meet the syntactic requirements...
Definition: iterator_interface.h:152
true if Type has the members required for Iterator_interface<Type> to meet the syntactic requirements...
Definition: iterator_interface.h:166
True if Type has the members and the value type for required for Iterator_interface<Type> to meet the...
Definition: iterator_interface.h:143
true if Type has the members required for Iterator_interface<Type> to meet the syntactic requirements...
Definition: iterator_interface.h:159
true if Type has an is_equal or distance_from member.
Definition: iterator_interface.h:116
true if Type has an advance member
Definition: iterator_interface.h:97
true if Type has a distance_from member
Definition: iterator_interface.h:109
true if Type has a distance_from member
Definition: iterator_interface.h:102
Helper: returns true if Type has a get function, regardless if it returns void or not.
Definition: iterator_interface.h:49
true if Type has a get member that returns a pointer.
Definition: iterator_interface.h:65
true if Type has a get member that returns a reference type.
Definition: iterator_interface.h:72
Helper: returns true if Type has a get function that returns void (which does not make it an iterator...
Definition: iterator_interface.h:54
true if Type has a get member that does not return void.
Definition: iterator_interface.h:60
true if Type has an is_equal member.
Definition: iterator_interface.h:81
true if Type has an is_sentinel member.
Definition: iterator_interface.h:87
true if Type has a next member.
Definition: iterator_interface.h:77
true if Type has a prev member
Definition: iterator_interface.h:93
MediaType
Definition: media_type.h:33
Definition: iterator_interface.h:39
Definition: empty_sequence_iterator.h:37
Iterator_t operator+(std::ptrdiff_t delta, const Iterator_t &iterator)
Addition operator with the left-hand-side of type ptrdiff_t and the right-hand-side of Iterator type,...
Definition: iterator_interface.h:600
bool operator==(const Iterator_t &a, const Iterator_t &b)
Equality operator, which returns true if the two iterators are equal.
Definition: iterator_interface.h:566
constexpr Default_sentinel default_sentinel
Definition: iterator_interface.h:217
std::ptrdiff_t operator-(const Iterator_t &iterator, const Default_sentinel &)
Subtraction operator with the left-hand-side of Iterator type and the right-hand-side of Sentinel typ...
Definition: iterator_interface.h:613
std::strong_ordering operator<=>(const Iterator_t &it1, const Iterator_t &it2)
Three-way comparison operator which compares two Iterator objects and returns a std::strong_ordering ...
Definition: iterator_interface.h:638
static mysql_service_status_t get(THD **thd) noexcept
Definition: mysql_current_thread_reader_all_empty.cc:31
Define std::hash<Gtid>.
Definition: gtid.h:355
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
Helper type to declare that an iterator is not a legacy iterator.
Definition: iterator_interface.h:660
std::ptrdiff_t difference_type
Definition: iterator_interface.h:803
std::remove_cvref_t< decltype(*std::declval< Iterator_t >())> value_type
Definition: iterator_interface.h:791
std::remove_cvref_t< reference > value_type
Definition: iterator_interface.h:680
decltype(std::declval< Iterator_t >().operator->()) pointer
Definition: iterator_interface.h:679
decltype([] { if constexpr(mysql::iterators::detail::Has_member_get_pointer< Iterator_t >) { return std::contiguous_iterator_tag{} iterator_concept
Definition: iterator_interface.h:738
decltype(*std::declval< Iterator_t >()) reference
Definition: iterator_interface.h:678
std::ptrdiff_t difference_type
Definition: iterator_interface.h:681
static pointer pointer_to(element_type &r)
Definition: iterator_interface.h:762
decltype(std::declval< Iterator_t >().operator*()) element_type
Definition: iterator_interface.h:758
std::ptrdiff_t difference_type
Definition: iterator_interface.h:759
Other * rebind
Definition: iterator_interface.h:761
decltype(std::declval< Iterator_t >().operator->()) pointer
Definition: iterator_interface.h:757