MySQL 9.6.0
Source Code Documentation
meta.h
Go to the documentation of this file.
1// Copyright (c) 2024, 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_META_H
25#define MYSQL_RANGES_META_H
26
27/// @file
28/// Experimental API header
29
30#include <concepts> // same_as
31#include <iterator> // forward_iterator
32#include <utility> // declval
33
34/// @addtogroup GroupLibsMysqlRanges
35/// @{
36
37namespace mysql::ranges {
38
39/// Gives the iterator type, deduced from the `begin()` member.
40template <class Range_t>
42 std::remove_cvref_t<decltype(std::declval<Range_t>().begin())>;
43
44/// Gives the const_iterator type, deduced from the `begin() const` member.
45template <class Range_t>
47 std::remove_cvref_t<decltype(std::declval<const Range_t>().begin())>;
48
49/// Gives the iterator type, deduced from the `end()` member.
50template <class Range_t>
52 std::remove_cvref_t<decltype(std::declval<Range_t>().end())>;
53
54/// True if Iterator is either the iterator or the const iterator for
55/// Range_t.
56template <class Iterator_t, class Range_t>
58 std::same_as<Iterator_t, Range_iterator_type<Range_t>>;
59
60/// Gives the value type for any iterator type, deduced from `operator *`.
61template <class Iterator_t>
63 std::remove_cvref_t<decltype(*std::declval<Iterator_t>())>;
64
65/// Gives the value type for any collection, deduced from `*begin()`.
66template <class Range_t>
68
69/// Gives the key type for any collection, deduced from `begin()->first`.
70///
71/// For standard types such as `std::map`, the member type `std::map::key_type`
72/// can be used instead. This deduced type is usable in other cases, for
73/// example, when a map is "emulated" using `std::vector<std::pair<K, V>>`, or
74/// for user-defined types that do no have a `key_type` member.
75template <class Map_t>
77 std::remove_cvref_t<decltype(std::declval<Map_t>().begin()->first)>;
78
79/// Gives the mapped type for any collection, deduced from `begin()->first`.
80///
81/// For standard types such as `std::map`, the member type
82/// `std::map::mapped_type` can be used instead. This deduced type is usable in
83/// other cases, for example, when a map is "emulated" using
84/// `std::vector<std::pair<K, V>>`, or for user-defined types that do no have a
85/// `key_type` member.
86template <class Map_t>
88 std::remove_cvref_t<decltype(std::declval<Map_t>().begin()->second)>;
89
90/// True if `Test` has the properties of a "collection", i.e., a range with
91/// member functions to query size and emptiness.
92///
93/// It requires the following:
94///
95/// - t.begin() returns a forward iterator
96///
97/// - t.end() returns a sentinel for t.begin()
98///
99/// - t.size() returns std::size_t
100///
101/// - t.ssize() returns std::ptrdiff_t
102///
103/// - t.empty() and (bool)t return bool
104///
105/// In addition, the following semantic requirements must hold:
106///
107/// - t.size() == std::ranges::distance(t.begin(), t.end())
108///
109/// - t.ssize() == std::ptrdiff_t(t.size())
110///
111/// - t.empty() == (t.size() == 0)
112///
113/// - t.empty() == !(bool)t
114template <class Test>
116 requires(const Test ct, Test t) // this comment helps clang-format
117{
118 { t.begin() } -> std::forward_iterator;
119 { t.end() } -> std::sentinel_for<decltype(t.begin())>;
120 { ct.begin() } -> std::forward_iterator;
121 { ct.end() } -> std::sentinel_for<decltype(ct.begin())>;
122 { ct.size() } -> std::same_as<std::size_t>;
123 { ct.ssize() } -> std::same_as<std::ptrdiff_t>;
124 { ct.empty() } -> std::same_as<bool>;
125 { (bool)ct } -> std::same_as<bool>;
126};
127
128/// True if `Test` models `Is_collection`, with `Value_t` as its value
129/// type.
130template <class Test, class Value_t>
133 std::same_as<mysql::ranges::Range_value_type<Test>, Value_t>;
134
135} // namespace mysql::ranges
136
137// addtogroup GroupLibsMysqlContainers
138/// @}
139
140#endif // ifndef MYSQL_RANGES_META_H
True if Test models Is_collection, with Value_t as its value type.
Definition: meta.h:131
True if Test has the properties of a "collection", i.e., a range with member functions to query size ...
Definition: meta.h:115
True if Iterator is either the iterator or the const iterator for Range_t.
Definition: meta.h:57
Definition: buffer_interface.h:40
std::remove_cvref_t< decltype(std::declval< Range_t >().end())> Range_sentinel_type
Gives the iterator type, deduced from the end() member.
Definition: meta.h:52
std::remove_cvref_t< decltype(std::declval< Map_t >().begin() ->first)> Map_key_type
Gives the key type for any collection, deduced from begin()->first.
Definition: meta.h:77
std::remove_cvref_t< decltype(std::declval< Map_t >().begin() ->second)> Map_mapped_type
Gives the mapped type for any collection, deduced from begin()->first.
Definition: meta.h:88
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
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
Iterator_value_type< Range_iterator_type< Range_t > > Range_value_type
Gives the value type for any collection, deduced from *begin().
Definition: meta.h:67