24#ifndef MYSQL_RANGES_DISJOINT_PAIRS_H
25#define MYSQL_RANGES_DISJOINT_PAIRS_H
48 template <
class Type_t>
49 constexpr static std::pair<Type_t &, Type_t &>
make_pair(Type_t &first,
51 return {first, second};
54 template <
class Type_t>
55 constexpr static std::pair<Type_t, Type_t>
make_pair(
const Type_t &first,
56 const Type_t &second) {
57 return {first, second};
74template <std::forward_iterator Source_iterator_tp,
75 class Make_pair_tp = detail::Make_pair>
78 Disjoint_pairs_iterator<Source_iterator_tp, Make_pair_tp>> {
83 using Value_t =
decltype(Make_pair_t::make_pair(
84 std::declval<Source_value_t>(), std::declval<Source_value_t>()));
120#if !defined(__GNUC__) || defined(__clang__)
124 std::ranges::advance(
m_first, 2);
127 std::ranges::advance(
m_first, 2);
139 std::ranges::advance(
m_first, -2);
145 requires std::random_access_iterator<Source_iterator_t>
154 requires std::random_access_iterator<Source_iterator_t>
156 return (
m_first - other.m_first) >> 1;
180template <
class Pair_t = detail::Make_pair,
class Iterator_t>
205template <
class Self_tp,
class Make_pair_tp>
216 return make_disjoint_pairs_iterator<Make_pair_t>(
source().
begin());
220 [[nodiscard]]
auto end()
const {
221 return make_disjoint_pairs_iterator<Make_pair_t>(
source().
end());
226 return make_disjoint_pairs_iterator<Make_pair_t>(
source().
begin());
230 [[nodiscard]]
auto end() {
231 return make_disjoint_pairs_iterator<Make_pair_t>(
source().
end());
250 requires requires(
Self_t s) { s.disjoint_pairs_source().empty(); }
259 [[nodiscard]]
auto size()
const {
267 [[nodiscard]]
auto size() const
268 requires requires(
Self_t s) { s.disjoint_pairs_source().size(); }
270 return source().size() >> 1;
274 [[nodiscard]]
const auto &
source()
const {
275 return static_cast<const Self_t *
>(
this)->disjoint_pairs_source();
278 return static_cast<Self_t *
>(
this)->disjoint_pairs_source();
301template <
class Source_tp,
class Make_pair_tp = detail::Make_pair>
304 Disjoint_pairs_view<Source_tp, Make_pair_tp>, Make_pair_tp>,
305 public std::ranges::view_base {
354template <
class Make_pair_t = detail::Make_pair,
class Source_t>
CRTP base class (mixin) that makes your class a standard-compliant iterator, given only a minimal set...
Definition: iterator_interface.h:370
CRTP base class to provide members of a collection based on an implementation that provides begin/end...
Definition: collection_interface.h:90
constexpr auto size() const
Return the number of elements in this view, unsigned (size_t), by computing std::ranges::distance(beg...
Definition: collection_interface.h:145
constexpr bool empty() const
Return true if the range is empty, i.e., begin() == end().
Definition: collection_interface.h:133
Self_tp Self_t
Definition: collection_interface.h:91
CRTP base used to define classes that yield disjoint, adjacent pairs of elements from an even-length ...
Definition: disjoint_pairs.h:207
auto size() const
Return the number of pairs, i.e., half the size of the source.
Definition: disjoint_pairs.h:267
bool empty() const
Return true if the range is empty.
Definition: disjoint_pairs.h:238
auto begin()
Return iterator to the beginning.
Definition: disjoint_pairs.h:225
auto & source()
Definition: disjoint_pairs.h:277
bool empty() const
Return true if the range is empty.
Definition: disjoint_pairs.h:249
auto begin() const
Return const iterator to the beginning.
Definition: disjoint_pairs.h:215
auto end() const
Return const iterator to sentinel.
Definition: disjoint_pairs.h:220
auto size() const
Return the number of pairs, i.e., half the size of the source.
Definition: disjoint_pairs.h:259
const auto & source() const
Definition: disjoint_pairs.h:274
auto end()
Return iterator to sentinel.
Definition: disjoint_pairs.h:230
Make_pair_tp Make_pair_t
Definition: disjoint_pairs.h:212
Iterator used by Disjoint_pairs_interface and Disjoint_pairs_view: this yields the disjoint,...
Definition: disjoint_pairs.h:78
Source_iterator_t m_first
Iterator to the first position.
Definition: disjoint_pairs.h:166
std::ptrdiff_t distance_from(const Disjoint_pairs_iterator &other) const
Definition: disjoint_pairs.h:152
Value_t get() const
Definition: disjoint_pairs.h:97
void prev()
Move to the previous position.
Definition: disjoint_pairs.h:133
Make_pair_tp Make_pair_t
Definition: disjoint_pairs.h:81
Source_iterator_tp Source_iterator_t
Definition: disjoint_pairs.h:80
bool is_equal(const Disjoint_pairs_iterator &other) const
Definition: disjoint_pairs.h:160
mysql::ranges::Iterator_value_type< Source_iterator_t > Source_value_t
Definition: disjoint_pairs.h:82
void advance(std::ptrdiff_t delta)
Move the iterator the given number of steps.
Definition: disjoint_pairs.h:144
std::optional< Source_iterator_t > m_second
Iterator to the second position.
Definition: disjoint_pairs.h:176
void next()
Move to the next position.
Definition: disjoint_pairs.h:109
Disjoint_pairs_iterator() noexcept=default
Default constructor, which leaves the object in a state that is not usable, except it can be assigned...
decltype(Make_pair_t::make_pair(std::declval< Source_value_t >(), std::declval< Source_value_t >())) Value_t
Definition: disjoint_pairs.h:84
View over an even-length sequence, yielding the disjoint, adjacent pairs of elements.
Definition: disjoint_pairs.h:305
Make_pair_tp Make_pair_t
Definition: disjoint_pairs.h:310
Disjoint_pairs_view(const Source_t &source)
Construct a view that over the given source.
Definition: disjoint_pairs.h:325
Disjoint_pairs_view(const Disjoint_pairs_view &)=default
Source_ref_t m_source
source, either owned or not.
Definition: disjoint_pairs.h:339
~Disjoint_pairs_view()=default
const Source_t & disjoint_pairs_source() const
Return const reference to the source.
Definition: disjoint_pairs.h:335
Disjoint_pairs_view & operator=(const Disjoint_pairs_view &)=default
Source_tp Source_t
Definition: disjoint_pairs.h:309
Disjoint_pairs_view(Disjoint_pairs_view &&)=default
mysql::ranges::Range_iterator_type< Source_t > Source_iterator_t
Definition: disjoint_pairs.h:311
Disjoint_pairs_view()=default
Disjoint_pairs_view & operator=(Disjoint_pairs_view &&)=default
mysql::ranges::Range_const_iterator_type< Source_t > Source_const_iterator_t
Definition: disjoint_pairs.h:313
Wrapper around an object that is the source for a view: the wrapped object is owned by this object if...
Definition: view_sources.h:101
const Source_t & reference() const
Return a reference to the stored object.
Definition: view_sources.h:130
Header for compiler-dependent features.
#define MY_COMPILER_GCC_DIAGNOSTIC_IGNORE(X)
Definition: my_compiler.h:242
#define MY_COMPILER_DIAGNOSTIC_PUSH()
save the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:277
#define MY_COMPILER_DIAGNOSTIC_POP()
restore the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:278
Definition: buffer_interface.h:40
Definition: buffer_interface.h:40
std::remove_cvref_t< decltype(std::declval< const Range_t >().begin())> Range_const_iterator_type
Gives the const_iterator type, deduced from the begin() const member.
Definition: meta.h:47
auto make_disjoint_pairs_iterator(const Iterator_t &position)
Factory function to create a Disjoint_pairs_iterator.
Definition: disjoint_pairs.h:181
std::remove_cvref_t< decltype(*std::declval< Iterator_t >())> Iterator_value_type
Gives the value type for any iterator type, deduced from operator *.
Definition: meta.h:63
std::remove_cvref_t< decltype(std::declval< Range_t >().begin())> Range_iterator_type
Gives the iterator type, deduced from the begin() member.
Definition: meta.h:42
auto make_disjoint_pairs_view(const Source_t &source)
Factory to construct a Disjoint_pairs_view from a given range.
Definition: disjoint_pairs.h:355
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
Define std::hash<Gtid>.
Definition: gtid.h:355
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42
Definition: disjoint_pairs.h:43
constexpr static std::pair< Type_t, Type_t > make_pair(const Type_t &first, const Type_t &second)
Definition: disjoint_pairs.h:55
constexpr static std::pair< Type_t &, Type_t & > make_pair(Type_t &first, Type_t &second)
Return a pair from the given arguments.
Definition: disjoint_pairs.h:49