MySQL 9.6.0
Source Code Documentation
set_container_helpers.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_CONTAINER_HELPERS_H
25#define MYSQL_SETS_SET_CONTAINER_HELPERS_H
26
27/// @file
28/// Experimental API header
29
30#include <utility> // forward
31#include "mysql/sets/binary_operation.h" // Binary_operation
32#include "mysql/sets/meta.h" // Has_fast_size
33#include "mysql/utils/is_same_object.h" // is_same_object
34
35/// @addtogroup GroupLibsMysqlSets
36/// @{
37
38namespace mysql::sets::detail {
39
40/// Handle the trivial cases of inplace union/intersection/subtraction where
41/// either both operands refer to the same set or one is empty.
42///
43/// @return true if a trivial case applied and was executed, false otherwise.
44template <Binary_operation operation, class Target_t, class Source_t>
45bool handle_inplace_op_trivial_cases(Target_t &target, Source_t &&source) {
47 if constexpr (operation == Binary_operation::op_subtraction) target.clear();
48 // self-union and self-intersection are no-ops.
49 return true;
50 }
51 if (Has_fast_size<Source_t> && source.empty()) {
52 if constexpr (operation == Binary_operation::op_intersection)
53 target.clear();
54 // union and subtraction with an empty set RHS are no-ops.
55 return true;
56 }
57 if (Has_fast_size<Target_t> && target.empty()) {
58 if constexpr (operation == Binary_operation::op_union) {
59 // Overwrite target by source, if we can do it without having to propagate
60 // a returned error status. (Which typically is the case if target is
61 // throwing).
62 if constexpr (std::same_as<decltype(target.assign(
63 std::forward<Source_t>(source))),
64 void>) {
65 target.assign(std::forward<Source_t>(source));
66 return true;
67 }
68 } else {
69 // intersection and subtraction on an empty set LHS are no-ops.
70 return true;
71 }
72 }
73 return false;
74}
75
76} // namespace mysql::sets::detail
77
78// addtogroup GroupLibsMysqlSets
79/// @}
80
81#endif // ifndef MYSQL_SETS_SET_CONTAINER_HELPERS_H
Experimental API header.
Determines if the given type has "fast" size computations.
Definition: meta.h:61
Experimental API header.
Experimental API header.
Definition: aliases.h:97
bool handle_inplace_op_trivial_cases(Target_t &target, Source_t &&source)
Handle the trivial cases of inplace union/intersection/subtraction where either both operands refer t...
Definition: set_container_helpers.h:45
bool is_same_object(const Obj1_t &obj1, const Obj2_t &obj2)
Return true if the types of the two objects are either equal or one derived from the other,...
Definition: is_same_object.h:40
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42