MySQL 9.6.0
Source Code Documentation
optional_view_source_set.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_OPTIONAL_VIEW_SOURCE_SET_H
25#define MYSQL_SETS_OPTIONAL_VIEW_SOURCE_SET_H
26
27/// @file
28/// Experimental API header
29
30#include <utility> // forward
31#include "mysql/meta/not_decayed.h" // Not_decayed
32#include "mysql/ranges/view_sources.h" // Optional_view_source
34
35/// @addtogroup GroupLibsMysqlSets
36/// @{
37///
38/// This file defines helper functions used by views whose source(s) are
39/// optional. When an optional source is absent, it is treated as an empty set.
40
41namespace mysql::sets {
42
43/// Used to represent an optional source of a view, when that source is a set.
44/// Provides the functions find, lower_bound, and upper_bound which work even if
45/// the optional source is absent, in which case they return the end iterator.
46template <Is_set Source_tp>
48 : public mysql::ranges::Optional_view_source<Source_tp> {
51
52 public:
53 /// Delegate construction to Optional_view_source
54 template <class... Args_t>
55 requires mysql::meta::Not_decayed<This_t, Args_t...>
56 explicit Optional_view_source_set(Args_t &&...args)
57 : Base_t(std::forward<Args_t>(args)...) {}
58
59 /// Default rule-of-5
63 default;
66
67 /// If the source is present, invoke find on it. Otherwise, return an end
68 /// iterator.
69 template <class... Args_t>
70 [[nodiscard]] auto find(Args_t &&...args) const {
71 if (!this->has_object()) return Base_t::null_iterator();
72 return (*this)->find(std::forward<Args_t>(args)...);
73 }
74
75 /// If the source is present, invoke lower_bound on it. Otherwise, return an
76 /// end iterator.
77 template <class... Args_t>
78 [[nodiscard]] auto lower_bound(Args_t &&...args) const {
79 if (!this->has_object()) return Base_t::null_iterator();
80 return (*this)->lower_bound(std::forward<Args_t>(args)...);
81 }
82
83 /// If the source is present, invoke upper_bound on it. Otherwise, return an
84 /// end iterator.
85 template <class... Args_t>
86 [[nodiscard]] auto upper_bound(Args_t &&...args) const {
87 if (!this->has_object()) return Base_t::null_iterator();
88 return (*this)->upper_bound(std::forward<Args_t>(args)...);
89 }
90}; // class Optional_view_source_set
91
92} // namespace mysql::sets
93
94// addtogroup GroupLibsMysqlSets
95/// @}
96
97#endif // ifndef MYSQL_SETS_OPTIONAL_VIEW_SOURCE_SET_H
std::optional-like wrapper around an object that is the source for a view: this may hold an object or...
Definition: view_sources.h:200
static auto null_iterator()
Definition: view_sources.h:279
bool has_object() const
Return true if this object holds a source.
Definition: view_sources.h:229
Used to represent an optional source of a view, when that source is a set.
Definition: optional_view_source_set.h:48
auto upper_bound(Args_t &&...args) const
If the source is present, invoke upper_bound on it.
Definition: optional_view_source_set.h:86
Optional_view_source_set< Source_tp > This_t
Definition: optional_view_source_set.h:50
Optional_view_source_set(Optional_view_source_set &&)=default
auto lower_bound(Args_t &&...args) const
If the source is present, invoke lower_bound on it.
Definition: optional_view_source_set.h:78
auto find(Args_t &&...args) const
If the source is present, invoke find on it.
Definition: optional_view_source_set.h:70
Optional_view_source_set & operator=(Optional_view_source_set &&)=default
Optional_view_source_set(Args_t &&...args)
Delegate construction to Optional_view_source.
Definition: optional_view_source_set.h:56
Optional_view_source_set(const Optional_view_source_set &)=default
Default rule-of-5.
Optional_view_source_set & operator=(const Optional_view_source_set &)=default
false if Args is exactly one type, say A, and std::decay_t<A> equals Type.
Definition: not_decayed.h:84
Definition: gtid_set.h:183
Define std::hash<Gtid>.
Definition: gtid.h:355
Experimental API header.
Experimental API header.
Experimental API header.