MySQL 9.6.0
Source Code Documentation
int_set_traits.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_SETS_INT_SET_TRAITS_H
25#define MYSQL_SETS_INT_SET_TRAITS_H
26
27/// @file
28/// Experimental API header
29
30#include <compare> // strong_ordering
31#include <limits> // numeric_limits
32#include "mysql/sets/ordered_set_traits_interface.h" // Ordered_set_traits_interface
33#include "mysql/sets/set_traits.h" // Is_discrete_metric_set_traits
34
35/// @addtogroup GroupLibsMysqlSets
36/// @{
37
38namespace mysql::sets {
39
40/// Set traits for integral types.
41///
42/// @tparam Element_tp The integral type.
43///
44/// @tparam min_tp The minimum value. Default is the minimum value for the type
45/// (negative for signed types, 0 for unsigned types).
46///
47/// @tparam max_exclusive_tp The maximum value. Default is the maximum value for
48/// the type.
49///
50/// @note This reserves std::numeric_limits<Element_tp>::max() for *exclusive*
51/// endpoints, so that value cannot be represented in the set.
52template <std::integral Element_tp,
53 Element_tp min_tp = std::numeric_limits<Element_tp>::min(),
54 Element_tp max_exclusive_tp = std::numeric_limits<Element_tp>::max()>
57 Int_set_traits<Element_tp, min_tp, max_exclusive_tp>, Element_tp,
58 std::make_unsigned_t<Element_tp>> {
61 std::make_unsigned_t<Element_tp>>;
64
65 /// Return the minimum allowed value.
66 [[nodiscard]] static constexpr Element_t min() { return min_tp; }
67
68 /// @return The maximum allowed value for exclusive endpoints.
69 ///
70 /// @note The set can store values that are strictly smaller than this number.
71 [[nodiscard]] static constexpr Element_t max_exclusive() {
72 return max_exclusive_tp;
73 }
74
75 /// @return true if @c left < @c right.
76 [[nodiscard]] static constexpr bool lt_impl(const Element_t &left,
77 const Element_t &right) {
78 return left < right;
79 }
80
81 /// @return true if @c left < @c right.
82 [[nodiscard]] static constexpr std::strong_ordering cmp_impl(
83 const Element_t &left, const Element_t &right) {
84 return left <=> right;
85 }
86
87 /// @return @c element + 1.
88 [[nodiscard]] static constexpr Element_t next(const Element_t &element) {
89 return element + 1;
90 }
91
92 /// @return @c element - 1.
93 [[nodiscard]] static constexpr Element_t prev(const Element_t &element) {
94 return element - 1;
95 }
96}; // struct Int_set_traits
97
98static_assert(Is_discrete_metric_set_traits<Int_set_traits<int>>);
99
100} // namespace mysql::sets
101
102// addtogroup GroupLibsMysqlSets
103/// @}
104
105#endif // ifndef MYSQL_SETS_INT_SET_TRAITS_H
void right(std::string *to_trim)
Definition: trim.h:41
void left(std::string *to_trim)
Definition: trim.h:35
ValueType max(X &&first)
Definition: gtid.h:103
Definition: gtid_set.h:183
Experimental API header.
Experimental API header.
Set traits for integral types.
Definition: int_set_traits.h:58
Base_t::Difference_t Difference_t
Definition: int_set_traits.h:63
static constexpr Element_t max_exclusive()
Definition: int_set_traits.h:71
Base_t::Element_t Element_t
Definition: int_set_traits.h:62
static constexpr std::strong_ordering cmp_impl(const Element_t &left, const Element_t &right)
Definition: int_set_traits.h:82
static constexpr Element_t next(const Element_t &element)
Definition: int_set_traits.h:88
static constexpr Element_t min()
Return the minimum allowed value.
Definition: int_set_traits.h:66
static constexpr Element_t prev(const Element_t &element)
Definition: int_set_traits.h:93
static constexpr bool lt_impl(const Element_t &left, const Element_t &right)
Definition: int_set_traits.h:76
Helper CRTP base class to define Ordered Set traits classes, which are optionally Bounded and/or Metr...
Definition: ordered_set_traits_interface.h:90
Element_tp Element_t
Definition: ordered_set_traits_interface.h:104
Difference_tp Difference_t
Definition: ordered_set_traits_interface.h:105