Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
set.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5///
6/// @file set.hpp
7/// @brief Provides the implementation of @c arene::base::inline_set .
8///
9#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_SET_HPP_
10#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_SET_HPP_
11
12// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
22#include "arene/base/inline_container/detail/compare.hpp"
23#include "arene/base/inline_container/detail/index_array.hpp"
24#include "arene/base/inline_container/detail/lower_bound_index.hpp"
30#include "arene/base/stdlib_choice/cstddef.hpp"
31#include "arene/base/stdlib_choice/enable_if.hpp"
32#include "arene/base/stdlib_choice/forward.hpp"
33#include "arene/base/stdlib_choice/ignore.hpp"
34#include "arene/base/stdlib_choice/initializer_list.hpp"
35#include "arene/base/stdlib_choice/integer_sequence.hpp"
36#include "arene/base/stdlib_choice/integral_constant.hpp"
37#include "arene/base/stdlib_choice/is_assignable.hpp"
38#include "arene/base/stdlib_choice/is_constructible.hpp"
39#include "arene/base/stdlib_choice/is_copy_assignable.hpp"
40#include "arene/base/stdlib_choice/is_copy_constructible.hpp"
41#include "arene/base/stdlib_choice/is_destructible.hpp"
42#include "arene/base/stdlib_choice/is_integral.hpp"
43#include "arene/base/stdlib_choice/is_move_assignable.hpp"
44#include "arene/base/stdlib_choice/is_move_constructible.hpp"
45#include "arene/base/stdlib_choice/iterator_tags.hpp"
46#include "arene/base/stdlib_choice/iterator_traits.hpp"
47#include "arene/base/stdlib_choice/move.hpp"
48#include "arene/base/stdlib_choice/pair.hpp"
59// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
60
61namespace arene {
62namespace base {
63
64// forward declaration
65// IWYU pragma: begin_keep
66template <typename Value, std::size_t Capacity, typename Compare>
67class inline_set;
68// IWYU pragma: end_keep
69
70namespace inline_set_detail {
71/// @brief Tag type to indicate the comparator for an inline_set
72struct inline_set_comparator_tag {};
73
74/// @brief Passkey type for iterator access.
75class set_passkey {
76 private:
77 /// @brief Prevent construction from @c {}
78 explicit set_passkey() = default;
79
80 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "Passkey idiom permitted by A11-3-1 Permit #1"
81 /// @brief friend declaration to allow inline_set to construct the passkey.
82 template <typename Value, std::size_t Capacity, typename Compare>
83 friend class ::arene::base::inline_set;
84 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
85};
86} // namespace inline_set_detail
87
88// parasoft-begin-suppress AUTOSAR-A12_1_5-a-2 "False positive: delegating constructors are used"
89// parasoft-begin-suppress AUTOSAR-A10_1_1-a-2 "False positive: 'generic_ordering_from_three_way_compare' is an
90// interface"
91// parasoft-begin-suppress AUTOSAR-A12_0_1-a-2 "False Positive: Copy operations are defined or deleted as appropriate"
92// parasoft-begin-suppress AUTOSAR-A1_1_1-b-2 "False Positive: Copy operations are defined or deleted as appropriate"
93/// @brief A non-allocating fixed-capacity associative container storing elements of type @c Value .
94///
95/// Any attempt to store more than @c Capacity elements will result in an @c ARENE_PRECONDITION violation. The
96/// comparison function specified with the @c Compare template parameter can either return @c bool, in which case it is
97/// assumed to be a simple ordering comparison like @c std::less, or it can return @c strong_ordering, in which case it
98/// is assumed to be a three-way comparison operator. The default comparison is @c three_way_compare.
99/// @tparam Value The type of values stored in the set. Must satisfy @c std::is_nothrow_destructible .
100/// @tparam Capacity The maximum number of elements that can be stored in the set .
101/// @tparam Compare The comparison function used to impose a sort order on the elements. Must satisfy
102/// @c std::is_nothrow_destructible as well as either
103/// <c>is_invocable_r_v<bool, const Compare&, const Value&, const Value&></c> or
104/// <c>is_invocable_r_v<strong_ordering, const Compare&, const Value&, const Value&></c>. The comparison must
105/// provide a strict ordering over the values of @c Value , and copies or moves of the comparator must yield the
106/// same ordering. Defaults to @c compare_three_way .
107template <typename Value, std::size_t Capacity, typename Compare = compare_three_way>
108// NOLINTNEXTLINE(hicpp-special-member-functions)
110 : inline_container::detail::compare_wrapper<Compare, Value>
111 , generic_ordering_from_three_way_compare<inline_set<Value, Capacity, Compare>> {
112 static_assert(std::is_nothrow_destructible<Value>::value, "Destructors must not throw");
113 static_assert(std::is_nothrow_destructible<Compare>::value, "Destructors must not throw");
114 static_assert(
117 "Compare must be invocable with two Values, and yield either a bool or a strong_ordering"
118 );
119
120 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
121 /// @brief helper trait for determining if the comparator supports transparent comparisons.
122 /// @tparam OtherKey the type of the other operand to test for validity against.
123 /// @return bool @c true If @c Compare satisfies either @c is_transparent_comparator_for_v or
124 /// @c is_transparent_three_way_comparator_for_v with @c Value and @c OtherKey , else @c false .
125 template <typename OtherKey>
126 static constexpr bool
128 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
129
130 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
131 /// @brief The base class that holds the comparator
132 using comparator_base = inline_container::detail::compare_wrapper<Compare, Value>;
133 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
134 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
135 /// @brief The base class that injects operator overloads.
137 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
138
139 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
140 /// @brief Can comparisons throw?
141 /// @tparam OtherKey The type of the rhs operand to a comparison.
142 /// @return bool alias for @c comparator_base::template comparison_is_noexcept<OtherKey>
143 template <typename OtherKey = Value>
144 static constexpr bool comparison_is_noexcept{comparator_base::template comparison_is_noexcept<OtherKey>};
145 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
146
147 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
148 /// @brief The type of each element in the index
150 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
151
152 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
153 /// @brief The type of the storage for an individual element
154 using entry_type = optional<Value>;
155 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
156
157 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
158 /// @brief The argument to the "move constructor": @c inline_set if the move constructor is supported, @c
159 /// non_constructible_dummy otherwise
160 using move_construct_source = conditional_t<
164 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
165 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
166 /// @brief The argument to the "move assignment operator": @c inline_set if the move assignment operator is supported,
167 /// @c non_constructible_dummy otherwise
168 using move_assign_source = conditional_t<
172 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
173 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
174 /// @brief The argument to the deleted "move assignment operator": @c inline_set if the move assignment operator is
175 /// NOT supported, @c non_constructible_dummy otherwise
176 using deleted_move_assign_source = conditional_t<
179 inline_set>;
180 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
181 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
182 /// @brief The argument to the "copy assignment operator": @c inline_set if the copy assignment operator is supported,
183 /// @c non_constructible_dummy otherwise
184 using copy_assign_source = conditional_t<
188 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
189 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
190 /// @brief The argument to the deleted "copy assignment operator": @c inline_set if the copy assignment operator is
191 /// NOT supported, @c non_constructible_dummy otherwise
192 using deleted_copy_assign_source = conditional_t<
195 inline_set>;
196 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
197
198 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
199 /// @brief An iterator into an @c inline_set
200 class iterator_impl : generic_ordering_from_three_way_compare<iterator_impl> {
201 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
202 /// @brief The set
203 inline_set const* set_{nullptr};
204 /// @brief The index to the target element
205 index_type element_index_{0};
206
207 public:
208 /// @brief The category of this iterator
209 using iterator_category = std::bidirectional_iterator_tag;
210
211 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "Required type alias to meet iterator requirements"
212 /// @brief The value type
213 using value_type = Value;
214 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
215
216 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "Required type alias to meet iterator requirements"
217 /// @brief The return type of @c operator->
218 using pointer = Value const*;
219 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
220
221 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "Required type alias to meet iterator requirements"
222 /// @brief The return type of @c operator*
223 using reference = Value const&;
224 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
225
226 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "Required type alias to meet iterator requirements"
227 /// @brief The type of the difference between two iterators
229 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
230
231 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
232 // initialize the base class"
233 /// @brief A default constructed iterator has no associated set
234 /// @post @c is_for(/*non-null*/) will return @c false .
235 /// @post @c index() will return @c 0 .
236 iterator_impl() noexcept
237 : iterator_impl(inline_set_detail::set_passkey{}, nullptr, 0U) {}
238 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
239
240 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
241 /// @brief Construct an iterator for the specified set and element index
242 ///
243 /// @param set_to_iterate The set to refer to
244 /// @param element The index into @c inline_set::indices_ of the element the iterator currently points to.
245 /// @post @c is_for(set_to_iterate) will return @c true .
246 /// @post @c index() will return @c element .
247 iterator_impl(inline_set_detail::set_passkey, inline_set const* set_to_iterate, index_type element) noexcept
249 set_(set_to_iterate),
250 element_index_(element) {}
251 // parasoft-end-suppress CERT_C-EXP37-a-3
252
253 /// @brief Get a reference to the target element
254 ///
255 /// @return reference A reference to the element at the current position.
256 /// @pre @c *this!=iterator{} , else @c ARENE_PRECONDITION violation.
257 /// @pre The iterator is in the valid range of the set, else @c ARENE_PRECONDITION violation.
258 auto operator*() const noexcept -> reference {
259 ARENE_PRECONDITION(set_ != nullptr);
260 return *(set_->values_[set_->indices_[element_index_]]);
261 }
262 /// @brief Get a pointer to the target element
263 ///
264 /// @return pointer A pointer to the element at the current position.
265 /// @pre @c *this!=iterator{} , else @c ARENE_PRECONDITION violation.
266 /// @pre The iterator is in the valid range of the set, else @c ARENE_PRECONDITION violation.
267 auto operator->() const noexcept -> pointer { return &**this; }
268
269 /// @brief Pre-increment the iterator
270 ///
271 /// @return iterator& The iterator post-modification
272 /// @post The iterator points to the next position in the set.
273 auto operator++() noexcept -> iterator_impl& {
274 ++element_index_;
275 return *this;
276 }
277
278 // parasoft-begin-suppress AUTOSAR-A3_9_1-b-2 "False positive: postincrement requires an int parameter"
279 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
280 /// @brief Post-increment the iterator
281 ///
282 /// @return iterator A copy of the iterator pre-modification
283 /// @post The iterator points to the next position in the set.
284 auto operator++(int) noexcept -> iterator_impl {
285 iterator temp{*this};
286 ++(*this);
287 return temp;
288 }
289 // parasoft-end-suppress CERT_C-EXP37-a-3
290 // parasoft-end-suppress AUTOSAR-A3_9_1-b-2
291
292 /// @brief Pre-decrement the iterator
293 ///
294 /// @return iterator& The iterator post-modification
295 /// @post The iterator points to the previous position in the set.
296 auto operator--() noexcept -> iterator_impl& {
297 ARENE_PRECONDITION(element_index_ > 0U);
298 --element_index_;
299 return *this;
300 }
301
302 // parasoft-begin-suppress AUTOSAR-A3_9_1-b-2 "False positive: postdecrement requires an int parameter"
303 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
304 /// @brief Post-increment the iterator
305 ///
306 /// @return iterator A copy of the iterator pre-modification
307 /// @post The iterator points to the previous position in the set.
308 auto operator--(int) noexcept -> iterator_impl {
309 iterator temp{*this};
310 --(*this);
311 return temp;
312 }
313 // parasoft-end-suppress CERT_C-EXP37-a-3
314 // parasoft-end-suppress AUTOSAR-A3_9_1-b-2
315
316 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
317 /// @brief Do three-way comparison on the provided iterators.
318 ///
319 /// @param lhs The first iterator to compare
320 /// @param rhs The second iterator to compare
321 /// @return @c strong_ordering::less if @c lhs comes before @c rhs in iteration order.
322 /// @return @c strong_ordering::equal if @c lhs is the same as @c rhs in iteration order.
323 /// @return @c strong_ordering::greater if @c lhs comes after @c rhs in iteration order.
324 /// @pre The iterators must be constructed from the same @c inline_set instance, else @c ARENE_PRECONDITION
325 /// violation.
326 static auto three_way_compare(iterator_impl const lhs, iterator_impl const rhs) noexcept -> strong_ordering {
327 ARENE_PRECONDITION(lhs.is_for(rhs.set_));
328 return compare_three_way{}(lhs.element_index_, rhs.element_index_);
329 }
330 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
331
332 /// @brief check if iterators are from the same set.
333 ///
334 /// @param set_to_check The set to check for
335 /// @return true if @c this->set_==set_to_check
336 /// @return false otherwise
337 auto is_for(inline_set const* set_to_check) const noexcept -> bool { return set_ == set_to_check; }
338
339 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
340 /// @brief Get the position this iterator references within a set.
341 /// Can only be called by members of @c inline_set
342 /// @return index_type The index position of this iterator.
343 auto index(inline_set_detail::set_passkey) const noexcept -> index_type { return element_index_; }
344 // parasoft-end-suppress CERT_C-EXP37-a-3
345 };
346
347 public:
348 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
349 /// @brief The type of the value in the set
350 using value_type = Value;
351 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
352
353 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
354 /// @brief The type of the comparator for the value
355 using value_compare = Compare;
356 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
357
358 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
359 /// @brief The type of the key in the set, which is the same as the value
360 using key_type = Value;
361 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
362
363 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
364 /// @brief The type of the comparator for the key
365 using key_compare = Compare;
366 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
367
368 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
369 /// @brief A pointer to the value
371 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
372
373 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
374 /// @brief A pointer to a const value
375 using const_pointer = value_type const*;
376 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
377
378 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
379 /// @brief A reference to a value
381 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
382
383 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
384 /// @brief A reference to a const value
386 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
387
388 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
389 /// @brief The type of the size of the container
391 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
392
393 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
394 /// @brief The type of the difference between two iterators
396 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
397
398 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
399 /// @brief The iterator type for the set.
400 using iterator = iterator_impl;
401 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
402
403 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
404 /// @brief A const iterator for the set: the same as @c iterator, since elements are @c const
406 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
407
408 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
409 /// @brief A reverse iterator for the set
411 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
412
413 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
414 /// @brief A const reverse iterator for the set.
416 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
417
418 /// @brief Construct a set with no elements and a default-constructed comparator
419 inline_set() = default;
420
421 /// @brief Default destructor; destroys all stored elements
422 ~inline_set() = default;
423
424 /// @brief Construct a set with no elements, using the specified comparator
425 ///
426 /// @param comp The comparator to use
427 /// @post @c size()==0
429 : comparator_base(comp),
430 operator_base() {}
431
432 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
433 /// @brief Construct a set from the specified list of values.
434 ///
435 /// @param init The list of elements to store in the set
436 /// @post @c size()==init.size()
437 /// @post The elements in the set will be the unique elements of @c init , sorted via a default-constructed instance
438 /// of @c Compare .
439 /// @pre @c init.size()<=max_size() else @c ARENE_PRECONDITION violation .
445 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
446
447 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
448 /// @brief Construct a set from the specified list of values and a specified comparator instance .
449 ///
450 /// @param init The list of elements to store in the set .
451 /// @param comp The comparator to use.
452 /// @post @c size()==init.size()
453 /// @post The elements in the set will be the unique elements of @c init , sorted via @c comp .
454 /// @pre @c init.size()<=max_size() else @c ARENE_PRECONDITION violation .
461 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
462
463 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
464 /// @brief Attempt to construct a set from the specified list of values.
465 ///
466 /// @param init The list of elements to store in the set
467 /// @return optional<inline_set> If the number of unique elements in @c init is less than or equal to @c Capacity ,
468 /// then will return a populated optional equivalent to @c inline_set{init} . Otherwise returns a null optional.
472 optional<inline_set> res{in_place};
473 if (!res->insert_elements_if_they_fit(init.begin(), init.end())) {
474 res.reset();
475 }
476 return res;
477 }
478 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
479
480 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
481 /// @brief Attempt to construct a set from the specified list of values and a comparator.
482 ///
483 /// @param init The list of elements to store in the set
484 /// @param comp The comparator to use.
485 /// @return optional<inline_set> If the number of unique elements in @c init is less than or equal to @c Capacity ,
486 /// then will return a populated optional equivalent to @c inline_set{init,comp} . Otherwise returns a null optional.
487 ARENE_NODISCARD static auto try_construct(std::initializer_list<Value> init, Compare const& comp) noexcept(
490 optional<inline_set> res{in_place, comp};
491 if (!res->insert_elements_if_they_fit(init.begin(), init.end())) {
492 res.reset();
493 }
494 return res;
495 }
496 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
497
498 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
499 /// @brief Construct a set from the elements in the provided iterator range.
500 ///
501 /// @tparam Iterator The type of the iterators. Must satisfy
502 /// @c std::is_constructible<Value,std::iterator_traits<Iterator>::reference> .
503 /// @param first The iterator to the first element in the range
504 /// @param last The iterator to the one-past-the-end element in the range
505 /// @post @c size() will be equal to the number of unique elements in the range @c [first,last)
506 /// @post The elements in the set will be the unique elements in the range @c [first,last) , sorted via a
507 /// default-constructed instance of @c Compare .
508 /// @pre The number of unique elements in the range @c [first,last) is less than or equal to @c max_size() , else @c
509 /// ARENE_PRECONDITION violation.
510 template <
511 typename Iterator,
514 std::enable_if_t<std::is_constructible<Value, typename std::iterator_traits<Iterator>::reference>::value>> =
515 nullptr>
523 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
524
525 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
526 /// @brief Construct a set from the elements in the provided iterator range and comparator.
527 ///
528 /// @tparam Iterator The type of the iterators. Must satisfy
529 /// @c std::is_constructible<Value,std::iterator_traits<Iterator>::reference> .
530 /// @param first The iterator to the first element in the range
531 /// @param last The iterator to the one-past-the-end element in the range
532 /// @param comp The comparator to use .
533 /// @post @c size() will be equal to the number of unique elements in the range @c [first,last)
534 /// @post The elements in the set will be the unique elements in the range @c [first,last) , sorted via @c comp .
535 /// @pre The number of unique elements in the range @c [first,last) is less than or equal to @c max_size() , else @c
536 /// ARENE_PRECONDITION violation.
537 template <
538 typename Iterator,
542 nullptr>
543 inline_set(Iterator first, Iterator last, Compare const& comp) noexcept(
546 )
547 : inline_set(comp) {
548 insert(first, last);
549 }
550 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
551
552 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
553 /// @brief Attempt to construct a set from the specified sequence of values.
554 ///
555 /// @tparam Iterator The type of the iterators. Must satisfy
556 /// @c std::is_constructible<Value,std::iterator_traits<Iterator>::reference> .
557 /// @param first The iterator to the first element in the range
558 /// @param last The iterator to the one-past-the-end element in the range
559 /// @return optional<inline_set> If the number of unique elements in the range @c [first,last) is less than or equal
560 /// to @c Capacity , then will return a populated optional equivalent to @c inline_set{first,last} . Otherwise returns
561 /// a null optional.
562 template <
563 typename Iterator,
567 nullptr>
568 ARENE_NODISCARD static auto try_construct(Iterator first, Iterator last) noexcept(
571 optional<inline_set> res{in_place};
572 if (!res->insert_elements_if_they_fit(first, last)) {
573 res.reset();
574 }
575 return res;
576 }
577 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
578
579 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
580 /// @brief Attempt to construct a set from the specified sequence of values and a comparator.
581 ///
582 /// @tparam Iterator The type of the iterators. Must satisfy
583 /// @c std::is_constructible<Value,std::iterator_traits<Iterator>::reference> .
584 /// @param first The iterator to the first element in the range
585 /// @param last The iterator to the one-past-the-end element in the range
586 /// @param comp The comparator to use .
587 /// @return optional<inline_set> If the number of unique elements in the range @c [first,last) is less than or equal
588 /// to @c Capacity , then will return a populated optional equivalent to @c inline_set{first,last} . Otherwise returns
589 /// a null optional.
590 template <
591 typename Iterator,
594 std::enable_if_t<std::is_constructible<Value, typename std::iterator_traits<Iterator>::reference>::value>> =
595 nullptr>
596 ARENE_NODISCARD static auto try_construct(Iterator first, Iterator last, Compare const& comp) noexcept(
599 optional<inline_set> res{in_place, comp};
600 if (!res->insert_elements_if_they_fit(first, last)) {
601 res.reset();
602 }
603 return res;
604 }
605 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
606
607 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
608 /// @brief copy ctor.
609 // NOLINTBEGIN(google-explicit-constructor,hicpp-explicit-conversions) These are copy ctors.
610 inline_set(inline_set const&) = default;
611 // parasoft-end-suppress CERT_C-EXP37-a-3
612
613 /// @brief copy construct from a set with a smaller capacity
614 ///
615 /// Participates in overload resolution if @c Value and @c Compare satisfy @c is_copy_constructible
616 ///
617 /// @tparam OtherCapacity The capacity of the other set
618 /// @param other The set to copy from.
619 /// @post @c size()==other.size()
620 /// @post The elements in the set will be equivalent to the elements that were in @c other , produced as if via
621 /// copy-construction.
622 template <
623 std::size_t OtherCapacity,
625 std::enable_if_t<(OtherCapacity < Capacity)>,
629 : comparator_base(other.get_comparator_base(inline_set_detail::set_passkey{})),
630 operator_base() {
631 do_copy(other);
632 }
633
634 /// @brief copy construct from a set with a larger capacity
635 ///
636 /// Participates in overload resolution if @c Value and @c Compare satisfy @c is_copy_constructible
637 ///
638 /// @tparam OtherCapacity The capacity of the other set
639 /// @param other The set to copy from.
640 /// @post @c size()==other.size()
641 /// @post The elements in the set will be equivalent to the elements that were in @c other , produced as if via
642 /// copy-construction.
643 /// @pre @c other.size()<=maximum_size() else @c ARENE_PRECONDITION violation.
644 template <
645 std::size_t OtherCapacity,
647 std::enable_if_t<(OtherCapacity > Capacity)>,
651 : comparator_base(other.get_comparator_base(inline_set_detail::set_passkey{})),
652 operator_base() {
653 ARENE_PRECONDITION(other.size() <= max_size());
654 do_copy(other);
655 }
656 // NOLINTEND(google-explicit-constructor,hicpp-explicit-conversions)
657
658 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
659 /// @brief Attempts to construct a set via copy-construction from a set with the same or smaller capacity.
660 ///
661 /// @tparam OtherCapacity The capacity of the other set
662 /// @param other The set to copy from.
663 /// @return A populated optional equivalent to @c inline_set{other}
664 template <
665 std::size_t OtherCapacity,
667 std::enable_if_t<(OtherCapacity <= Capacity)>,
670 ) noexcept(noexcept(inline_set{other})) -> optional<inline_set> {
671 return optional<inline_set>{in_place, other};
672 }
673 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
674
675 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
676 /// @brief Attempts to construct a set from a set with a larger capacity.
677 ///
678 /// @tparam OtherCapacity The capacity of the other set
679 /// @param other The set to copy from.
680 /// @return optional<inline_set> If @c other.size()<=Capacity , then will return a populated optional equivalent to
681 /// @c inline_set{other} . Otherwise returns a null optional.
682 template <
683 std::size_t OtherCapacity,
685 std::enable_if_t<(OtherCapacity > Capacity)>,
688 ) noexcept(noexcept(inline_set{other})) -> optional<inline_set> {
689 if (other.size() <= Capacity) {
690 return optional<inline_set>{in_place, other};
691 }
692 return nullopt;
693 }
694 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
695
696 // parasoft-begin-suppress AUTOSAR-A15_5_1-b-2 "False positive: Conditionally noxecept"
697 // NOLINTBEGIN(google-explicit-constructor,hicpp-explicit-conversions) clang-tidy doesn't see these as move ctors.
698 /// @brief move ctor
699 ///
700 /// Participates in overload resolution if @c Value satisfies @c is_move_constructible
701 ///
702 /// @tparam OtherCapacity The maximum capacity of the other set to move from.
703 /// @param other The set to move from
704 /// @post @c size()==other.size()
705 /// @post The elements in the set will be equivalent to the elements that were in @c other , produced as if via
706 /// move-construction.
707 inline_set(move_construct_source&& other
709 : comparator_base(std::move(static_cast<comparator_base&>(other))),
710 operator_base(),
711 number_of_active_elements_(other.number_of_active_elements_),
712 values_(move_values(other, std::make_index_sequence<Capacity>())),
713 indices_(std::move(other.indices_)) {}
714 // parasoft-end-suppress AUTOSAR-A15_5_1-b-2
715
716 /// @brief move construct from a set with a larger capacity
717 ///
718 /// Participates in overload resolution if @c Value satisfies @c is_move_constructible
719 ///
720 /// @tparam OtherCapacity The maximum capacity of the other set to move from.
721 /// @param other The set to move from
722 /// @post @c size()==other.size()
723 /// @post The elements in the set will be equivalent to the elements that were in @c other , produced as if via
724 /// move-construction.
725 /// @pre @c other.size()<=maximum_size() else @c ARENE_PRECONDITION violation.
726 template <
727 std::size_t OtherCapacity,
729 std::enable_if_t<(OtherCapacity > Capacity)>,
732 : comparator_base(std::move(other.get_comparator_base(inline_set_detail::set_passkey{}))),
733 operator_base() {
734 ARENE_PRECONDITION(other.size() <= max_size());
735 do_move(std::move(other));
736 }
737 /// @brief move construct from a set with a smaller capacity
738 ///
739 /// Participates in overload resolution if @c Value satisfies @c is_move_constructible
740 ///
741 /// @tparam OtherCapacity The maximum capacity of the other set to move from.
742 /// @param other The set to move from
743 /// @post @c size()==other.size()
744 /// @post The elements in the set will be equivalent to the elements that were in @c other , produced as if via
745 /// move-construction.
746 template <
747 std::size_t OtherCapacity,
749 std::enable_if_t<(OtherCapacity < Capacity)>,
753 : comparator_base(std::move(other.get_comparator_base(inline_set_detail::set_passkey{}))),
754 operator_base() {
755 do_move(std::move(other));
756 }
757 // NOLINTEND(google-explicit-constructor,hicpp-explicit-conversions) clang-tidy doesn't see these as move ctors.
758
759 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
760 /// @brief Attempts to construct a set via move-construction from a set with a capacity that is less than or equal to
761 /// the target capacity.
762 ///
763 /// @tparam OtherCapacity The capacity of the other set
764 /// @param other The set to move from.
765 /// @return A populated optional equivalent to @c inline_set{other} .
766 template <
767 std::size_t OtherCapacity,
769 std::enable_if_t<(OtherCapacity <= Capacity)>,
772 ) noexcept(noexcept(inline_set{std::move(other)})) -> optional<inline_set> {
773 return optional<inline_set>{in_place, std::move(other)};
774 }
775 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
776
777 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
778 /// @brief Attempts to construct a set via move-construction from a set with a larger capacity.
779 ///
780 /// @tparam OtherCapacity The capacity of the other set
781 /// @param other The set to move from.
782 /// @return If @c other.size()<=Capacity , then will return a populated optional equivalent to @c inline_set{other} .
783 /// Otherwise returns a null optional.
784 template <
785 std::size_t OtherCapacity,
787 std::enable_if_t<(OtherCapacity > Capacity)>,
790 ) noexcept(noexcept(inline_set{other})) -> optional<inline_set> {
791 if (other.size() <= Capacity) {
792 return optional<inline_set>{in_place, std::move(other)};
793 }
794 return nullopt;
795 }
796 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
797
798 /// @brief Deleted copy-assignment operator where the set is not copy-assignable
799 auto operator=(deleted_copy_assign_source const& other) -> inline_set& = delete;
800 /// @brief copy-assignment operator.
801 ///
802 /// Participates in overload resolution if @c Value satisfies @c std::is_copy_constructible and @c Compare satisfies
803 /// @c is_copy_assignable
804 ///
805 /// @tparam OtherCapacity the capacity of the other set.
806 /// @param other The set to copy-assign from.
807 /// @return inline_set& The set post-assignment.
808 /// @post @c size()==other.size()
809 /// @post The elements in the set will be equivalent to the elements that were in @c other , produced as if via
810 /// copy-assignment/construction.
811 /// @pre @c other.size()<=maximum_size() else @c ARENE_PRECONDITION violation.
812 auto operator=(copy_assign_source const& other
814 -> inline_set& {
815 if (this != &other) {
816 static_cast<comparator_base&>(*this) = other;
817 do_copy(other);
818 }
819 return *this;
820 }
821 /// @brief Copy-assignment operator for copying from a set with a larger capacity
822 ///
823 /// Participates in overload resolution if @c Value satisfies @c std::is_copy_constructible and @c Compare satisfies
824 /// @c is_copy_assignable
825 ///
826 /// @tparam OtherCapacity the capacity of the other set.
827 /// @param other The set to copy-assign from.
828 /// @return inline_set& The set post-assignment.
829 /// @post @c size()==other.size()
830 /// @post The elements in the set will be equivalent to the elements that were in @c other , produced as if via
831 /// copy-assignment/construction.
832 /// @pre @c other.size()<=maximum_size() else @c ARENE_PRECONDITION violation.
833 template <
834 std::size_t OtherCapacity,
836 std::enable_if_t<(OtherCapacity > Capacity)>,
840 -> inline_set& {
841 ARENE_PRECONDITION(other.size() <= max_size());
842 static_cast<comparator_base&>(*this) = other.get_comparator_base(inline_set_detail::set_passkey{});
843 do_copy(other);
844 return *this;
845 }
846 /// @brief copy-assignment operator for copying from a set with a smaller capacity
847 ///
848 /// Participates in overload resolution if @c Value satisfies @c std::is_copy_constructible and @c Compare satisfies
849 /// @c is_copy_assignable
850 ///
851 /// @tparam OtherCapacity the capacity of the other set.
852 /// @param other The set to copy-assign from.
853 /// @return inline_set& The set post-assignment.
854 /// @post @c size()==other.size()
855 /// @post The elements in the set will be equivalent to the elements that were in @c other , produced as if via
856 /// copy-assignment/construction.
857 template <
858 std::size_t OtherCapacity,
860 std::enable_if_t<(OtherCapacity < Capacity)>,
864 static_cast<comparator_base&>(*this) = other.get_comparator_base(inline_set_detail::set_passkey{});
865 do_copy(other);
866 return *this;
867 }
868
869 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
870 /// @brief The move assignment operator is deleted if move assignment is not supported
871 auto operator=(deleted_move_assign_source&&) -> inline_set& = delete;
872 // parasoft-end-suppress CERT_C-EXP37-a-3
873
874 // parasoft-begin-suppress AUTOSAR-A15_5_1-b-2 "False positive: Conditionally noxecept"
875 /// @brief move-assignment operator
876 ///
877 /// Participates in overload resolution if @c Value satisfies @c is_move_constructible, and @c Compare satisfies @c
878 /// std::is_move_assignable
879 ///
880 /// @param other The set to move-assign from.
881 /// @return inline_set& The set post-assignment.
882 /// @post @c size()==other.size()
883 /// @post The elements in the set will be equivalent to the elements that were in @c other , produced as if via
884 /// move-assignment/construction.
885 /// @pre @c other.size()<=maximum_size() else @c ARENE_PRECONDITION violation.
886 auto operator=(move_assign_source&& other
888 -> inline_set& {
889 if (this != &other) {
890 static_cast<comparator_base&>(*this) = std::move(other);
891 do_move(std::move(other));
892 }
893 return *this;
894 }
895 // parasoft-end-suppress AUTOSAR-A15_5_1-b-2
896
897 /// @brief move-assignment operator from an @c inline_set with a larger capacity
898 ///
899 /// Participates in overload resolution if @c Value satisfies @c is_move_constructible, and @c Compare satisfies @c
900 /// std::is_move_assignable
901 ///
902 /// @tparam OtherCapacity The capacity of the source set
903 /// @param other The set to move-assign from.
904 /// @return inline_set& The set post-assignment.
905 /// @post @c size()==other.size()
906 /// @post The elements in the set will be equivalent to the elements that were in @c other , produced as if via
907 /// move-assignment/construction.
908 /// @pre @c other.size()<=maximum_size() else @c ARENE_PRECONDITION violation.
909 template <
910 std::size_t OtherCapacity,
912 std::enable_if_t<(OtherCapacity > Capacity)>,
915 ARENE_PRECONDITION(other.size() <= max_size());
916 static_cast<comparator_base&>(*this) = std::move(other.get_comparator_base(inline_set_detail::set_passkey{}));
917 do_move(std::move(other));
918 return *this;
919 }
920
921 /// @brief move-assignment operator from an @c inline_set with a smaller capacity
922 ///
923 /// Participates in overload resolution if @c Value satisfies @c is_move_constructible, and @c Compare satisfies @c
924 /// std::is_move_assignable
925 ///
926 /// @tparam OtherCapacity The capacity of the source set
927 /// @param other The set to move-assign from.
928 /// @return inline_set& The set post-assignment.
929 /// @post @c size()==other.size()
930 /// @post The elements in the set will be equivalent to the elements that were in @c other , produced as if via
931 /// move-assignment/construction.
932 template <
933 std::size_t OtherCapacity,
935 std::enable_if_t<(OtherCapacity < Capacity)>,
939 static_cast<comparator_base&>(*this) = std::move(other.get_comparator_base(inline_set_detail::set_passkey{}));
940 do_move(std::move(other));
941 return *this;
942 }
943
944 /// @brief Check if the set is empty
945 /// @return @c true if the set does not hold any elements, @c false otherwise
946 ARENE_NODISCARD auto empty() const noexcept -> bool { return number_of_active_elements_ == 0U; }
947
948 /// @brief Get the number of elements in the set
949 /// @return The number of elements in the set
950 auto size() const noexcept -> std::size_t { return number_of_active_elements_; }
951
952 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
953 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
954 /// @brief The maximum number of elements that can be held in the set.
955 ///
956 /// @return size_t Equivalent to @c Capacity .
958 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
959 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
960
961 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
962 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
963 /// @brief Get the maximum number of elements in the set
964 ///
965 /// @return size_t Equivalent to @c Capacity .
967 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
968 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
969
970 /// @brief Get the comparator
971 /// @return A copy of the comparator
972 auto key_comp() const noexcept(std::is_nothrow_copy_constructible<Compare>::value) -> key_compare {
973 return comparator_base::get_comparator();
974 }
975
976 /// @brief Get the comparator
977 /// @return A copy of the comparator
978 auto value_comp() const noexcept(std::is_nothrow_copy_constructible<Compare>::value) -> value_compare {
979 return comparator_base::get_comparator();
980 }
981
982 /// @brief Obtain an iterator referring to the element equivalent to the supplied value, if there is one.
983 ///
984 /// @param value_to_find The value to find
985 /// @return iterator to the equivalent element, or @c end() if the element is not found
986 auto find(Value const& value_to_find) noexcept(comparison_is_noexcept<>) -> iterator {
987 return do_find(value_to_find);
988 }
989 /// @brief Obtain an iterator referring to the element equivalent to the supplied value, if there is one.
990 ///
991 /// @param value_to_find The value to find
992 /// @return const_iterator to the equivalent element, or @c end() if the element is not found
993 auto find(Value const& value_to_find) const noexcept(comparison_is_noexcept<>) -> const_iterator {
994 return do_find(value_to_find);
995 }
996 /// @brief Obtain an iterator referring to the element equivalent to the supplied value, if there is one.
997 ///
998 /// @tparam OtherKey the type of the value to find. Must satisfy @c is_transparent_comparator_for<Compare,Value,K> or
999 /// @c is_transparent_three_way_comparator_for<Compare,Value,K> .
1000 /// @param value The value to find
1001 /// @return iterator to the equivalent element, or @c end() if the element is not found
1002 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported_for<OtherKey>>> = nullptr>
1003 auto find(OtherKey const& value) noexcept(comparison_is_noexcept<OtherKey>) -> iterator {
1004 return do_find(value);
1005 }
1006 /// @brief Obtain an iterator referring to the element equivalent to the supplied value, if there is one.
1007 ///
1008 /// @tparam OtherKey the type of the value to find. Must satisfy @c is_transparent_comparator_for<Compare,Value,K> or
1009 /// @c is_transparent_three_way_comparator_for<Compare,Value,K> .
1010 /// @param value The value to find
1011 /// @return const_iterator to the equivalent element, or @c end() if the element is not found
1012 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported_for<OtherKey>>> = nullptr>
1013 auto find(OtherKey const& value) const noexcept(comparison_is_noexcept<OtherKey>) -> const_iterator {
1014 return do_find(value);
1015 }
1016
1017 /// @brief Check if the set contains a specific value
1018 ///
1019 /// @param value_to_check The value to search for
1020 /// @return true if @c find(value_to_check)!=end() .
1021 /// @return false if @c find(value_to_check)==end() .
1022 auto contains(Value const& value_to_check) const noexcept(comparison_is_noexcept<>) -> bool {
1023 return do_contains(value_to_check);
1024 }
1025 /// @brief Check if the set contains a value equivalent to a specific value.
1026 ///
1027 /// @tparam OtherKey the type of the value to find. Must satisfy @c is_transparent_comparator_for<Compare,Value,K> or
1028 /// @c is_transparent_three_way_comparator_for<Compare,Value,K> .
1029 /// @param value The value to search for
1030 /// @return true if @c find(value)!=end() .
1031 /// @return false if @c find(value)==end() .
1032 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported_for<OtherKey>>> = nullptr>
1033 auto contains(OtherKey const& value) const noexcept(comparison_is_noexcept<OtherKey>) -> bool {
1034 return do_contains(value);
1035 }
1036
1037 /// @brief Return the number of elements in the set equivalent to a specific value.
1038 ///
1039 /// @param value_to_count The value to search for.
1040 /// @return std::size_t @c 0 if the element was not in the set, else @c 1 .
1041 auto count(Value const& value_to_count) const noexcept(comparison_is_noexcept<>) -> std::size_t {
1042 return do_count(value_to_count);
1043 }
1044 /// @brief Return the number of elements in the set equivalent to a specific value.
1045 ///
1046 /// @tparam OtherKey the type of the value to find. Must satisfy @c is_transparent_comparator_for<Compare,Value,K> or
1047 /// @c is_transparent_three_way_comparator_for<Compare,Value,K> .
1048 /// @param value The value to search for.
1049 /// @return std::size_t @c 0 if the element was not in the set, else @c 1 .
1050 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported_for<OtherKey>>> = nullptr>
1051 auto count(OtherKey const& value) const noexcept(comparison_is_noexcept<OtherKey>) -> std::size_t {
1052 return do_count(value);
1053 }
1054
1055 /// @brief Find the first element which is _not less than_ a given value.
1056 ///
1057 /// @param value_to_find The value to find the lower bound for.
1058 /// @return iterator to the first element which is _not less than_ @c value_to_find, or @c end() if there is no
1059 /// such element.
1060 auto lower_bound(Value const& value_to_find) noexcept(comparison_is_noexcept<>) -> iterator {
1061 return do_lower_bound(value_to_find);
1062 }
1063 /// @brief Find the first element which is _not less than_ a given value.
1064 ///
1065 /// @param value_to_find The value to find the lower bound for.
1066 /// @return const_iterator to the first element which is _not less than_ @c value_to_find, or @c end() if there is no
1067 /// such element.
1068 auto lower_bound(Value const& value_to_find) const noexcept(comparison_is_noexcept<>) -> const_iterator {
1069 return do_lower_bound(value_to_find);
1070 }
1071 /// @brief Find the first element which is _not less than_ a given value.
1072 ///
1073 /// @tparam OtherKey the type of the value to find. Must satisfy @c is_transparent_comparator_for<Compare,Value,K> or
1074 /// @c is_transparent_three_way_comparator_for<Compare,Value,K> .
1075 /// @param value The value to find the lower bound for.
1076 /// @return iterator to the first element which is _not less than_ @c value , or @c end() if there is no
1077 /// such element.
1078 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported_for<OtherKey>>> = nullptr>
1079 auto lower_bound(OtherKey const& value) noexcept(comparison_is_noexcept<OtherKey>) -> iterator {
1080 return do_lower_bound(value);
1081 }
1082 /// @brief Find the first element which is _not less than_ a given value.
1083 ///
1084 /// @tparam OtherKey the type of the value to find. Must satisfy @c is_transparent_comparator_for<Compare,Value,K> or
1085 /// @c is_transparent_three_way_comparator_for<Compare,Value,K> .
1086 /// @param value The value to find the lower bound for.
1087 /// @return const_iterator to the first element which is _not less than_ @c value , or @c end() if there is no
1088 /// such element.
1089 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported_for<OtherKey>>> = nullptr>
1090 auto lower_bound(OtherKey const& value) const noexcept(comparison_is_noexcept<OtherKey>) -> const_iterator {
1091 return do_lower_bound(value);
1092 }
1093
1094 /// @brief Find the first element which is _greater than_ a given value.
1095 ///
1096 /// @param value_to_find The value to search for.
1097 /// @return iterator to the first element which is _greater than_ @c value_to_find , or @c end() if there is no such
1098 /// element.
1099 auto upper_bound(Value const& value_to_find) noexcept(comparison_is_noexcept<>) -> iterator {
1100 return do_upper_bound(value_to_find);
1101 }
1102 /// @brief Find the first element which is _greater than_ a given value.
1103 ///
1104 /// @param value_to_find The value to search for.
1105 /// @return const_iterator to the first element which is _greater than_ @c value_to_find , or @c end() if there is no
1106 /// such
1107 /// element.
1108 auto upper_bound(Value const& value_to_find) const noexcept(comparison_is_noexcept<>) -> const_iterator {
1109 return do_upper_bound(value_to_find);
1110 }
1111 /// @brief Find the first element which is _greater than_ a given value.
1112 ///
1113 /// @tparam OtherKey the type of the value to find. Must satisfy @c is_transparent_comparator_for<Compare,Value,K> or
1114 /// @c is_transparent_three_way_comparator_for<Compare,Value,K> .
1115 /// @param value The value to search for.
1116 /// @return iterator to the first element which is _greater than_ @c value , or @c end() if there is no such
1117 /// element.
1118 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported_for<OtherKey>>> = nullptr>
1119 auto upper_bound(OtherKey const& value) noexcept(comparison_is_noexcept<OtherKey>) -> iterator {
1120 return do_upper_bound(value);
1121 }
1122 /// @brief Find the first element which is _greater than_ a given value.
1123 ///
1124 /// @tparam OtherKey the type of the value to find. Must satisfy @c is_transparent_comparator_for<Compare,Value,K> or
1125 /// @c is_transparent_three_way_comparator_for<Compare,Value,K> .
1126 /// @param value The value to search for.
1127 /// @return const_iterator to the first element which is _greater than_ @c value , or @c end() if there is no such
1128 /// element.
1129 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported_for<OtherKey>>> = nullptr>
1130 auto upper_bound(OtherKey const& value) const noexcept(comparison_is_noexcept<OtherKey>) -> const_iterator {
1131 return do_upper_bound(value);
1132 }
1133
1134 /// @brief Finds the sequence of values which compare equivalent to a given value.
1135 ///
1136 /// @param value_to_find The value to search for
1137 /// @return std::pair<iterator, iterator> A pair of iterators such that all values in the range @c [first,second)
1138 /// compare equal to @c value_to_find if there was an element equivalent to @c value_to_find in the set.
1139 /// Otherwise both iterators will be @c end() .
1140 auto equal_range(Value const& value_to_find) noexcept(comparison_is_noexcept<>) -> std::pair<iterator, iterator> {
1141 return do_equal_range(value_to_find);
1142 }
1143 /// @brief Finds the sequence of values which compare equivalent to a given value.
1144 ///
1145 /// @param value_to_find The value to search for
1146 /// @return std::pair<const_iterator, const_iterator> A pair of iterators such that all values in the range
1147 /// @c [first,second) compare equal to @c value_to_find if there was an element equivalent to @c value_to_find
1148 /// in the set. Otherwise both iterators will be @c end() .
1149 auto equal_range(Value const& value_to_find) const noexcept(comparison_is_noexcept<>)
1150 -> std::pair<const_iterator, const_iterator> {
1151 return do_equal_range(value_to_find);
1152 }
1153 /// @brief Finds the sequence of values which compare equivalent to a given value.
1154 ///
1155 /// @tparam OtherKey the type of the value to find. Must satisfy @c is_transparent_comparator_for<Compare,Value,K> or
1156 /// @c is_transparent_three_way_comparator_for<Compare,Value,K> .
1157 /// @param value The value to search for
1158 /// @return std::pair<iterator, iterator> A pair of iterators such that all values in the range @c [first,second)
1159 /// compare equal to @c value if there was an element equivalent to @c value in the set. Otherwise both
1160 /// iterators will be @c end() .
1161 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported_for<OtherKey>>> = nullptr>
1162 auto equal_range(OtherKey const& value) noexcept(comparison_is_noexcept<OtherKey>) -> std::pair<iterator, iterator> {
1163 return do_equal_range(value);
1164 }
1165 /// @brief Finds the sequence of values which compare equivalent to a given value.
1166 ///
1167 /// @tparam OtherKey the type of the value to find. Must satisfy @c is_transparent_comparator_for<Compare,Value,K> or
1168 /// @c is_transparent_three_way_comparator_for<Compare,Value,K> .
1169 /// @param value The value to search for
1170 /// @return std::pair<const_iterator, const_iterator> A pair of iterators such that all values in the range
1171 /// @c [first,second) compare equal to @c value if there was an element equivalent to @c value in the set.
1172 /// Otherwise both iterators will be @c end() .
1173 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported_for<OtherKey>>> = nullptr>
1174 auto equal_range(OtherKey const& value) const noexcept(comparison_is_noexcept<OtherKey>)
1175 -> std::pair<const_iterator, const_iterator> {
1176 return do_equal_range(value);
1177 }
1178
1179 // parasoft-begin-suppress AUTOSAR-A13_3_1-a-2 "Constrained via SFINAE, permitted by A13-3-1 Permit #1"
1180 /// @brief Attempt to insert an element into the set.
1181 ///
1182 /// @param value_to_insert The element to insert via copy-construction
1183 /// @return std::pair<iterator,bool> A pair where the first element is an iterator pointing to either the newly
1184 /// inserted element at its sort-order position in the set, or the existing element in the set if the set
1185 /// already contained @c value_to_insert , and the second element is a boolean which is @c true if the
1186 /// insertion happened, or @c false otherwise.
1187 /// @post If the insertion happened, @c size() increases by 1.
1188 /// @post If the insertion happened, there is an element equivalent to @c value_to_insert in the set at the position
1189 /// referenced
1190 /// by the returned iterator.
1191 /// @pre @c size()+1<=max_size() , else @c ARENE_PRECONDITION violation .
1192 auto insert(Value const& value_to_insert
1193 ) noexcept(comparison_is_noexcept<> && std::is_nothrow_copy_constructible<Value>::value)
1194 -> std::pair<iterator, bool> {
1195 return internal_insert(value_to_insert);
1196 }
1197 // parasoft-end-suppress AUTOSAR-A13_3_1-a-2
1198
1199 /// @brief Attempt to insert an element into the set.
1200 ///
1201 /// @param value_to_insert The element to insert via move-construction
1202 /// @return std::pair<iterator,bool> A pair where the first element is an iterator pointing to either the newly
1203 /// inserted element at its sort-order position in the set, or the existing element in the set if the set
1204 /// already contained @c value_to_insert , and the second element is a boolean which is @c true if the
1205 /// insertion happened, or @c false otherwise.
1206 /// @post If the insertion happened, @c size() increases by 1.
1207 /// @post If the insertion happened, there is an element equivalent to @c value_to_insert in the set at the position
1208 /// referenced
1209 /// by the returned iterator.
1210 /// @pre @c size()+1<=max_size() , else @c ARENE_PRECONDITION violation .
1211 auto insert(Value&& value_to_insert
1212 ) noexcept(comparison_is_noexcept<> && std::is_nothrow_move_constructible<Value>::value)
1213 -> std::pair<iterator, bool> {
1214 return internal_insert(std::move(value_to_insert));
1215 }
1216
1217 /// @brief Attempt to insert an element into the set.
1218 ///
1219 /// @tparam OtherKey The type of the element to attempt to insert. Must satisfy
1220 /// @c std::is_constructible<Value,OtherKey&&>
1221 /// @param value The element to insert via perfect forwarding.
1222 /// @return std::pair<iterator,bool> A pair where the first element is an iterator pointing to either the newly
1223 /// inserted element at its sort-order position in the set, or the existing element in the set if the set
1224 /// already contained @c value , and the second element is a boolean which is @c true if the insertion
1225 /// happened, or @c false otherwise.
1226 /// @post If the insertion happened, @c size() increases by 1.
1227 /// @post If the insertion happened, there is an element equivalent to @c value in the set at the position referenced
1228 /// by the returned iterator.
1229 /// @pre @c size()+1<=max_size() , else @c ARENE_PRECONDITION violation .
1230 template <
1231 typename OtherKey,
1232 typename SfinaeKey = Value,
1237 auto insert(OtherKey&& value
1238 ) noexcept(comparison_is_noexcept<OtherKey> && std::is_nothrow_constructible<Value, OtherKey&&>::value)
1239 -> std::pair<iterator, bool> {
1240 return internal_insert(std::forward<OtherKey>(value));
1241 }
1242
1243 /// @brief Insert all the elements in the provided iterator range into the set, if there are not already equivalent
1244 /// elements.
1245 /// @tparam Iterator The type of the iterators
1246 /// @param first The iterator to the first element in the range
1247 /// @param last The iterator to the one-past-the-end element in the range
1248 /// @post @c size() increases by the number of elements in @c [first,last) which did not already exist in the set.
1249 /// @post @c find(*itr) will return an iterator other than @c end() for all elements in the range @c [first,last)
1250 /// @pre Let @c unique_elements equal the number of elements in the range @c [first,last) for which @c contains(*itr)
1251 /// would return @c false ; @c size()+unique_elements<=max_size() , else @c ARENE_PRECONDITION violation .
1252 template <
1253 typename Iterator,
1257 nullptr>
1258 void insert(Iterator first, Iterator last) noexcept(std::is_nothrow_constructible<Value, decltype(*first)>::value) {
1259 for (decltype(auto) element : arene::base::make_subrange(first, last)) {
1260 std::ignore = insert(std::forward<decltype(element)>(element));
1261 }
1262 }
1263
1264 // parasoft-begin-suppress AUTOSAR-A13_3_1-a-2 "Constrained via SFINAE, permitted by A13-3-1 Permit #1"
1265 /// @brief Attempt to insert the elements in the provided initializer list into the set.
1266 ///
1267 /// @param init The list of elements to insert
1268 /// @post @c size() increases by the number of elements in @c init which did not already exist in the set.
1269 /// @post @c find(*itr) wil return an iterator other than @c end() for all elements in @c init
1270 /// @pre Let @c unique_elements equal the number of elements in @c init for which @c contains()
1271 /// would return @c false ; @c size()+unique_elements<=max_size() , else @c ARENE_PRECONDITION violation .
1272 void insert(std::initializer_list<Value> init) { insert(init.begin(), init.end()); }
1273 // parasoft-end-suppress AUTOSAR-A13_3_1-a-2
1274
1275 /// @brief Obtain an iterator referring to the beginning of the sorted range of elements.
1276 /// @return const_iterator Points to the first element in the sequence, or @c end() if @c empty() .
1277 auto begin() const noexcept -> const_iterator { return make_iterator(*this, 0U); }
1278 /// @brief Obtain an iterator referring to the beginning of the sorted range of elements.
1279 /// @return const_iterator Points to the first element in the sequence, or @c end() if @c empty() .
1280 auto cbegin() const noexcept -> const_iterator { return make_iterator(*this, 0U); }
1281
1282 /// @brief Obtain an iterator referring to one past the last element in the sorted range of elements.
1283 /// @return const_iterator Points to one past the last element in the sequence.
1284 auto end() const noexcept -> const_iterator { return make_iterator(*this, number_of_active_elements_); }
1285 /// @brief Obtain an iterator referring to one past the last element in the sorted range of elements.
1286 /// @return const_iterator Points to one past the last element in the sequence.
1287 auto cend() const noexcept -> const_iterator { return make_iterator(*this, number_of_active_elements_); }
1288
1289 /// @brief Obtain an iterator referring to the beginning of a reversed traversal of the sorted range of elements.
1290 /// @return const_reverse_iterator Points to the last element in the sequence, or @c rend() if @c empty() .
1291 auto rbegin() const noexcept -> const_reverse_iterator { return const_reverse_iterator(end()); }
1292 /// @brief Obtain an iterator referring to the beginning of a reversed traversal of the sorted range of elements.
1293 /// @return const_reverse_iterator Points to the last element in the sequence, or @c rend() if @c empty() .
1294 auto crbegin() const noexcept -> const_reverse_iterator { return const_reverse_iterator(end()); }
1295
1296 /// @brief Obtain an iterator referring to one past the last element in a reversed traversal of the sorted range of
1297 /// elements.
1298 /// @return const_reverse_iterator An iterator pointing to one before the first element in the sequence.
1299 auto rend() const noexcept -> const_reverse_iterator { return const_reverse_iterator(begin()); }
1300 /// @brief Obtain an iterator referring to one past the last element in a reversed traversal of the sorted range of
1301 /// elements.
1302 /// @return const_reverse_iterator An iterator pointing to one before the first element in the sequence.
1303 auto crend() const noexcept -> const_reverse_iterator { return const_reverse_iterator(begin()); }
1304
1305 // parasoft-begin-suppress AUTOSAR-A8_4_2-a "False positive: function does have a return"
1306 // parasoft-begin-suppress CERT_C-MSC37-a "False positive: function does have a return"
1307 // parasoft-begin-suppress CERT_C-EXP37-a "False positive: function does have a return"
1308 // parasoft-begin-suppress CERT_CPP-MSC52-a "False positive: function does have a return"
1309 // parasoft-begin-suppress AUTOSAR-A0_1_4-a "False positive: Parameter is used"
1310 /// @brief Construct a new element from the specified initialization arguments, and then attempt to insert it.
1311 ///
1312 /// @tparam ArgTypes The types of the initialization arguments
1313 /// @param args The initialization arguments of the new element
1314 /// @return std::pair<iterator, bool> Equivalent to calling @c insert(Value{ArgTypes...}) .
1315 template <
1316 typename... ArgTypes,
1317 constraints<std::enable_if_t<std::is_constructible<Value, ArgTypes&&...>::value>> = nullptr>
1318 auto emplace(ArgTypes&&... args) -> std::pair<iterator, bool> {
1319 if (number_of_active_elements_ == Capacity) {
1320 Value const value{std::forward<ArgTypes>(args)...};
1321 auto const pos_info = lower_bound_index(value);
1322 ARENE_PRECONDITION(pos_info.order == strong_ordering::equal);
1323 return {make_iterator(*this, pos_info.index), false};
1324 }
1325 auto const new_index = indices_[number_of_active_elements_];
1326 auto& potentially_inserted_element = values_[new_index];
1327 potentially_inserted_element.emplace(std::forward<ArgTypes>(args)...);
1328 optional_resetter<Value> destroy_if_not_inserted{potentially_inserted_element};
1329 auto const pos_info = lower_bound_index(*potentially_inserted_element);
1330 bool const do_insert{pos_info.order != strong_ordering::equal};
1331 if (do_insert) {
1332 insert_index_at(pos_info.index, new_index);
1333 destroy_if_not_inserted.dismiss();
1334 }
1335 return {make_iterator(*this, pos_info.index), do_insert};
1336 }
1337 // parasoft-end-suppress AUTOSAR-A0_1_4-a
1338 // parasoft-end-suppress CERT_CPP-MSC52-a
1339 // parasoft-end-suppress AUTOSAR-A8_4_2-a
1340 // parasoft-end-suppress CERT_C-MSC37-a
1341 // parasoft-end-suppress CERT_C-EXP37-a
1342
1343 /// @brief Erase any elements with a value equivalent to the supplied element.
1344 ///
1345 /// @param value_to_erase The value of elements to erase
1346 /// @return The number of elements erased, which will be @c 1 if the element was in the set, else @c 0 .
1347 auto erase(Value const& value_to_erase) noexcept(comparison_is_noexcept<>) -> size_type {
1348 return do_erase(value_to_erase);
1349 }
1350 /// @brief Erase any elements with a value equivalent to the supplied element.
1351 ///
1352 /// @tparam OtherKey The type of the element to erase.
1353 /// @param value The value of elements to erase
1354 /// @return The number of elements erased, which will be @c 1 if the element was in the set, else @c 0 .
1355 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported_for<OtherKey>>> = nullptr>
1356 auto erase(OtherKey const& value) noexcept(comparison_is_noexcept<OtherKey>) -> size_type {
1357 return do_erase(value);
1358 }
1359
1360 /// @brief Erase the element referred to be the specified iterator.
1361 /// @param pos The iterator referring to the element to erase
1362 /// @return An iterator referring to the element after the erased element if there is one, or @c end() otherwise.
1363 /// @pre @c pos Must be a deferencable iterator into @c *this
1364 auto erase(iterator pos) noexcept -> iterator {
1365 ARENE_PRECONDITION(pos.is_for(this));
1366 auto const index = pos.index(inline_set_detail::set_passkey{});
1367 ARENE_PRECONDITION(index <= number_of_active_elements_);
1368 std::ignore = erase_at_index(index);
1369 return pos;
1370 }
1371
1372 /// @brief Erase all the elements referred to be the specified iterator range.
1373 /// @param first The iterator for the start of the range
1374 /// @param last The iterator for one-past-the-end of the range
1375 /// @return An iterator referring to the element after the erased elements if there is one, or @c end() otherwise.
1376 /// @pre @c (first,last] Must be a valid iterator range into @c *this
1377 auto erase(iterator first, iterator last) noexcept -> iterator {
1378 ARENE_PRECONDITION(first.is_for(this) && last.is_for(this));
1379 index_type const first_index{first.index(inline_set_detail::set_passkey{})};
1380 index_type const last_index{last.index(inline_set_detail::set_passkey{})};
1381 ARENE_PRECONDITION((first_index <= last_index) && (last_index <= size()));
1382 erase_index_range(first_index, static_cast<index_type>(last_index - first_index));
1383 return first;
1384 }
1385
1386 /// @brief Erase all the elements in @c *this
1387 /// @post @c size()==0 .
1388 /// @post The destructors of all elements in the range @c [begin(),end()) will have been called once.
1389 void clear() noexcept { erase_index_range(0U, number_of_active_elements_); }
1390
1391 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
1392 /// @brief Fast inequality heuristic to shortcut on different sized containers.
1393 ///
1394 /// @tparam OtherCapacity the capacity of @c rhs
1395 /// @param lhs The left-hand operand to the check
1396 /// @param rhs The right-hand operand to the check
1397 /// @return inequality_heuristic::may_be_equal_or_not_equal if @c lhs.size()==rhs.size()
1398 /// @return inequality_heuristic::definitely_not_equal if @c lhs.size()!=rhs.size()
1399 template <size_type OtherCapacity>
1400 ARENE_NODISCARD static auto
1406 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
1407
1408 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
1409 /// @brief Compares two sets lexicographically .
1410 ///
1411 /// @note Lexicographic comparison between sets ignores the order of keys as defined by @c Compare . That is, it is
1412 /// a lexicographic comparison between the @c value_type elements of each container, in iteration order, using the
1413 /// standard @c compare_three_way facility. This means that for all possible sets which result in element sequences
1414 /// <c>{1, 2, 3}</c> and <c>{1, 2, 5}</c>, when compared against each other
1415 /// the result of the comparison will always be the same, @c strong_ordering::less.
1416 ///
1417 /// @tparam OtherCapacity the capacity of @c rhs
1418 /// @tparam SfinaeKey dummy template parameter to disable the operator if @c key_Type is not three way comparable.
1419 /// @param lhs The left hand operand to the comparison.
1420 /// @param rhs The right hand operand to the comparison.
1421 /// @return strong_ordering Equivalent to
1422 /// @c arene::base::lexicographical_compare_three_way(lhs.begin(),lhs.end(),rhs.begin(),rhs.end())
1423 template <
1424 size_type OtherCapacity,
1425 typename SfinaeKey = key_type,
1427 ARENE_NODISCARD static auto
1429 -> strong_ordering {
1430 return ::arene::base::lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1431 }
1432 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
1433
1434 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
1435 /// @brief Get the comparator base.
1436 /// @note This can only be called from @c inline_set internals due to the passkey
1437 /// @return A reference to the base
1438 auto get_comparator_base(inline_set_detail::set_passkey) noexcept -> comparator_base& { return *this; }
1439 // parasoft-end-suppress CERT_C-EXP37-a-3
1440
1441 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
1442 /// @brief Get the comparator base.
1443 /// @note This can only be called from @c inline_set internals due to the passkey
1444 /// @return A reference to the base
1445 auto get_comparator_base(inline_set_detail::set_passkey) const noexcept -> comparator_base const& { return *this; }
1446 // parasoft-end-suppress CERT_C-EXP37-a-3
1447
1448 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
1449 /// @brief Gets a reference to the element corrsponding to a given index.
1450 /// @param index Index of the element in iteration order.
1451 /// @return A reference to the element for the given index.
1452 /// @note This can only be called from @c inline_set internals due to the passkey
1453 /// @pre @c index<indicies.size()
1454 auto entry_at_index(inline_set_detail::set_passkey, index_type index) noexcept -> entry_type& {
1455 return values_[indices_[index]];
1456 }
1457 // parasoft-end-suppress CERT_C-EXP37-a-3
1458
1459 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
1460 /// @brief Gets a reference to the element corrsponding to a given index.
1461 /// @param index Index of the element in iteration order.
1462 /// @return A reference to the element for the given index.
1463 /// @note This can only be called from @c inline_set internals due to the passkey
1464 /// @pre @c index<indicies.size()
1465 auto entry_at_index(inline_set_detail::set_passkey, index_type index) const noexcept -> entry_type const& {
1466 return values_[indices_[index]];
1467 }
1468 // parasoft-end-suppress CERT_C-EXP37-a-3
1469
1470 private:
1471 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
1472 /// @brief The type of the storage for the whole set of elements
1473 using storage_type = array<entry_type, Capacity>;
1474 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
1475 /// @brief The current size of set
1476 index_type number_of_active_elements_{0};
1477 // parasoft-begin-suppress AUTOSAR-M8_5_2-b-2 "False Positive: all elements default-initialized"
1478 /// @brief The storage of the elements
1479 storage_type values_{};
1480 // parasoft-end-suppress AUTOSAR-M8_5_2-b-2
1481
1482 /// @brief The indices for the elements. Initially @c indices_[i] is @c i, so each element sets to the corresponding
1483 /// element in @c values_.
1484 array<index_type, Capacity> indices_{inline_container_detail::make_index_array<index_type, Capacity>()};
1485
1486 /// @brief Implementation helper for @c try_construct
1487 ///
1488 /// @param first The first iterator in the sequence of elements to attempt to insert.
1489 /// @param last The last iterator in the sequence of elements to attempt to insert.
1490 /// @return true If all elements were successfully inserted without exceeding capacity.
1491 /// @return false If an element needed to be inserted, but there was not enough room.
1492 /// @post Equivalent to having called @c insert on each element in the range @c [first,last) until either all elements
1493 /// were successfully inserted or @c Capacity was reached an an element needed to be inserted still.
1494 template <
1495 typename Iterator,
1498 std::enable_if_t<std::is_constructible<Value, typename std::iterator_traits<Iterator>::reference>::value>> =
1499 nullptr>
1500 auto insert_elements_if_they_fit(Iterator first, Iterator last) noexcept(
1501 comparison_is_noexcept<> && std::is_nothrow_copy_constructible<Value>::value
1502 ) -> bool {
1503 while (first != last) {
1504 if (size() < Capacity) {
1505 std::ignore = insert(*first);
1506 } else if (!contains(*first)) {
1507 return false;
1508 } else {
1509 // do nothing, element already present
1510 }
1511 arene::base::advance(first, 1);
1512 }
1513 return true;
1514 }
1515
1516 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: this is not a move constructor"
1517 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "The universal reference is used to detect the value category"
1518 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: Self is a template parameter"
1519 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
1520 /// @brief Deduced-this helper for universally constructing iterators.
1521 ///
1522 /// @tparam SelfType Deduced-this type of the set.
1523 /// @param self The instance of the set to operate on.
1524 /// @param index The index to create the iterator from
1525 /// @return auto An iterator constructed as if via @c self and @c index .
1526 template <typename SelfType, constraints<std::enable_if_t<decays_to_v<SelfType, inline_set>>> = nullptr>
1527 static auto make_iterator(SelfType&& self, index_type index) noexcept -> iterator {
1528 return iterator_impl{inline_set_detail::set_passkey{}, &self, index};
1529 }
1530 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
1531 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
1532 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
1533 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
1534
1535 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
1536 /// @brief Deduced-this helper that detemplitizes find iterator generation from key type.
1537 ///
1538 /// @tparam SelfType Deduced-this type of the set.
1539 /// @param self The instance of the set to operate on.
1540 /// @param lb_info An instance of the return from @c lower_bound_index()
1541 /// @return auto If @c lb_info.order==strong_ordering::equal , then an iterator constructed as if via @c
1542 /// make_iterator(self,lb_info.index) , otherwise @c self.end() .
1543 template <typename SelfType, constraints<std::enable_if_t<decays_to_v<SelfType, inline_set>>> = nullptr>
1544 static auto
1545 make_find_iterator(SelfType&& self, inline_container::detail::lower_bound_index_info<index_type> lb_info) noexcept
1546 -> iterator {
1547 if (lb_info.order == strong_ordering::equal) {
1548 return make_iterator(std::forward<SelfType>(self), lb_info.index);
1549 }
1550 return self.end();
1551 }
1552 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
1553
1554 /// @brief Helper implementation for @c find() which works for all comparators and iterator types.
1555 ///
1556 /// @tparam OtherKey the type of the key to search for.
1557 /// @param value The key to search for.
1558 /// @return iterator The iterator at the position of @c value if it is found, else @c end() .
1559 template <typename OtherKey>
1560 auto do_find(OtherKey const& value) const -> iterator {
1561 return make_find_iterator(*this, lower_bound_index(value));
1562 }
1563
1564 /// @brief Helper implementation for @c contains which works for all comparators.
1565 ///
1566 /// @tparam OtherKey the type of the value to find
1567 /// @param value The value to search for
1568 /// @return true if @c find(value)!=end() .
1569 /// @return false if @c find(value)==end() .
1570 template <typename OtherKey>
1571 auto do_contains(OtherKey const& value) const noexcept(comparison_is_noexcept<OtherKey>) -> bool {
1572 return do_find(value) != end();
1573 }
1574
1575 /// @brief Helper implementation for @c count which works for all comparators.
1576 ///
1577 /// @tparam OtherKey the type of the value to find.
1578 /// @param value The value to search for.
1579 /// @return std::size_t @c 0 if the element was not in the set, else @c 1 .
1580 template <typename OtherKey>
1581 auto do_count(OtherKey const& value) const noexcept(comparison_is_noexcept<OtherKey>) -> std::size_t {
1582 return static_cast<std::size_t>(do_contains(value));
1583 }
1584
1585 /// @brief Helper implementation for @c lower_bound which works for all comparators and iterator types.
1586 ///
1587 /// @tparam OtherKey the type of the value to find.
1588 /// @param value The value to find the lower bound for.
1589 /// @return iterator An iterator to the first element which is _not less than_ @c value.
1590 template <typename OtherKey>
1591 auto do_lower_bound(OtherKey const& value) const noexcept(comparison_is_noexcept<OtherKey>) -> iterator {
1592 return make_iterator(*this, lower_bound_index(value).index);
1593 }
1594
1595 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
1596 /// @brief Deduced-this helper that detemplitizes upper_bound iterator generation from key type.
1597 ///
1598 /// @tparam SelfType Deduced-this type of the set.
1599 /// @param self The instance of the set to operate on.
1600 /// @param lb_info An instance of the return from @c lower_bound_index()
1601 /// @return auto If @c lb_info.order==strong_ordering::equal , then an iterator constructed as if via @c
1602 /// make_iterator(self,lb_info.index + 1) , otherwise @c make_iterator(self,lb_info.index) .
1603 template <typename SelfType, constraints<std::enable_if_t<decays_to_v<SelfType, inline_set>>> = nullptr>
1604 static auto make_upper_bound_iterator(
1605 SelfType&& self,
1606 inline_container::detail::lower_bound_index_info<index_type> lb_info
1607 ) noexcept -> iterator {
1608 if (lb_info.order == strong_ordering::equal) {
1609 ++lb_info.index;
1610 }
1611 return make_iterator(std::forward<SelfType>(self), lb_info.index);
1612 }
1613 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
1614
1615 /// @brief Helper implementation for @c upper_bound which works for all comparators and iterator types.
1616 ///
1617 /// @tparam OtherKey the type of the value to find
1618 /// @param value The value to search for.
1619 /// @return An iterator to the first element which is _greater than_ @c value , or @c end() if there is no such
1620 /// element.
1621 template <typename OtherKey>
1622 auto do_upper_bound(OtherKey const& value) const noexcept(comparison_is_noexcept<OtherKey>) -> iterator {
1623 return make_upper_bound_iterator(*this, lower_bound_index(value));
1624 }
1625
1626 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
1627 // parasoft-begin-suppress AUTOSAR-M0_1_3-a "False Positive: All local variables are used"
1628 // parasoft-begin-suppress AUTOSAR-A8_4_2-a "False positive: function does have a return"
1629 // parasoft-begin-suppress CERT_C-MSC37-a "False positive: function does have a return"
1630 // parasoft-begin-suppress CERT_C-EXP37-a "False positive: function does have a return"
1631 // parasoft-begin-suppress CERT_CPP-MSC52-a "False positive: function does have a return"
1632 /// @brief Deduced-this helper that detemplitizes equal_range iterator generation from key type.
1633 ///
1634 /// @tparam SelfType Deduced-this type of the set.
1635 /// @param self The instance of the set to operate on.
1636 /// @param lb_info An instance of the return from @c lower_bound_index()
1637 /// @return auto A pair of iterators where the first element is @c make_find_iterator(self,lb_info) , and the second
1638 /// element is either that iterator incremented by one if the iterator was not @c self.end() , otherwise @c self.end()
1639 template <typename SelfType, constraints<std::enable_if_t<decays_to_v<SelfType, inline_set>>> = nullptr>
1640 static auto
1641 make_equal_range_iterator(SelfType&& self, inline_container::detail::lower_bound_index_info<index_type> lb_info)
1642 -> std::pair<iterator, iterator> {
1643 auto first = make_find_iterator(std::forward<SelfType>(self), lb_info);
1644 auto last = first == self.end() ? first : ::arene::base::next(first);
1645 return std::make_pair(first, last);
1646 }
1647 // parasoft-end-suppress CERT_CPP-MSC52-a
1648 // parasoft-end-suppress AUTOSAR-A8_4_2-a
1649 // parasoft-end-suppress CERT_C-MSC37-a
1650 // parasoft-end-suppress CERT_C-EXP37-a
1651 // parasoft-end-suppress AUTOSAR-M0_1_3-a
1652 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
1653
1654 /// @brief Helper implementation for @c equal_range which works for all comparators and iterator types.
1655 ///
1656 /// @tparam OtherKey the type of the value to find
1657 /// @param value The value to search for
1658 /// @return std::pair<iterator, iterator> A pair of iterators such that all values in the range @c [first,second)
1659 /// compare equal to @c value if there was an element equivalent to @c value in the set. Otherwise both
1660 /// iterators will be @c end() .
1661 template <typename OtherKey>
1662 auto do_equal_range(OtherKey const& value) const noexcept(comparison_is_noexcept<OtherKey>)
1663 -> std::pair<iterator, iterator> {
1664 return make_equal_range_iterator(*this, lower_bound_index(value));
1665 }
1666
1667 /// @brief Obtain the index of the first element such that @c element < @c value
1668 /// @param value The value to search for
1669 /// @return inline_container::detail::lower_bound_index_info<index_type> The index of the element, and the
1670 /// strong_ordering between that
1671 /// element and @c value . If @c value is greater than all elements, then the index is @c size() and the
1672 /// ordering is @c strong_ordering::greater .
1673 /// @throws Any exception thrown by the comparisons
1674 template <typename OtherKey>
1675 auto lower_bound_index(OtherKey const& value) const noexcept(comparison_is_noexcept<OtherKey>)
1676 -> inline_container::detail::lower_bound_index_info<index_type> {
1677 auto const compare = [this](key_type const& lhs, OtherKey const& rhs) noexcept(comparison_is_noexcept<OtherKey>) {
1678 return this->key_ordering(lhs, rhs);
1679 };
1680 auto const accessor = [this](index_type const index) noexcept -> key_type const& {
1681 return *(this->entry_at_index(inline_set_detail::set_passkey{}, index));
1682 };
1683 return inline_container::detail::lower_bound_index<key_type, OtherKey, index_type>(
1684 value,
1685 number_of_active_elements_,
1686 compare,
1687 accessor
1688 );
1689 }
1690
1691 /// @brief Helper implementation for @c erase which works for all comparators
1692 ///
1693 /// @tparam OtherKey The type of the element to erase.
1694 /// @param value The value of elements to erase
1695 /// @return The number of elements erased, which will be @c 1 if the element was in the set, else <c>0</c>.
1696 template <typename OtherKey>
1697 auto do_erase(OtherKey const& value) noexcept(comparison_is_noexcept<OtherKey>) -> size_type {
1698 return erase_at_index(do_find(value).index(inline_set_detail::set_passkey{}));
1699 }
1700
1701 /// @brief Insert a new element at the specified index, constructed from the supplied value. This uses perfect
1702 /// forwarding so the same function handles copies and moves.
1703 /// @tparam V The type of the source value
1704 /// @param pos The position at which to insert the element
1705 /// @param value The new value
1706 /// @pre If insertion is required, @c size<Capacity else @c ARENE_PRECONDITION violation.
1707 template <typename V>
1708 void insert_at(index_type pos, V&& value) noexcept(std::is_nothrow_constructible<Value, V&&>::value) {
1709 auto const new_index = indices_[number_of_active_elements_];
1710 values_[new_index].emplace(std::forward<V>(value));
1711 insert_index_at(pos, new_index);
1712 }
1713
1714 // parasoft-begin-suppress AUTOSAR-A8_4_2-a "False positive: function does have a return"
1715 // parasoft-begin-suppress CERT_C-MSC37-a "False positive: function does have a return"
1716 // parasoft-begin-suppress CERT_C-EXP37-a "False positive: function does have a return"
1717 /// @brief Insert a new entry into the index at the specified position.
1718 /// @param pos The position at which to insert the new value
1719 /// @param new_index The index into the data array of the element being inserted
1720 void insert_index_at(index_type pos, index_type new_index) noexcept {
1721 for (index_type i{number_of_active_elements_}; i != pos; --i) {
1722 indices_[i] = indices_[static_cast<index_type>(i - 1U)];
1723 }
1724 indices_[pos] = new_index;
1725 ++number_of_active_elements_;
1726 }
1727 // parasoft-end-suppress AUTOSAR-A8_4_2-a
1728 // parasoft-end-suppress CERT_C-MSC37-a
1729 // parasoft-end-suppress CERT_C-EXP37-a
1730
1731 // parasoft-begin-suppress CERT_C-MSC37-a "False positive: function does have a return"
1732 // parasoft-begin-suppress CERT_CPP-MSC52-a "False positive: function does have a return"
1733 // parasoft-begin-suppress AUTOSAR-A8_4_2-a "False positive: function does have a return"
1734 /// @brief Insert a new element constructed from the specified value if there is not already an equivalent element in
1735 /// the map. Uses perfect forwarding to handle copying/moving as appropriate
1736 /// @tparam V The type of the source value
1737 /// @param value The new value
1738 /// @return A pair holding an iterator to the inserted element, or the existing element with equivalent value, and a
1739 /// boolean which is @c true if the value was inserted, and @c false otherwise.
1740 /// @pre If insertion is required, @c size<Capacity else @c ARENE_PRECONDITION violation.
1741 template <typename V>
1742 auto internal_insert(V&& value
1743 ) noexcept(comparison_is_noexcept<V> && std::is_nothrow_constructible<Value, V&&>::value)
1744 -> std::pair<iterator, bool> {
1745 auto const pos_info = lower_bound_index(value);
1746 auto const do_insert = pos_info.order != strong_ordering::equal;
1747 if (do_insert) {
1748 insert_at(pos_info.index, std::forward<V>(value));
1749 }
1750 return {make_iterator(*this, pos_info.index), do_insert};
1751 }
1752 // parasoft-end-suppress AUTOSAR-A8_4_2-a
1753 // parasoft-end-suppress CERT_CPP-MSC52-a
1754 // parasoft-end-suppress CERT_C-MSC37-a
1755
1756 /// @brief Erase the element at the specified index if the index is in bounds; otherwise, do nothing.
1757 /// @param index The index of the element to erase
1758 /// @return The number of elements erased: @c size_type{1U} if an erasure was performed, or @c size_type{0U} if not
1759 auto erase_at_index(index_type index) noexcept -> size_type {
1760 if (index < number_of_active_elements_) {
1761 erase_index_range(index, 1U);
1762 return 1U;
1763 }
1764 return 0U;
1765 }
1766
1767 /// @brief Erase the specified number of elements starting at the specified position.
1768 /// @param from The position in the index of the first element to erase
1769 /// @param count_to_erase The number of elements to erase
1770 // NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
1771 auto erase_index_range(index_type from, index_type count_to_erase) noexcept -> void {
1772 index_type last_index{static_cast<index_type>(from + count_to_erase)};
1773 for (index_type index{from}; index < last_index; ++index) {
1774 entry_at_index(inline_set_detail::set_passkey{}, index).reset();
1775 }
1776 std::ignore = arene::base::rotate(
1777 indices_.begin() + from,
1778 indices_.begin() + last_index,
1779 indices_.begin() + number_of_active_elements_
1780 );
1781 number_of_active_elements_ = static_cast<index_type>(number_of_active_elements_ - (last_index - from));
1782 }
1783
1784 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
1785 /// @brief Move-construct a new element from the specified element, and clear the old element.
1786 /// @param other The element to move from
1787 /// @return The new element
1788 /// @throws Any exception thrown by the copy-constructor of @c Key or the
1789 /// move-constructor of @c Value
1790 static auto move_value(entry_type& other) noexcept(std::is_nothrow_move_constructible<value_type>::value)
1791 -> entry_type {
1792 entry_type res{std::move(other)};
1793 other.reset();
1794 return res;
1795 }
1796 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
1797
1798 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
1799 /// @brief Move the values from the source set into a new array. Clears the source set.
1800 /// @tparam Indices The indices into the source set
1801 /// @param source The source set
1802 /// @return The new data array
1803 template <std::size_t... Indices>
1804 static auto move_values(inline_set& source, std::index_sequence<Indices...>) -> storage_type {
1805 // parasoft-begin-suppress AUTOSAR-M0_1_3-a-2 "False positive: RAII class"
1806 auto const clear_on_exit = clear_on_scope_exit(source);
1807 // parasoft-end-suppress AUTOSAR-M0_1_3-a-2
1808 return {{move_value(source.values_[Indices])...}};
1809 }
1810 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
1811
1812 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
1813 /// @brief Move the values from a source set with a different capacity into a new array. Clears the source set.
1814 /// @tparam OtherCapacity The capacity of the other set
1815 /// @tparam Indices The indices into the source set
1816 /// @param source The source set
1817 /// @return The new data array
1818 /// @pre The size of the source set must be less than @c Capacity
1819 template <std::size_t OtherCapacity, std::size_t... Indices>
1821 -> storage_type {
1822 auto const clear_on_exit = clear_on_scope_exit(source);
1823 return {{move_value(source.entry_at_index(inline_set_detail::set_passkey{}, Indices))...}};
1824 }
1825 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
1826
1827 // parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: This identifier does not hide anything"
1828 /// @brief Helper to create a scope-guard which clears the input source on scope exit.
1829 ///
1830 /// @param source The container to clear on scope exit.
1831 /// @return A @c scope_guard which will call @c clear() on @c source .
1832 template <std::size_t OtherCapacity>
1833 static auto clear_on_scope_exit(inline_set<Value, OtherCapacity, Compare>& source) noexcept -> decltype(auto) {
1834 return on_scope_exit( //
1835 [&source]() noexcept { source.clear(); }
1836 );
1837 }
1838 // parasoft-end-suppress AUTOSAR-A2_10_1-e-2
1839
1840 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: Uses this"
1841 /// @brief Helper to create a scope-guard which resets all values between the current number_of_active_elements_ and
1842 /// an index.
1843 ///
1844 /// @param end_index One past the last index to reset to.
1845 /// @return A @c scope_guard which will call @c reset() on every element fetched via @c entry_at_index() in the range
1846 /// @c [number_of_active_elements_,end_index) .
1847 auto reset_trailing_values_on_scope_exit(index_type end_index) noexcept -> decltype(auto) {
1848 return on_scope_exit([this, end_index]() noexcept {
1849 for (index_type idx = this->number_of_active_elements_; idx < end_index; ++idx) {
1850 this->entry_at_index(inline_set_detail::set_passkey{}, idx).reset();
1851 }
1852 });
1853 }
1854 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
1855
1856 /// @brief Copy the elements from the other set over those in the current set.
1857 ///
1858 /// @tparam OtherSet The type of the set to copy from
1859 /// @param other The source set
1860 /// @throws Any exception thrown by the copy of the elements or comparator
1861 /// @post @c size()==other.size() , or the index of the first element which throws during copy construction if a throw
1862 /// occurs.
1863 /// @post @c The elements from @c other will have been copy-emplaced into @c this , up to the first element which
1864 /// threw during move-construction, if any.
1865 /// @post @c The elements in the range @c [size(),other.size()) will have been reset if @c other.size() was smaller
1866 /// than the original size of @c this .
1867 template <typename OtherSet>
1868 void do_copy(OtherSet const& other
1870 do_assignment(other);
1871 }
1872
1873 /// @brief Move the elements from the other set over those in the current set.
1874 ///
1875 /// @tparam OtherSet The type of the set to move from
1876 /// @param other The source set
1877 /// @throws Any exception thrown by the move of the elements or comparator
1878 /// @post @c size()==other.size() , or the index of the first element which throws during move construction if a throw
1879 /// occurs.
1880 /// @post @c other.clear() will have been executed
1881 /// @post @c The elements from @c other will have been move-emplaced into @c this , up to the first element which
1882 /// threw during move-construction, if any.
1883 /// @post @c The elements in the range @c [size(),other.size()) will have been reset if @c other.size() was smaller
1884 /// than the original size of @c this .
1885 template <typename OtherSet>
1886 void do_move(OtherSet&& other
1888 // parasoft-begin-suppress AUTOSAR-M0_1_3-a-2 "False positive: RAII class"
1889 auto const clear_on_exit = clear_on_scope_exit(other);
1890 // parasoft-end-suppress AUTOSAR-M0_1_3-a-2
1891 do_assignment(std::forward<OtherSet>(other));
1892 }
1893
1894 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "False positive: Elements are forwarded via 'forward_like'"
1895 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: Elements are forwarded via 'forward_like'"
1896 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: Elements are forwarded via 'forward_like'"
1897 /// @brief Helper for @c do_copy and @c do_move with non-copy/move dependent logic.
1898 ///
1899 /// @tparam OtherSet The type of the set to copy/move from
1900 /// @param other The source set top copy/move from.
1901 /// @throws Any exception thrown by the copy/move of the elements or comparator
1902 /// @post @c size()==other.size() , or the index of the first element which throws during move construction if a throw
1903 /// occurs.
1904 /// @post @c The elements from @c other will have been move-emplaced into @c this , up to the first element which
1905 /// threw during copy/move-construction, if any.
1906 /// @post @c The elements in the range @c [size(),other.size()) will have been reset if @c other.size() was smaller
1907 /// than the original size of @c this .
1908 template <typename OtherSet>
1909 void do_assignment(OtherSet&& other) noexcept(
1912 ) {
1913 // parasoft-begin-suppress AUTOSAR-M0_1_3-a-2 "False positive: RAII class"
1914 auto const reset_trailing_values = reset_trailing_values_on_scope_exit(number_of_active_elements_);
1915 // parasoft-end-suppress AUTOSAR-M0_1_3-a-2
1916 number_of_active_elements_ = 0U;
1917 while (number_of_active_elements_ != other.size()) {
1918 this->entry_at_index(inline_set_detail::set_passkey{}, number_of_active_elements_)
1920 *other.entry_at_index(inline_set_detail::set_passkey{}, number_of_active_elements_)
1921 ));
1922 ++number_of_active_elements_;
1923 }
1924 }
1925 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
1926 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
1927 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
1928}; // namespace base
1929// parasoft-end-suppress AUTOSAR-A1_1_1-c-2
1930// parasoft-end-suppress AUTOSAR-A12_0_1-a-2
1931// parasoft-end-suppress AUTOSAR-A10_1_1-a-2
1932// parasoft-end-suppress AUTOSAR-A12_1_5-a-2
1933
1934/// @brief Externalized initialization of max_size is needed pre C++17.
1935template <typename T, std::size_t Capacity, typename Compare>
1937
1938/// @brief Externalized initialization of capacity is needed pre C++17.
1939template <typename T, std::size_t Capacity, typename Compare>
1941
1942} // namespace base
1943} // namespace arene
1944
1945#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_SET_HPP_
Provides a backport of C++17's constexpr std::advance.
A fixed-size array of T objects.
Definition array.hpp:77
A non-allocating fixed-capacity associative container storing elements of type Value .
Definition set.hpp:111
auto find(OtherKey const &value) noexcept(comparison_is_noexcept< OtherKey >) -> iterator
Obtain an iterator referring to the element equivalent to the supplied value, if there is one.
Definition set.hpp:1003
auto insert(Value &&value_to_insert) noexcept(comparison_is_noexcept<> &&std::is_nothrow_move_constructible< Value >::value) -> std::pair< iterator, bool >
Attempt to insert an element into the set.
Definition set.hpp:1211
auto crbegin() const noexcept -> const_reverse_iterator
Obtain an iterator referring to the beginning of a reversed traversal of the sorted range of elements...
Definition set.hpp:1294
Compare key_compare
The type of the comparator for the key.
Definition set.hpp:365
auto cbegin() const noexcept -> const_iterator
Obtain an iterator referring to the beginning of the sorted range of elements.
Definition set.hpp:1280
auto lower_bound(OtherKey const &value) const noexcept(comparison_is_noexcept< OtherKey >) -> const_iterator
Find the first element which is not less than a given value.
Definition set.hpp:1090
auto operator=(deleted_copy_assign_source const &other) -> inline_set &=delete
Deleted copy-assignment operator where the set is not copy-assignable.
value_type const * const_pointer
A pointer to a const value.
Definition set.hpp:375
Value key_type
The type of the key in the set, which is the same as the value.
Definition set.hpp:360
inline_set(inline_set< Value, OtherCapacity, Compare > &&other)
move construct from a set with a larger capacity
Definition set.hpp:731
auto emplace(ArgTypes &&... args) -> std::pair< iterator, bool >
Construct a new element from the specified initialization arguments, and then attempt to insert it.
Definition set.hpp:1318
static ARENE_NODISCARD auto try_construct(std::initializer_list< Value > init) noexcept(noexcept(inline_set{init}) &&std::is_nothrow_move_constructible< inline_set >::value) -> optional< inline_set >
Attempt to construct a set from the specified list of values.
Definition set.hpp:469
void insert(std::initializer_list< Value > init)
Attempt to insert the elements in the provided initializer list into the set.
Definition set.hpp:1272
Value value_type
The type of the value in the set.
Definition set.hpp:350
::arene::base::reverse_iterator< iterator > reverse_iterator
A reverse iterator for the set.
Definition set.hpp:410
auto erase(Value const &value_to_erase) noexcept(comparison_is_noexcept<>) -> size_type
Erase any elements with a value equivalent to the supplied element.
Definition set.hpp:1347
auto upper_bound(OtherKey const &value) noexcept(comparison_is_noexcept< OtherKey >) -> iterator
Find the first element which is greater than a given value.
Definition set.hpp:1119
static ARENE_NODISCARD auto try_construct(inline_set< Value, OtherCapacity, Compare > &&other) noexcept(noexcept(inline_set{other})) -> optional< inline_set >
Attempts to construct a set via move-construction from a set with a larger capacity.
Definition set.hpp:789
Compare value_compare
The type of the comparator for the value.
Definition set.hpp:355
inline_set()=default
Construct a set with no elements and a default-constructed comparator.
auto count(OtherKey const &value) const noexcept(comparison_is_noexcept< OtherKey >) -> std::size_t
Return the number of elements in the set equivalent to a specific value.
Definition set.hpp:1051
static ARENE_NODISCARD auto try_construct(Iterator first, Iterator last, Compare const &comp) noexcept(noexcept(inline_set{first, last, comp}) &&std::is_nothrow_move_constructible< inline_set >::value) -> optional< inline_set >
Attempt to construct a set from the specified sequence of values and a comparator.
Definition set.hpp:596
std::ptrdiff_t difference_type
The type of the difference between two iterators.
Definition set.hpp:395
static constexpr std::integral_constant< size_type, Capacity > capacity
The maximum number of elements that can be held in the set.
Definition set.hpp:957
static constexpr std::integral_constant< size_type, Capacity > max_size
Get the maximum number of elements in the set.
Definition set.hpp:966
auto insert(Value const &value_to_insert) noexcept(comparison_is_noexcept<> &&std::is_nothrow_copy_constructible< Value >::value) -> std::pair< iterator, bool >
Attempt to insert an element into the set.
Definition set.hpp:1192
auto lower_bound(Value const &value_to_find) const noexcept(comparison_is_noexcept<>) -> const_iterator
Find the first element which is not less than a given value.
Definition set.hpp:1068
auto rbegin() const noexcept -> const_reverse_iterator
Obtain an iterator referring to the beginning of a reversed traversal of the sorted range of elements...
Definition set.hpp:1291
ARENE_NODISCARD auto empty() const noexcept -> bool
Check if the set is empty.
Definition set.hpp:946
auto find(Value const &value_to_find) noexcept(comparison_is_noexcept<>) -> iterator
Obtain an iterator referring to the element equivalent to the supplied value, if there is one.
Definition set.hpp:986
auto count(Value const &value_to_count) const noexcept(comparison_is_noexcept<>) -> std::size_t
Return the number of elements in the set equivalent to a specific value.
Definition set.hpp:1041
auto key_comp() const noexcept(std::is_nothrow_copy_constructible< Compare >::value) -> key_compare
Get the comparator.
Definition set.hpp:972
static ARENE_NODISCARD auto try_construct(std::initializer_list< Value > init, Compare const &comp) noexcept(noexcept(inline_set{init, comp}) &&std::is_nothrow_move_constructible< inline_set >::value) -> optional< inline_set >
Attempt to construct a set from the specified list of values and a comparator.
Definition set.hpp:487
auto erase(iterator first, iterator last) noexcept -> iterator
Erase all the elements referred to be the specified iterator range.
Definition set.hpp:1377
~inline_set()=default
Default destructor; destroys all stored elements.
inline_set(Iterator first, Iterator last) noexcept(std::is_nothrow_constructible< Value, typename std::iterator_traits< Iterator >::reference >::value &&std::is_nothrow_constructible< Compare >::value)
Construct a set from the elements in the provided iterator range.
Definition set.hpp:516
auto crend() const noexcept -> const_reverse_iterator
Obtain an iterator referring to one past the last element in a reversed traversal of the sorted range...
Definition set.hpp:1303
auto erase(OtherKey const &value) noexcept(comparison_is_noexcept< OtherKey >) -> size_type
Erase any elements with a value equivalent to the supplied element.
Definition set.hpp:1356
auto insert(OtherKey &&value) noexcept(comparison_is_noexcept< OtherKey > &&std::is_nothrow_constructible< Value, OtherKey && >::value) -> std::pair< iterator, bool >
Attempt to insert an element into the set.
Definition set.hpp:1237
auto find(Value const &value_to_find) const noexcept(comparison_is_noexcept<>) -> const_iterator
Obtain an iterator referring to the element equivalent to the supplied value, if there is one.
Definition set.hpp:993
static ARENE_NODISCARD auto three_way_compare(inline_set const &lhs, inline_set< Value, OtherCapacity, Compare > const &rhs) noexcept -> strong_ordering
Compares two sets lexicographically .
Definition set.hpp:1428
auto value_comp() const noexcept(std::is_nothrow_copy_constructible< Compare >::value) -> value_compare
Get the comparator.
Definition set.hpp:978
inline_set(inline_set< Value, OtherCapacity, Compare > const &other) noexcept(std::is_nothrow_copy_constructible< Value >::value &&std::is_nothrow_copy_constructible< Compare >::value)
copy construct from a set with a larger capacity
Definition set.hpp:649
auto operator=(deleted_move_assign_source &&) -> inline_set &=delete
The move assignment operator is deleted if move assignment is not supported.
auto operator=(inline_set< Value, OtherCapacity, Compare > &&other) noexcept(std::is_nothrow_move_assignable< inline_set< Value, OtherCapacity, Compare > >::value) -> inline_set &
move-assignment operator from an inline_set with a smaller capacity
Definition set.hpp:937
inline_set(move_construct_source &&other) noexcept(std::is_nothrow_move_constructible< Value >::value &&std::is_nothrow_constructible< Compare >::value)
move ctor
Definition set.hpp:707
inline_set(inline_set const &)=default
copy ctor.
auto cend() const noexcept -> const_iterator
Obtain an iterator referring to one past the last element in the sorted range of elements.
Definition set.hpp:1287
std::size_t size_type
The type of the size of the container.
Definition set.hpp:390
auto begin() const noexcept -> const_iterator
Obtain an iterator referring to the beginning of the sorted range of elements.
Definition set.hpp:1277
auto erase(iterator pos) noexcept -> iterator
Erase the element referred to be the specified iterator.
Definition set.hpp:1364
inline_set(std::initializer_list< Value > init, Compare const &comp) noexcept(std::is_nothrow_copy_constructible< Value >::value &&std::is_nothrow_copy_constructible< Compare >::value)
Construct a set from the specified list of values and a specified comparator instance .
Definition set.hpp:455
auto lower_bound(OtherKey const &value) noexcept(comparison_is_noexcept< OtherKey >) -> iterator
Find the first element which is not less than a given value.
Definition set.hpp:1079
auto rend() const noexcept -> const_reverse_iterator
Obtain an iterator referring to one past the last element in a reversed traversal of the sorted range...
Definition set.hpp:1299
auto entry_at_index(inline_set_detail::set_passkey, index_type index) noexcept -> entry_type &
Gets a reference to the element corrsponding to a given index.
Definition set.hpp:1454
auto equal_range(Value const &value_to_find) noexcept(comparison_is_noexcept<>) -> std::pair< iterator, iterator >
Finds the sequence of values which compare equivalent to a given value.
Definition set.hpp:1140
inline_set(inline_set< Value, OtherCapacity, Compare > const &other) noexcept(std::is_nothrow_copy_constructible< Value >::value &&std::is_nothrow_copy_constructible< Compare >::value)
copy construct from a set with a smaller capacity
Definition set.hpp:627
iterator const_iterator
A const iterator for the set: the same as iterator, since elements are const.
Definition set.hpp:405
auto upper_bound(OtherKey const &value) const noexcept(comparison_is_noexcept< OtherKey >) -> const_iterator
Find the first element which is greater than a given value.
Definition set.hpp:1130
auto contains(OtherKey const &value) const noexcept(comparison_is_noexcept< OtherKey >) -> bool
Check if the set contains a value equivalent to a specific value.
Definition set.hpp:1033
auto find(OtherKey const &value) const noexcept(comparison_is_noexcept< OtherKey >) -> const_iterator
Obtain an iterator referring to the element equivalent to the supplied value, if there is one.
Definition set.hpp:1013
static ARENE_NODISCARD auto try_construct(inline_set< Value, OtherCapacity, Compare > const &other) noexcept(noexcept(inline_set{other})) -> optional< inline_set >
Attempts to construct a set via copy-construction from a set with the same or smaller capacity.
Definition set.hpp:669
void clear() noexcept
Erase all the elements in *this.
Definition set.hpp:1389
value_type const & const_reference
A reference to a const value.
Definition set.hpp:385
auto operator=(inline_set< Value, OtherCapacity, Compare > const &other) noexcept(std::is_nothrow_copy_assignable< inline_set< Value, OtherCapacity, Compare > >::value) -> inline_set &
copy-assignment operator for copying from a set with a smaller capacity
Definition set.hpp:862
inline_set(Compare const &comp) noexcept(std::is_nothrow_copy_constructible< Compare >::value)
Construct a set with no elements, using the specified comparator.
Definition set.hpp:428
auto upper_bound(Value const &value_to_find) noexcept(comparison_is_noexcept<>) -> iterator
Find the first element which is greater than a given value.
Definition set.hpp:1099
iterator_impl iterator
The iterator type for the set.
Definition set.hpp:400
inline_set(inline_set< Value, OtherCapacity, Compare > &&other) noexcept(std::is_nothrow_move_constructible< Value >::value &&std::is_nothrow_move_constructible< Compare >::value)
move construct from a set with a smaller capacity
Definition set.hpp:751
static ARENE_NODISCARD auto try_construct(inline_set< Value, OtherCapacity, Compare > const &other) noexcept(noexcept(inline_set{other})) -> optional< inline_set >
Attempts to construct a set from a set with a larger capacity.
Definition set.hpp:687
auto equal_range(OtherKey const &value) noexcept(comparison_is_noexcept< OtherKey >) -> std::pair< iterator, iterator >
Finds the sequence of values which compare equivalent to a given value.
Definition set.hpp:1162
value_type * pointer
A pointer to the value.
Definition set.hpp:370
auto upper_bound(Value const &value_to_find) const noexcept(comparison_is_noexcept<>) -> const_iterator
Find the first element which is greater than a given value.
Definition set.hpp:1108
::arene::base::reverse_iterator< const_iterator > const_reverse_iterator
A const reverse iterator for the set.
Definition set.hpp:415
inline_set(Iterator first, Iterator last, Compare const &comp) noexcept(std::is_nothrow_constructible< Value, typename std::iterator_traits< Iterator >::reference >::value &&std::is_nothrow_copy_constructible< Compare >::value)
Construct a set from the elements in the provided iterator range and comparator.
Definition set.hpp:543
auto equal_range(OtherKey const &value) const noexcept(comparison_is_noexcept< OtherKey >) -> std::pair< const_iterator, const_iterator >
Finds the sequence of values which compare equivalent to a given value.
Definition set.hpp:1174
auto operator=(copy_assign_source const &other) noexcept(std::is_nothrow_copy_constructible< Value >::value &&std::is_nothrow_copy_assignable< Compare >::value) -> inline_set &
copy-assignment operator.
Definition set.hpp:812
auto equal_range(Value const &value_to_find) const noexcept(comparison_is_noexcept<>) -> std::pair< const_iterator, const_iterator >
Finds the sequence of values which compare equivalent to a given value.
Definition set.hpp:1149
auto contains(Value const &value_to_check) const noexcept(comparison_is_noexcept<>) -> bool
Check if the set contains a specific value.
Definition set.hpp:1022
auto operator=(move_assign_source &&other) noexcept(std::is_nothrow_move_constructible< Value >::value &&std::is_nothrow_move_assignable< Compare >::value) -> inline_set &
move-assignment operator
Definition set.hpp:886
auto lower_bound(Value const &value_to_find) noexcept(comparison_is_noexcept<>) -> iterator
Find the first element which is not less than a given value.
Definition set.hpp:1060
auto end() const noexcept -> const_iterator
Obtain an iterator referring to one past the last element in the sorted range of elements.
Definition set.hpp:1284
auto get_comparator_base(inline_set_detail::set_passkey) noexcept -> comparator_base &
Get the comparator base.
Definition set.hpp:1438
auto size() const noexcept -> std::size_t
Get the number of elements in the set.
Definition set.hpp:950
static ARENE_NODISCARD auto try_construct(inline_set< Value, OtherCapacity, Compare > &&other) noexcept(noexcept(inline_set{std::move(other)})) -> optional< inline_set >
Attempts to construct a set via move-construction from a set with a capacity that is less than or equ...
Definition set.hpp:771
auto entry_at_index(inline_set_detail::set_passkey, index_type index) const noexcept -> entry_type const &
Gets a reference to the element corrsponding to a given index.
Definition set.hpp:1465
static ARENE_NODISCARD auto try_construct(Iterator first, Iterator last) noexcept(noexcept(inline_set{first, last}) &&std::is_nothrow_move_constructible< inline_set >::value) -> optional< inline_set >
Attempt to construct a set from the specified sequence of values.
Definition set.hpp:568
auto get_comparator_base(inline_set_detail::set_passkey) const noexcept -> comparator_base const &
Get the comparator base.
Definition set.hpp:1445
void insert(Iterator first, Iterator last) noexcept(std::is_nothrow_constructible< Value, >::value)
Insert all the elements in the provided iterator range into the set, if there are not already equival...
Definition set.hpp:1258
value_type & reference
A reference to a value.
Definition set.hpp:380
inline_set(std::initializer_list< Value > init) noexcept(std::is_nothrow_copy_constructible< Value >::value &&std::is_nothrow_constructible< Compare >::value)
Construct a set from the specified list of values.
Definition set.hpp:440
static ARENE_NODISCARD auto fast_inequality_check(inline_set const &lhs, inline_set< Value, OtherCapacity, Compare > const &rhs) noexcept -> inequality_heuristic
Fast inequality heuristic to shortcut on different sized containers.
Definition set.hpp:1401
A special dummy class that cannot be constructed. It can be used as a substitute argument for copy/mo...
Definition non_constructible_dummy.hpp:16
A simple class that resets an optional value in its destructor, unless dismissed.
Definition optional_resetter.hpp:29
Implementation of std::optional for pre-C++17 compilers, and which replaces defined undefined behavio...
Definition optional.hpp:122
A backport of the constexpr std::reverse_iterator from C++17.
Definition reverse_iterator.hpp:188
An empty tag type corresponding to a bidirectional iterator.
Definition iterator_tags.hpp:25
Implementation of std::initializer_list for brace initialization.
Definition initializer_list.hpp:21
constexpr auto end() const noexcept -> iterator
Get a pointer to one-past-the-last element.
Definition initializer_list.hpp:51
constexpr auto begin() const noexcept -> iterator
Get a pointer to the first element.
Definition initializer_list.hpp:46
A helper class to represent a compile-time constant with the specified type and value....
Definition integral_constant.hpp:23
static constexpr value_type value
Definition integral_constant.hpp:34
Type trait to detect if a type is constructible from arguments of the specified types.
Definition is_constructible.hpp:29
Type trait to detect if an instance of T is copy assignable.
Definition is_copy_assignable.hpp:59
Type trait to detect if an instance of T is copy constructible.
Definition is_copy_constructible.hpp:60
Type trait to detect if an instance of T is move assignable.
Definition is_move_assignable.hpp:60
Type trait to detect if a type is constructible from arguments of the specified types and is noexcept...
Definition is_constructible.hpp:84
Type trait to detect if an instance of T is copy assignable without throwing.
Definition is_copy_assignable.hpp:69
Type trait to detect if an instance of T is move assignable without throwing.
Definition is_move_assignable.hpp:70
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Provides the decays_to_v<T, U> trait.
Implementation of a backport of std::forward_like.
Provides backports of std::in_place_t, std::in_place_type_t, and std::in_place_index_t from C++17.
Provides implementation of arene::base::is_transparent_comparator_for.
Provides an implementation of a backport of std::lexicographical_compare from C++20.
Definition accumulate.hpp:37
constexpr auto move(InIterator first, InIterator last, OutIterator output) noexcept(noexcept(*first++) &&noexcept(output++) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) noexcept(first !=last) &&//CODEQLFP(A5-2-6) std::is_nothrow_assignable<, typename std::iterator_traits< InIterator >::value_type >::value) -> OutIterator
Moves the elements in the range [first, last), to another range beginning at output,...
Definition move.hpp:46
ARENE_NODISCARD constexpr auto next(Iterator itr, typename std::iterator_traits< Iterator >::difference_type steps=1) noexcept(noexcept(::arene::base::advance(itr, steps))) -> Iterator
Produces the Nth successor (or predecessor if steps is negative) of an iterator.
Definition next.hpp:38
strong_ordering_detail::strong_ordering strong_ordering
The enumeration specifying the result of an ordering comparison.
Definition strong_ordering.hpp:147
typename static_if< B >::template then_else< T, F > conditional_t
lazily select between two types based on a boolean condition
Definition conditional.hpp:28
three_way_compare_detail::compare_three_way compare_three_way
Function object that does a three-way comparison between operands, equivalent to std::compare_three_w...
Definition compare_three_way.hpp:214
constexpr bool is_invocable_r_v
Determine if a functor type is invocable with the specified return and argument types.
conditional_t<(MaxValue<=smallest_integer_for_detail::max_uint8), std::uint8_t, conditional_t<(MaxValue<=smallest_integer_for_detail::max_uint16), std::uint16_t, conditional_t<(MaxValue<=smallest_integer_for_detail::max_uint32), std::uint32_t, std::uint64_t > > > smallest_unsigned_integer_for
Calculates the smallest unsigned integer type that can be used to hold values up to and including Max...
Definition smallest_integer_for.hpp:38
constexpr auto make_subrange(Iterator iterator, Sentinel sentinel) noexcept(std::is_nothrow_move_constructible< Iterator >::value &&//std::is_nothrow_move_constructible< Sentinel >::value) -> make_subrange_detail::iterator_range< Iterator, Sentinel >
Combine an iterator and sentinel into a range type that can be used with range-based for loops.
Definition make_subrange.hpp:98
ARENE_NODISCARD auto on_scope_exit(CallableType &&func) noexcept(std::is_nothrow_constructible< remove_cvref_t< CallableType >, CallableType >::value) -> scope_guard< remove_cvref_t< CallableType > >
Declarative helper for constructing scope_guard instances.
Definition scope_guard.hpp:122
constexpr bool is_transparent_three_way_comparator_for_v
Trait to determine if a given type is a transparent comparator that performs a three-way comparison f...
constexpr auto forward_like
A backport of C++23's std::forward_like, which allows forwarding a type with the same reference and c...
constexpr bool is_transparent_comparator_for_v
Trait to determine if a given type is a transparent comparator for a given set of operands.
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
inequality_heuristic
An enumeration used for the return value of fast_inequality_check functions to indicate if two values...
Definition operators.hpp:696
@ may_be_equal_or_not_equal
The values checked may or may not be equal to each other; a more detailed check is required.
Definition operators.hpp:700
@ definitely_not_equal
The two values checked are definitely not equal to each other.
Definition operators.hpp:698
Definition accumulate.hpp:36
STL namespace.
::ptrdiff_t ptrdiff_t
A type suitable for holding the difference between two pointers.
Definition cstddef.hpp:31
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
constexpr auto make_pair(T1 &&first, T2 &&second) noexcept(is_nothrow_constructible_v< pair_detail::deduced_pair_type_t< T1, T2 >, T1, T2 >) -> pair_detail::deduced_pair_type_t< T1, T2 >
Creates a std::pair object, deducing the target type from the types of arguments.
Definition pair.hpp:611
integer_sequence< size_t, Ints... > index_sequence
A helper alias template for integer_sequence<size_t, Ints>
Definition integer_sequence.hpp:218
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
static constexpr auto const & ignore
An object to which anything can be assigned, which ignores the assigned value.
Definition ignore.hpp:72
constexpr auto forward(remove_reference_t< T > &value) noexcept -> T &&
Cast a value to an rvalue if T is an rvalue or rvalue reference, otherwise forward an lvalue referenc...
Definition forward.hpp:24
#define ARENE_NODISCARD
An alias for [[nodiscard]] , or a no-op if the attribute is not supported.
Definition nodiscard.hpp:26
Provides a backport of the constexpr implementation of std::reverse_iterator .