MySQL 9.6.0
Source Code Documentation
transform_view.h
Go to the documentation of this file.
1// Copyright (c) 2025, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License, version 2.0, for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24#ifndef MYSQL_RANGES_TRANSFORM_VIEW_H
25#define MYSQL_RANGES_TRANSFORM_VIEW_H
26
27/// @file
28/// Experimental API header
29
30#include <algorithm> // move
31#include <iterator> // input_iterator
32#include <ranges> // range
33#include "mysql/iterators/iterator_interface.h" // Iterator_interface
34#include "mysql/ranges/collection_interface.h" // Collection_interface
35#include "mysql/ranges/meta.h" // Range_iterator_type
36#include "mysql/ranges/view_sources.h" // View_source
37
38/// @addtogroup GroupLibsMysqlRanges
39/// @{
40
41namespace mysql::ranges {
42
43/// Iterator adaptor that applies a transformation on each value before
44/// returning it.
45///
46/// @tparam Transform_tp The transform.
47///
48/// @tparam Source_iterator_tp The source iterator type.
49template <class Transform_tp, std::input_iterator Source_iterator_tp>
52 Transform_iterator<Transform_tp, Source_iterator_tp>> {
53 public:
54 using Transform_t = Transform_tp;
55 using Source_iterator_t = Source_iterator_tp;
56
57 explicit Transform_iterator() = default;
58 explicit Transform_iterator(const Source_iterator_t &source_iterator)
59 : m_source_iterator(source_iterator) {}
60 explicit Transform_iterator(Source_iterator_t &&source_iterator)
61 : m_source_iterator(std::move(source_iterator)) {}
62
63 [[nodiscard]] decltype(auto) get() const {
65 }
66
67 void next() { ++m_source_iterator; }
68
69 void prev()
70 requires std::bidirectional_iterator<Source_iterator_t>
71 {
73 }
74
75 void advance(std::ptrdiff_t delta)
76 requires std::random_access_iterator<Source_iterator_t>
77 {
78 m_source_iterator += delta;
79 }
80
81 [[nodiscard]] bool is_equal(const Transform_iterator &other) const {
83 }
84
85 [[nodiscard]] std::ptrdiff_t distance_from(
86 const Transform_iterator &other) const
87 requires std::random_access_iterator<Source_iterator_t>
88 {
89 return m_source_iterator - other.m_source_iterator;
90 }
91
92 private:
94}; // class Transform_iterator
95
96/// Factory function to create a Transform_iterator.
97///
98/// @tparam Transform_t The transform.
99///
100/// @tparam Source_iterator_t The source iterator type.
101template <class Transform_t, std::input_iterator Source_iterator_t>
102[[nodiscard]] auto make_transform_iterator(const Source_iterator_t &iterator) {
104}
105
106/// CRTP base class / mixin used to define ranges that provide
107/// Transform_iterators.
108///
109/// This is for objects that own the source. If you need objects that do not own
110/// the source - a *view* - use Transform_view.
111///
112/// @tparam Self_tp Derived class. This must implement the member function
113/// `transform_source()` which returns a source object whose iterators return
114/// tuple-like objects.
115///
116/// @tparam Transform_tp The transform.
117///
118/// @tparam Source_tp The source type.
119template <class Self_tp, class Transform_tp, std::ranges::range Source_tp>
121 : public Collection_interface<
122 Transform_interface<Self_tp, Transform_tp, Source_tp>> {
123 public:
124 using Source_t = Source_tp;
125 using Transform_t = Transform_tp;
127 Transform_iterator<Transform_tp,
129
130 [[nodiscard]] auto begin() {
131 return make_transform_iterator<Transform_t>(source().begin());
132 }
133 [[nodiscard]] auto end() {
134 return make_transform_iterator<Transform_t>(source().end());
135 }
136 [[nodiscard]] auto begin() const {
137 return make_transform_iterator<Transform_t>(source().begin());
138 }
139 [[nodiscard]] auto end() const {
140 return make_transform_iterator<Transform_t>(source().end());
141 }
142 [[nodiscard]] auto size() const
143 requires requires {
144 std::declval<const Self_tp>().transform_source().size();
145 }
146 {
147 return source().size();
148 }
149 [[nodiscard]] auto empty() const
150 requires requires {
151 std::declval<const Self_tp>().transform_source().empty();
152 }
153 {
154 return source().empty();
155 }
156
157 private:
158 [[nodiscard]] const auto &source() const {
159 return static_cast<const Self_tp *>(this)->transform_source();
160 }
161 [[nodiscard]] auto &source() {
162 return static_cast<Self_tp *>(this)->transform_source();
163 }
164}; // class Transform_interface
165
166/// View whose iterators provide transformed values.
167///
168/// @tparam Transform_tp The transform.
169///
170/// @tparam Source_tp The source type.
171template <class Transform_tp, std::ranges::range Source_tp>
173 : public Transform_interface<Transform_view<Transform_tp, Source_tp>,
174 Transform_tp, Source_tp>,
175 public std::ranges::view_base {
177
178 public:
179 using Source_t = Source_tp;
180
181 Transform_view() = default;
183
184 [[nodiscard]] auto &transform_source() { return m_source.reference(); }
185 [[nodiscard]] const auto &transform_source() const {
186 return m_source.reference();
187 }
188
189 private:
191}; // class Transform_view
192
193/// Factory function to create a Transform_view.
194///
195/// @tparam Transform_t The transform.
196///
197/// @tparam Source_t The source type.
198template <class Transform_t, std::ranges::range Source_t>
199[[nodiscard]] auto make_transform_view(const Source_t &source) {
201}
202
203} // namespace mysql::ranges
204
205// addtogroup GroupLibsMysqlRanges
206/// @}
207
208#endif // ifndef MYSQL_RANGES_TRANSFORM_VIEW_H
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
CRTP base class / mixin used to define ranges that provide Transform_iterators.
Definition: transform_view.h:122
auto end() const
Definition: transform_view.h:139
const auto & source() const
Definition: transform_view.h:158
auto begin() const
Definition: transform_view.h:136
auto empty() const
Definition: transform_view.h:149
auto size() const
Definition: transform_view.h:142
Source_tp Source_t
Definition: transform_view.h:124
auto begin()
Definition: transform_view.h:130
auto end()
Definition: transform_view.h:133
auto & source()
Definition: transform_view.h:161
Transform_tp Transform_t
Definition: transform_view.h:125
Iterator adaptor that applies a transformation on each value before returning it.
Definition: transform_view.h:52
void prev()
Definition: transform_view.h:69
Transform_iterator(Source_iterator_t &&source_iterator)
Definition: transform_view.h:60
Transform_tp Transform_t
Definition: transform_view.h:54
Transform_iterator(const Source_iterator_t &source_iterator)
Definition: transform_view.h:58
void next()
Definition: transform_view.h:67
decltype(auto) get() const
Definition: transform_view.h:63
Source_iterator_tp Source_iterator_t
Definition: transform_view.h:55
std::ptrdiff_t distance_from(const Transform_iterator &other) const
Definition: transform_view.h:85
Source_iterator_t m_source_iterator
Definition: transform_view.h:93
bool is_equal(const Transform_iterator &other) const
Definition: transform_view.h:81
void advance(std::ptrdiff_t delta)
Definition: transform_view.h:75
View whose iterators provide transformed values.
Definition: transform_view.h:175
const auto & transform_source() const
Definition: transform_view.h:185
auto & transform_source()
Definition: transform_view.h:184
Transform_view(const Source_t &source)
Definition: transform_view.h:182
Source_ref_t m_source
Definition: transform_view.h:190
Source_tp Source_t
Definition: transform_view.h:179
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
Experimental API header.
Experimental API header.
Experimental API header.
Definition: buffer_interface.h:40
auto make_transform_iterator(const Source_iterator_t &iterator)
Factory function to create a Transform_iterator.
Definition: transform_view.h:102
auto make_transform_view(const Source_t &source)
Factory function to create a Transform_view.
Definition: transform_view.h:199
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
std::basic_string< Char > transform(std::basic_string_view< Char > s, F fun)
Definition: utils_string.h:53
Define std::hash<Gtid>.
Definition: gtid.h:355
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42
Experimental API header.