MySQL 9.6.0
Source Code Documentation
base_binary_operation_views.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_BASE_BINARY_OPERATION_VIEWS_H
25#define MYSQL_SETS_BASE_BINARY_OPERATION_VIEWS_H
26
27/// @file
28/// Experimental API header
29
30#include <ranges> // enable_view
31#include <type_traits> // is_pointer_v
32#include "mysql/sets/binary_operation.h" // Binary_operation
33
34/// @addtogroup GroupLibsMysqlSets
35/// @{
36///
37/// This file defines the primary template classes and factory functions for
38/// `Union_view`, `Intersection_view`, and `Subtraction_view`. Each set category
39/// may specialize the primary template to classes of the category. The operands
40/// may be of different types, but must have the same Set traits.
41///
42/// This file also declares that the views satisfy `std::ranges::view`. And it
43/// contains a helper enum type that lists the three set operations.
44
45// ==== Primary templates ====
46
47namespace mysql::sets {
48
49/// Primary template for views over unions of two sets operations.
50///
51/// This can be specialized to specific set categories, e.g. boundary sets,
52/// interval sets, and nested sets.
53template <class Source1_tp, class Source2_tp>
55
56/// Primary template for views over intersections of two sets operations.
57///
58/// This can be specialized to specific set categories, e.g. boundary sets,
59/// interval sets, and nested sets.
60template <class Source1_tp, class Source2_tp>
62
63/// Primary template for views over subtractions of two sets operations.
64///
65/// This can be specialized to specific set categories, e.g. boundary sets,
66/// interval sets, and nested sets.
67template <class Source1_tp, class Source2_tp>
69
70// ==== Parameterization by Binary_operation ====
71
72/// For a Binary_operation and two operand sets, gives the corresponding
73/// Union_view, Intersection_view, or Subtraction_view class.
74//
75// The casts to int are workarounds for what appears to be a bug in MSVC 19.29
76// (VS16.11). It gives the error "error C2677: binary '==': no global operator
77// found which takes type 'mysql::sets::Binary_operation' (or there is no
78// acceptable conversion)".
79//
80// @todo Remove the casts when we drop support for the buggy compiler version.
81template <Binary_operation binary_operation, class Source1_t, class Source2_t>
82using Binary_operation_view_type = std::conditional_t<
83 (int)binary_operation == (int)Binary_operation::op_union,
85 std::conditional_t<
86 (int)binary_operation == (int)Binary_operation::op_intersection,
88 std::conditional_t<(int)binary_operation ==
91 /*impossible*/ void>>>;
92
93// ==== Factory functions ====
94
95/// Return the Union_view, Intersection_view, or Subtraction_view over the
96/// arguments, according to the given Binary_operation.
97///
98/// @tparam binary_operation Type of operation.
99///
100/// @tparam Source1_t Type of first operand.
101///
102/// @tparam Source2_t Type of second operand.
103///
104/// @param source1 First operand.
105///
106/// @param source2 Second operand.
107template <Binary_operation binary_operation, class Source1_t, class Source2_t>
108[[nodiscard]] auto make_binary_operation_view(const Source1_t &source1,
109 const Source2_t &source2) {
110 static_assert(!std::is_pointer_v<Source1_t> && !std::is_pointer_v<Source2_t>);
112 source1, source2);
113}
114
115/// Return the Union_view over the arguments.
116///
117/// @tparam Source1_t Type of first operand.
118///
119/// @tparam Source2_t Type of second operand.
120///
121/// @param source1 First operand.
122///
123/// @param source2 Second operand.
124template <class Source1_t, class Source2_t>
125[[nodiscard]] auto make_union_view(const Source1_t &source1,
126 const Source2_t &source2) {
127 return make_binary_operation_view<Binary_operation::op_union>(source1,
128 source2);
129}
130
131/// Return the Intersection_view over the arguments.
132///
133/// @tparam Source1_t Type of first operand.
134///
135/// @tparam Source2_t Type of second operand.
136///
137/// @param source1 First operand.
138///
139/// @param source2 Second operand.
140template <class Source1_t, class Source2_t>
141[[nodiscard]] auto make_intersection_view(const Source1_t &source1,
142 const Source2_t &source2) {
143 return make_binary_operation_view<Binary_operation::op_intersection>(source1,
144 source2);
145}
146
147/// Return the Subtraction_view over the arguments.
148///
149/// @tparam Source1_t Type of first operand.
150///
151/// @tparam Source2_t Type of second operand.
152///
153/// @param source1 First operand.
154///
155/// @param source2 Second operand.
156template <class Source1_t, class Source2_t>
157[[nodiscard]] auto make_subtraction_view(const Source1_t &source1,
158 const Source2_t &source2) {
159 return make_binary_operation_view<Binary_operation::op_subtraction>(source1,
160 source2);
161}
162
163} // namespace mysql::sets
164
165// ==== Declarations of std::ranges::enable_view ====
166
167/// @cond DOXYGEN_DOES_NOT_UNDERSTAND_THIS
168/// Declare that Union_view is a view.
169template <class Source1_t, class Source2_t>
170constexpr bool
171 std::ranges::enable_view<mysql::sets::Union_view<Source1_t, Source2_t>> =
172 true;
173
174/// Declare that Intersection_view is a view.
175template <class Source1_t, class Source2_t>
176constexpr bool std::ranges::enable_view<
178
179/// Declare that Subtraction_view is a view.
180template <class Source1_t, class Source2_t>
181constexpr bool std::ranges::enable_view<
183/// @endcond
184
185// addtogroup GroupLibsMysqlSets
186/// @}
187
188#endif // ifndef MYSQL_SETS_BASE_BINARY_OPERATION_VIEWS_H
Experimental API header.
Primary template for views over intersections of two sets operations.
Definition: base_binary_operation_views.h:61
Primary template for views over subtractions of two sets operations.
Definition: base_binary_operation_views.h:68
Primary template for views over unions of two sets operations.
Definition: base_binary_operation_views.h:54
Definition: gtid_set.h:183
auto make_union_view(const Source1_t &source1, const Source2_t &source2)
Return the Union_view over the arguments.
Definition: base_binary_operation_views.h:125
auto make_binary_operation_view(const Source1_t &source1, const Source2_t &source2)
Return the Union_view, Intersection_view, or Subtraction_view over the arguments, according to the gi...
Definition: base_binary_operation_views.h:108
auto make_subtraction_view(const Source1_t &source1, const Source2_t &source2)
Return the Subtraction_view over the arguments.
Definition: base_binary_operation_views.h:157
std::conditional_t<(int) binary_operation==(int) Binary_operation::op_union, Union_view< Source1_t, Source2_t >, std::conditional_t<(int) binary_operation==(int) Binary_operation::op_intersection, Intersection_view< Source1_t, Source2_t >, std::conditional_t<(int) binary_operation==(int) Binary_operation::op_subtraction, Subtraction_view< Source1_t, Source2_t >, void > > > Binary_operation_view_type
For a Binary_operation and two operand sets, gives the corresponding Union_view, Intersection_view,...
Definition: base_binary_operation_views.h:91
auto make_intersection_view(const Source1_t &source1, const Source2_t &source2)
Return the Intersection_view over the arguments.
Definition: base_binary_operation_views.h:141