MySQL 9.6.0
Source Code Documentation
set_traits.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_SETS_SET_TRAITS_H
25#define MYSQL_SETS_SET_TRAITS_H
26
27/// @file
28/// Experimental API header
29
30#include <concepts> // derived_from
31#include "mysql/meta/optional_is_same.h" // Optional_is_same
32
33/// @addtogroup GroupLibsMysqlSets
34/// @{
35
36namespace mysql::sets {
37
38// ==== Set traits ====
39
40/// Base class for all Set_traits classes.
41///
42/// Set traits are used to determine if sets (of the same category) are
43/// compatible. For example, if two set classes have the same category and
44/// traits, it is allowed to compute the union of them (using the algorithm for
45/// "union" determined by their category tag).
47
48/// True if Test is a Set_traits class, i.e., is derived from Base_set_traits.
49template <class Test>
50concept Is_set_traits = std::derived_from<Test, Base_set_traits>;
51
52// ==== Has_*_traits ====
53
54/// True if Test has a member Set_traits_t.
55///
56/// If Set_traits_t is given, true only if Test::Set_traits_t is the same type
57/// as Set_traits_t.
58template <class Test, class Set_traits_t = void>
62
63/// True if Test1 and Test2 have the same Set_traits_t.
64template <class Test1, class Test2>
67 std::same_as<typename Test1::Set_traits_t, typename Test2::Set_traits_t>;
68
69// ==== Specific kinds of set traits ====
70
71/// True if Test is a Set traits class with an element type member, Element_t.
72///
73/// This requires that the member type Element_t exists and satisfies
74/// std::equality_comparable. If the template argument Element_t is given, it
75/// also requires that Test::Element_t equals Element_t.
76template <class Test, class Element_t = void>
78 Is_set_traits<Test> && std::equality_comparable<typename Test::Element_t> &&
80
81/// True if Test is an "ordered" Set traits class.
82///
83/// This requires that Test has an element type, and the static member functions
84/// lt, le, gt, and ge to compare two values, and the member type Less_t which
85/// is a function object class whose objects satisfy the *Compare* named
86/// requirements (cf. https://en.cppreference.com/w/cpp/named_req/Compare).
87template <class Test>
89 Is_element_set_traits<Test> && requires { typename Test::Less_t; } &&
90 requires(typename Test::Element_t v1, typename Test::Element_t v2) {
91 { Test::lt(v1, v2) } -> std::same_as<bool>;
92 { Test::le(v1, v2) } -> std::same_as<bool>;
93 { Test::gt(v1, v2) } -> std::same_as<bool>;
94 { Test::ge(v1, v2) } -> std::same_as<bool>;
95 { typename Test::Less_t()(v1, v2) } -> std::same_as<bool>;
96 };
97
98/// True if Test is a "bounded" Set traits class.
99///
100/// This requires that it is ordered, and has static member functions `min` and
101/// `max_exclusive` that give the minimum and maximum value, respectively, as
102/// well as the `in_range` convenience function that returns true if a value is
103/// in the range.
104template <class Test>
105concept Is_bounded_set_traits = // this comment helps clang-format
107 requires(typename Test::Element_t value) {
108 { Test::min() } -> std::same_as<typename Test::Element_t>;
109 { Test::max_exclusive() } -> std::same_as<typename Test::Element_t>;
110 { Test::in_range(value) } -> std::same_as<bool>;
111 };
112
113/// True if Test is a "discrete" Set traits class, i.e., it bounded, and it is
114/// possible to compute successors and predecessors.
115///
116/// This requires that each value has a successor and a predecessor given by the
117/// static member functions prev and next.
118template <class Test>
121 requires(typename Test::Element_t v1, typename Test::Element_t v2) {
122 { Test::next(v1) } -> std::same_as<typename Test::Element_t>;
123 { Test::prev(v1) } -> std::same_as<typename Test::Element_t>;
124 };
125
126/// True if Test is a "metric" Set traits class, i.e., it is bounded, and it is
127/// possible to compute differences between boundaries.
128///
129/// This requires that it has a member type Difference_t (which may or may not
130/// be equal to Element_t), that the difference between two Element_t values is
131/// of type Difference_t and can be computed using member function sub, that two
132/// Difference_t objects can be added using `add` to give another Difference_t,
133/// and that a Difference_t can be added to a Element_t using `add` to give
134/// another Element_t.
135template <class Test>
138 std::same_as<typename Test::Difference_t, typename Test::Difference_t> &&
139 (!std::same_as<typename Test::Difference_t, void>) &&
140 requires(Test t, typename Test::Element_t v1, typename Test::Element_t v2,
141 typename Test::Difference_t d1, typename Test::Difference_t d2) {
142 { Test::sub(v1, v2) } -> std::same_as<typename Test::Difference_t>;
143 { Test::add(v1, d1) } -> std::same_as<typename Test::Element_t>;
144 { Test::add(d1, v1) } -> std::same_as<typename Test::Element_t>;
145 { Test::add(d1, d2) } -> std::same_as<typename Test::Difference_t>;
146 };
147
148/// True if Test satisfies both Is_discrete_set_traits and
149/// Is_metric_set_traits.
150template <class Test>
153
154} // namespace mysql::sets
155
156// addtogroup GroupLibsMysqlSets
157/// @}
158
159#endif // ifndef MYSQL_SETS_SET_TRAITS_H
True if either Other is omitted/void, or Test is the same type as Other.
Definition: optional_is_same.h:39
True if Test1 and Test2 have the same Set_traits_t.
Definition: set_traits.h:65
True if Test has a member Set_traits_t.
Definition: set_traits.h:59
True if Test is a "bounded" Set traits class.
Definition: set_traits.h:105
True if Test satisfies both Is_discrete_set_traits and Is_metric_set_traits.
Definition: set_traits.h:151
True if Test is a "discrete" Set traits class, i.e., it bounded, and it is possible to compute succes...
Definition: set_traits.h:119
True if Test is a Set traits class with an element type member, Element_t.
Definition: set_traits.h:77
True if Test is a "metric" Set traits class, i.e., it is bounded, and it is possible to compute diffe...
Definition: set_traits.h:136
True if Test is an "ordered" Set traits class.
Definition: set_traits.h:88
True if Test is a Set_traits class, i.e., is derived from Base_set_traits.
Definition: set_traits.h:50
#define d1
Type sub(Shards< COUNT > &shards, size_t id, size_t n)
Decrement the counter for a shard by n.
Definition: ut0counter.h:280
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
Definition: gtid_set.h:183
static mysql_service_status_t add(reference_caching_channel channel, const char *implementation_name) noexcept
Definition: component.cc:127
Experimental API header.
Base class for all Set_traits classes.
Definition: set_traits.h:46