MySQL 9.6.0
Source Code Documentation
nested_set_binary_operation_view_interface.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_NESTED_SET_BINARY_OPERATION_VIEW_INTERFACE_H
25#define MYSQL_SETS_NESTED_SET_BINARY_OPERATION_VIEW_INTERFACE_H
26
27/// @file
28/// Experimental API header
29
30#include <cassert> // assert
31#include "mysql/sets/binary_operation.h" // Binary_operation
32#include "mysql/sets/nested_set_category.h" // Nested_set_category_tag
33#include "mysql/sets/nested_set_interface.h" // Nested_view_interface
34#include "mysql/sets/nested_set_intersection_iterator.h" // Nested_set_intersection_iterator
35#include "mysql/sets/nested_set_meta.h" // Is_nested_set
36#include "mysql/sets/nested_set_subtraction_iterator.h" // Nested_set_subtraction_iterator
37#include "mysql/sets/nested_set_union_iterator.h" // Nested_set_union_iterator
38#include "mysql/sets/optional_view_source_set.h" // Optional_view_source_set
39#include "mysql/sets/set_categories_and_traits.h" // Is_compatible_set
40
41/// @addtogroup GroupLibsMysqlSets
42/// @{
43
44namespace mysql::sets::detail {
45
46/// Type alias that provides the iterator type for a given Binary_operation.
47///
48/// @tparam Source1_t The first source.
49///
50/// @tparam Source2_t The second source.
51///
52/// @tparam operation_t The binary operation.
53//
54// The casts to int are workarounds for what appears to be a bug in MSVC 19.29
55// (VS16.11). It gives the error "error C2677: binary '==': no global operator
56// found which takes type 'mysql::sets::Binary_operation' (or there is no
57// acceptable conversion)".
58//
59// @todo Remove the casts when we drop support for the buggy compiler version.
60template <Is_nested_set Source1_t, Is_nested_set Source2_t,
61 Binary_operation operation_t>
62using Nested_binary_operation_iterator_type = std::conditional_t<
63 (int)operation_t == (int)Binary_operation::op_union,
65 std::conditional_t<(int)operation_t ==
69
70/// Common base class for all the view classes.
71///
72/// @tparam Source1_tp The first source.
73///
74/// @tparam Source2_tp The second source.
75///
76/// @tparam operation_tp The binary operation.
77template <class Self_tp, Is_nested_set Source1_tp, Is_nested_set Source2_tp,
78 Binary_operation operation_tp>
81 : public Nested_view_interface<Self_tp,
82 Nested_binary_operation_iterator_type<
83 Source1_tp, Source2_tp, operation_tp>,
84 Nested_binary_operation_iterator_type<
85 Source1_tp, Source2_tp, operation_tp>,
86 typename Source1_tp::Set_traits_t> {
87 using Self_t = Self_tp;
88
89 public:
90 using Source1_t = Source1_tp;
91 using Source2_t = Source2_tp;
94 static constexpr auto operation = operation_tp;
97 using Set_traits_t = typename Source1_t::Set_traits_t;
99 using Key_traits_t = typename Set_traits_t::Key_traits_t;
100 using Mapped_traits_t = typename Set_traits_t::Mapped_traits_t;
101 using Mapped_category_t = typename Set_traits_t::Mapped_category_t;
102 using Key_t = typename Key_traits_t::Element_t;
105 using Mapped_t = typename Iterator_t::Mapped_t;
106 using Value_t = typename Iterator_t::Value_t;
107 static constexpr bool disable_fast_size = true;
108
110
111 /// Construct a new Nested_set_binary_operation_view_interface over the given
112 /// sources.
113 ///
114 /// @param source1 The first source.
115 ///
116 /// @param source2 The second source.
118 const Source2_t &source2) noexcept
119 : m_source1(source1), m_source2(source2) {}
120
121 /// Construct a new Nested_set_binary_operation_view_interface over the given
122 /// sources.
123 ///
124 /// Use this constructor if one of the sources may be empty and you do not
125 /// have an object representing it; then pass nullptr for that source.
126 ///
127 /// @param source1 The first source, or nullptr for empty set.
128 ///
129 /// @param source2 The second source, or nullptr for empty set.
131 const Source2_t *source2) noexcept
132 : m_source1(source1), m_source2(source2) {}
133
134 // Default rule-of-5.
136 const Nested_set_binary_operation_view_interface &) noexcept = default;
144
145 [[nodiscard]] auto operator[](const Key_t &key) const noexcept {
146 auto it = self().find(key);
147 assert(it != self().end());
148 return it->second;
149 }
150
151 [[nodiscard]] auto operator[](const Key_t &key) noexcept {
152 auto it = self().find(key);
153 assert(it != self().end());
154 return it->second;
155 }
156
157 protected:
158 // Return a new iterator based on the two given source iterators.
159 [[nodiscard]] Iterator_t make_iterator(const Iterator1_t &iterator1,
160 const Iterator2_t &iterator2) const {
161 return Iterator_t(m_source1.pointer(), m_source2.pointer(), iterator1,
162 iterator2);
163 }
164
165 /// Pointer to the first nested set operand.
167
168 /// Pointer to the second nested set operand.
170
171 private:
172 [[nodiscard]] const auto &self() const {
173 return static_cast<const Self_t &>(*this);
174 }
175 [[nodiscard]] auto &self() { return static_cast<Self_t &>(*this); }
176}; // class Nested_set_binary_operation_view_interface
177
178} // namespace mysql::sets::detail
179
180// addtogroup GroupLibsMysqlSets
181/// @}
182
183#endif // ifndef MYSQL_SETS_NESTED_SET_BINARY_OPERATION_VIEW_INTERFACE_H
Experimental API header.
Self_tp Self_t
Definition: collection_interface.h:91
const Source_t * pointer() const
Return a pointer to the source if there is one, or nullptr otherwise.
Definition: view_sources.h:242
CRTP base class/mixin used to implement Nested sets that are views.
Definition: nested_set_interface.h:131
Common base class for all the view classes.
Definition: nested_set_binary_operation_view_interface.h:86
mysql::ranges::Range_const_iterator_type< Source1_t > Iterator1_t
Definition: nested_set_binary_operation_view_interface.h:95
typename Set_traits_t::Mapped_traits_t Mapped_traits_t
Definition: nested_set_binary_operation_view_interface.h:100
Source2_tp Source2_t
Definition: nested_set_binary_operation_view_interface.h:91
typename Iterator_t::Value_t Value_t
Definition: nested_set_binary_operation_view_interface.h:106
Nested_binary_operation_iterator_type< Source1_t, Source2_t, operation > Iterator_t
Definition: nested_set_binary_operation_view_interface.h:104
typename Set_traits_t::Mapped_category_t Mapped_category_t
Definition: nested_set_binary_operation_view_interface.h:101
Nested_set_binary_operation_view_interface(Nested_set_binary_operation_view_interface &&) noexcept=default
typename Key_traits_t::Element_t Key_t
Definition: nested_set_binary_operation_view_interface.h:102
typename Source1_t::Set_traits_t Set_traits_t
Definition: nested_set_binary_operation_view_interface.h:97
Nested_set_binary_operation_view_interface(const Source1_t &source1, const Source2_t &source2) noexcept
Construct a new Nested_set_binary_operation_view_interface over the given sources.
Definition: nested_set_binary_operation_view_interface.h:117
Source1_tp Source1_t
Definition: nested_set_binary_operation_view_interface.h:90
typename Iterator_t::Mapped_t Mapped_t
Definition: nested_set_binary_operation_view_interface.h:105
Opt_source2_t m_source2
Pointer to the second nested set operand.
Definition: nested_set_binary_operation_view_interface.h:169
auto operator[](const Key_t &key) noexcept
Definition: nested_set_binary_operation_view_interface.h:151
Opt_source1_t m_source1
Pointer to the first nested set operand.
Definition: nested_set_binary_operation_view_interface.h:166
Nested_set_binary_operation_view_interface(const Source1_t *source1, const Source2_t *source2) noexcept
Construct a new Nested_set_binary_operation_view_interface over the given sources.
Definition: nested_set_binary_operation_view_interface.h:130
mysql::ranges::Range_const_iterator_type< Source2_t > Iterator2_t
Definition: nested_set_binary_operation_view_interface.h:96
static constexpr auto operation
Definition: nested_set_binary_operation_view_interface.h:94
typename Set_traits_t::Key_traits_t Key_traits_t
Definition: nested_set_binary_operation_view_interface.h:99
Iterator_t make_iterator(const Iterator1_t &iterator1, const Iterator2_t &iterator2) const
Definition: nested_set_binary_operation_view_interface.h:159
Nested_set_binary_operation_view_interface(const Nested_set_binary_operation_view_interface &) noexcept=default
static constexpr bool disable_fast_size
Definition: nested_set_binary_operation_view_interface.h:107
Iterator over the intersection of two sets.
Definition: nested_set_intersection_iterator.h:50
Iterator over the difference of two sets.
Definition: nested_set_subtraction_iterator.h:50
Iterator over the union of two sets.
Definition: nested_set_union_iterator.h:51
True if Set1_t and Set2_t have the same Set_category_t and Set_traits_t.
Definition: set_categories_and_traits.h:77
True if Test is a nested set.
Definition: nested_set_meta.h:110
Container::const_iterator find(const Container &c, Value &&value)
Definition: generic.h:39
std::remove_cvref_t< decltype(std::declval< const Range_t >().begin())> Range_const_iterator_type
Gives the const_iterator type, deduced from the begin() const member.
Definition: meta.h:47
Definition: aliases.h:97
std::conditional_t<(int) operation_t==(int) Binary_operation::op_union, Nested_set_union_iterator< Source1_t, Source2_t >, std::conditional_t<(int) operation_t==(int) Binary_operation::op_intersection, Nested_set_intersection_iterator< Source1_t, Source2_t >, Nested_set_subtraction_iterator< Source1_t, Source2_t > > > Nested_binary_operation_iterator_type
Type alias that provides the iterator type for a given Binary_operation.
Definition: nested_set_binary_operation_view_interface.h:68
Binary_operation
Identifies the type of a binary operation.
Definition: binary_operation.h:37
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
Experimental API header.
Experimental API header.
Experimental API header.
Experimental API header.
Experimental API header.
Experimental API header.
Experimental API header.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
Experimental API header.
Tag to identify a class as a Nested set.
Definition: nested_set_category.h:41