Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
map.hpp
Go to the documentation of this file.
1// parasoft-begin-suppress AUTOSAR-A2_8_1-a-2 AUTOSAR-A8_4_2-a CERT_C-MSC37-a CERT_CPP-MSC52-a
2// "inline_container/map.hpp is clear enough for inline_map and
3// ARENE_PRECONDITION terminates, so does not need a return"
4
5// Copyright 2024, Toyota Motor Corporation
6//
7// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
9#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_MAP_HPP_
10#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_MAP_HPP_
11
12// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
24#include "arene/base/detail/exceptions.hpp"
25#include "arene/base/detail/iterator_interface.hpp"
26#include "arene/base/inline_container/detail/compare.hpp"
27#include "arene/base/inline_container/detail/container_base_type.hpp"
28#include "arene/base/inline_container/detail/index_array.hpp"
29#include "arene/base/inline_container/detail/lower_bound_index.hpp"
35#include "arene/base/stdlib_choice/cstddef.hpp"
36#include "arene/base/stdlib_choice/enable_if.hpp"
37#include "arene/base/stdlib_choice/forward.hpp"
38#include "arene/base/stdlib_choice/ignore.hpp"
39#include "arene/base/stdlib_choice/initializer_list.hpp"
40#include "arene/base/stdlib_choice/integer_sequence.hpp"
41#include "arene/base/stdlib_choice/integral_constant.hpp"
42#include "arene/base/stdlib_choice/is_assignable.hpp"
43#include "arene/base/stdlib_choice/is_const.hpp"
44#include "arene/base/stdlib_choice/is_constructible.hpp"
45#include "arene/base/stdlib_choice/is_copy_assignable.hpp"
46#include "arene/base/stdlib_choice/is_copy_constructible.hpp"
47#include "arene/base/stdlib_choice/is_default_constructible.hpp"
48#include "arene/base/stdlib_choice/is_integral.hpp"
49#include "arene/base/stdlib_choice/is_move_assignable.hpp"
50#include "arene/base/stdlib_choice/is_move_constructible.hpp"
51#include "arene/base/stdlib_choice/is_same.hpp"
52#include "arene/base/stdlib_choice/iterator_tags.hpp"
53#include "arene/base/stdlib_choice/move.hpp"
54#include "arene/base/stdlib_choice/pair.hpp"
55#include "arene/base/stdlib_choice/remove_reference.hpp"
56#include "arene/base/stdlib_choice/tuple.hpp"
67// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
68
69// parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
70// parasoft-begin-suppress AUTOSAR-M2_10_1-a-2 "Similar names permitted by M2-10-1 Permit #1"
71// parasoft-begin-suppress AUTOSAR-A2_10_1-e-2 "False Positive: A2-10-1 exempts identifiers at class/namespace scope"
72// parasoft-begin-suppress AUTOSAR-A13_5_5-b-2 "Mixed comparisons permitted by A13-5-5 Permit #1"
73// parasoft-begin-suppress AUTOSAR-A7_1_5-a "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
74
75namespace arene {
76namespace base {
77namespace inline_map_detail {
78
79// parasoft-begin-suppress AUTOSAR-A15_4_5-a "False positive: The exception type that can be thrown is documented."
80/// @brief Implementation helper for conditional disablement of throwing when compiling with @c -fno-exceptions.
81/// @throws @c std::out_of_range if @c detail::are_exceptions_enabled_v is @c true .
82ARENE_NORETURN void throw_out_of_range();
83// parasoft-end-suppress AUTOSAR-A15_4_5-a "False positive: The exception type that can be thrown is documented."
84
85/// @brief base type for @c inline_map, allowing erasure of the @c Capacity value
86/// @tparam Key The key type for the map
87/// @tparam Value The mapped type for the map
88/// @tparam Compare The comparison function
89/// @pre The comparison must provide a strict ordering over the values of @c Key
90///
91template <typename Key, typename Value, typename Compare = compare_three_way>
92class inline_map_base {
93 public:
94 /// @brief key type of the map
95 using key_type = Key;
96 /// @brief mapped type of the map
97 using mapped_type = Value;
98 /// @brief value type of the map
99 using value_type = std::pair<Key const, Value>;
100 /// @brief compare type of the map
101 using compare_type = Compare;
102 /// @brief The size type of the map
103 using size_type = std::size_t;
104};
105
106/// @brief provides private access for the family of types related to an @c inline_map
107/// @tparam MapBase common tag across @c inline_map and related types
108///
109template <class MapBase>
110class inline_map_passkey_base {
111 static_assert(
113 "'MapBase' must be an instantiation of 'inline_map_base'."
114 );
115
116 protected:
117 /// @brief tag type used to limit access to a family of associated types
118 ///
119 class inline_map_passkey {
120 public:
121 /// @brief default constructor
122 ///
123 explicit inline_map_passkey() = default;
124 };
125};
126
127} // namespace inline_map_detail
128
129// parasoft-begin-suppress AUTOSAR-A12_0_1-b-2 "False positive: copy assignment defined or deleted as appropriate"
130// parasoft-begin-suppress AUTOSAR-A12_0_1-a-2 "False positive: copy assignment defined or deleted as appropriate"
131// parasoft-begin-suppress AUTOSAR-A1_1_1-b-2 "False positive: copy assignment defined or deleted as appropriate"
132// parasoft-begin-suppress AUTOSAR-A10_1_1-a-2 "False positive: the ordering base class is empty"
133// parasoft-begin-suppress AUTOSAR-A13_5_1-a-2 "False positive: This follows the std::map interface. The non-const
134// overload inserts a new element in the map if not present; the const overload cannot do that so is not provided"
135/// @brief A container similar to @c std::map that has a fixed capacity.
136///
137/// The storage is held internally in the object. Any attempt to store more than @c Capacity elements will either result
138/// in a precondition failure (and thus process termination), or an error being returned. The comparison function
139/// specified with the @c Compare template parameter can either return @c bool, in which case it is assumed to be a
140/// simple ordering comparison like @c std::less, or it can return @c strong_ordering, in which case it is assumed to be
141/// a three-way comparison operator. The default comparison is @c three_way_compare.
142/// @tparam Key The key type for the map
143/// @tparam Value The mapped type for the map
144/// @tparam Capacity The maximum number of elements that can be stored in the map
145/// @tparam Compare The comparison function
146/// @pre The comparison must provide a strict ordering over the values of @c Key
147template <typename Key, typename Value, std::size_t Capacity, typename Compare = compare_three_way>
148// NOLINTNEXTLINE(hicpp-special-member-functions,cppcoreguidelines-special-member-functions)
150 : public inline_map_detail::inline_map_base<Key, Value, Compare>
151 , inline_map_detail::inline_map_passkey_base<inline_map_detail::inline_map_base<Key, Value, Compare>>
152 , inline_container::detail::compare_wrapper<Compare, Key>
153 , generic_ordering_from_three_way_compare_and_equals<inline_map<Key, Value, Capacity, Compare>> {
154 // AUTOSAR exceptions:
155 // A11-3-1: Friend declarations shall not be used
156 // The inline_map class template declares other instantiations of the same
157 // template to be friends, so that copy and move operations between maps with
158 // different capacities work nicely.
159 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "Friendship allows copy and move between maps with different
160 // capacities"
161 template <typename OtherKey, typename OtherValue, std::size_t OtherCapacity, typename OtherCompare>
162 friend class inline_map;
163 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
164
165 /// @brief helper trait for determining if transparent comparison is supported in a type-dependent context
166 /// @tparam OtherKey Dummy parameter to make this type-dependent as it's used for SFINAE.
167 /// @return bool Equivalent to @c ::arene::base::is_transparent_comparator_v<Compare>
168 template <typename OtherKey>
169 static constexpr bool transparent_comparison_supported{::arene::base::is_transparent_comparator_v<Compare>};
170
171 /// @brief helper trait for determining if transparent insertion is supported in a type-dependent context
172 /// @tparam OtherKey Dummy parameter to make this type-dependent as it's used for SFINAE.
173 /// @return bool Equivalent to @c transparent_comparison_supported<Compare>&&!std::is_integral<Key>::value
174 template <typename OtherKey>
175 static constexpr bool transparent_insertion_supported{
176 transparent_comparison_supported<OtherKey> && !std::is_integral<Key>::value
177 };
178
179 /// @brief helper trait for determining if the comparator supports transparent comparisons.
180 /// @tparam OtherKey the type of the other operand to test for validity against.
181 /// @return bool @c true If @c Compare satisfies either @c is_transparent_comparator_for_v or
182 /// @c is_transparent_three_way_comparator_for_v with @c Key and @c OtherKey , else @c false .
183 template <typename OtherKey>
184 static constexpr bool
186
187 /// @brief The base class that holds the comparator
188 using comparator_base = inline_container::detail::compare_wrapper<Compare, Key>;
189
190 /// @brief The base class for ordering
192
193 /// @brief Can comparisons throw?
194 /// @tparam OtherKey The type of the rhs operand to a comparison.
195 /// @return bool alias for @c comparator_base::template comparison_is_noexcept<OtherKey>
196 template <typename OtherKey = Key>
197 static constexpr bool comparison_is_noexcept{comparator_base::template comparison_is_noexcept<OtherKey>};
198
199 /// @brief Base type of this @c inline_map type
200 using map_base_type = inline_map_detail::inline_map_base<Key, Value, Compare>;
201
202 /// @brief The type of an index which is the smallest that can fit @c Capacity .
204
205 /// @brief alias to the passkey type
206 using inline_map_passkey = typename inline_map_detail::inline_map_passkey_base<map_base_type>::inline_map_passkey;
207
208 /// @brief An iterator for a map; if @c IsConst is @c true this is a @c
209 /// const_iterator, otherwise an @c iterator.
210 /// @tparam IsConst Is this a const iterator?
211 template <bool IsConst>
212 class iterator_impl
213 : public detail::iterator_interface<iterator_impl<IsConst>>
214 , inline_map_detail::inline_map_passkey_base<map_base_type> {
215 /// @brief Alias for interface base
216 using iterator_interface = detail::iterator_interface<iterator_impl>;
217
218 /// @brief alias to the passkey type
219 using inline_map_passkey = typename inline_map_detail::inline_map_passkey_base<map_base_type>::inline_map_passkey;
220
221 /// @brief The type of the associated map: if this is a const iterator, we can use
222 /// a const map
224 /// @brief Pointer to the referenced map
225 map_type* map_;
226 /// @brief The index of the pointed-to element
227 index_type pos_;
228
229 /// @brief The corresponding non-const iterator
230 using non_const_iterator = iterator_impl<false>;
231 /// @brief The source of an implicit conversion: const iterators can be implicitly
232 /// constructed from non-const iterators
234
235 // parasoft-begin-suppress AUTOSAR-A7_1_1-a "Declaring 'iter' as reference to const changes semantics"
236 // parasoft-begin-suppress AUTOSAR-M7_1_2-c "Declaring 'iter' as reference to const changes semantics"
237 // parasoft-begin-suppress AUTOSAR-A8_4_9-a "Declaring 'iter' as reference to const changes semantics"
238
239 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "Use of a friend function with
240 // passkey improves encapsulation. It allows data members to remain private
241 // and does not unnecessarily expose a public member function."
242
243 // parasoft-begin-suppress AUTOSAR-A0_1_3-a "False positive: Function is namespace scope and used in other
244 // translation units"
245
246 /// @brief basis function for increment
247 /// @param iter iterator to increment
248 ///
249 friend auto step_forward(detail::iterator_interface_tag, iterator_impl& iter) noexcept -> void { ++iter.pos_; }
250
251 /// @brief basis function for decrement
252 /// @param iter iterator to increment
253 ///
254 friend auto step_backward(detail::iterator_interface_tag, iterator_impl& iter) noexcept -> void { --iter.pos_; }
255
256 // parasoft-end-suppress AUTOSAR-A11_3_1-a
257 // parasoft-end-suppress AUTOSAR-A0_1_3-a
258 // parasoft-end-suppress AUTOSAR-A7_1_1-a
259 // parasoft-end-suppress AUTOSAR-M7_1_2-c
260 // parasoft-end-suppress AUTOSAR-A8_4_9-a
261
262 public:
263 /// @brief Default construct an iterator that does not refer to any map element
264 iterator_impl() noexcept
265 : map_(nullptr),
266 pos_(0) {}
267
268 /// @brief Default copy constructor
269 /// @param other The source
270 iterator_impl(iterator_impl const& other) = default;
271 /// @brief Default move constructor
272 /// @param other The source
273 iterator_impl(iterator_impl&& other) = default;
274 /// @brief Default copy assignment
275 /// @param other The source
276 auto operator=(iterator_impl const& other) -> iterator_impl& = default;
277 /// @brief Default move assignment
278 /// @param other The source
279 auto operator=(iterator_impl&& other) -> iterator_impl& = default;
280
281 /// @brief Default destructor
282 ~iterator_impl() = default;
283
284 /// @brief Construct an iterator from a map and a position; only callable from @c
285 /// inline_map members.
286 /// @param map The map
287 /// @param pos The position
288 iterator_impl(inline_map_passkey, map_type* map, index_type pos) noexcept
289 : iterator_interface{},
290 map_(map),
291 pos_(pos) {}
292
293 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
294 // initialize the base class"
295 /// @brief Implicitly convert from a non-const iterator, if this
296 /// is a const iterator.
297 /// @param other The source iterator
298 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
299 iterator_impl(implicit_conversion_type other) noexcept
300 : iterator_impl(
301 inline_map_passkey{},
302 other.get_map(inline_map_passkey{}),
303 other.get_index(inline_map_passkey{})
304 ) {}
305 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
306
307 /// @brief The iterator category
308 using iterator_category = std::bidirectional_iterator_tag;
309 /// @brief The iterator value type
310 using value_type = std::pair<Key const, Value>;
311 /// @brief The iterator difference type
312 using difference_type = std::ptrdiff_t;
313 /// @brief The pointer type
315 /// @brief The reference type
317
318 /// @brief The associated @c inline_map type
319 using inline_map_type = inline_map;
320
321 // parasoft-begin-suppress AUTOSAR-M9_3_1-a-2 "False positive: It returns a reference to the map element"
322 /// @brief Dereference the iterator
323 /// @return A reference to the referenced element
324 /// @pre The iterator must have been constructed referring to a map, otherwise the behaviour is undefined
325 auto operator*() const noexcept -> reference { return *map_->entry_at_index(pos_); }
326 // parasoft-end-suppress AUTOSAR-M9_3_1-a-2
327
328 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "Hidden friends permitted by A11-3-1 Permit #2 v1.0.0"
329 // parasoft-begin-suppress AUTOSAR-A0_1_3-a "False positive: Function is namespace scope and used in other
330 // translation units"
331
332 /// @brief equality
333 /// @param lhs The first iterator to compare
334 /// @param rhs The second iterator to compare
335 /// @return @c true if @c lhs is equal to @c rhs, otherwise @c false
336 /// @pre The iterators must refer to the same map, otherwise the result is meaningless
337 friend auto operator==(iterator_impl const& lhs, iterator_impl const& rhs) noexcept -> bool {
338 return lhs.pos_ == rhs.pos_;
339 }
340
341 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
342 // parasoft-end-suppress AUTOSAR-A0_1_3-a
343
344 /// @brief Check if this is an iterator for a given map.
345 /// @param map A pointer to the map we are looking for
346 /// @return true If @c this was produced from @c map
347 /// @return false Otherwise.
348 auto is_iterator_for(map_type* map) const noexcept -> bool { return map == map_; }
349
350 /// @brief Get the map this iterator references. Can only be called by members of
351 /// @c inline_map
352 /// @return A pointer to the referenced map
353 auto get_map(inline_map_passkey) const noexcept -> map_type* { return map_; }
354
355 /// @brief Get the position this iterator references within a map. Can only be
356 /// called by members of @c inline_map
357 /// @return The index position of the referenced element
358 auto get_index(inline_map_passkey) const noexcept -> index_type { return pos_; }
359 };
360
361 public:
362 /// @brief The value type of the map
363 using value_type = typename map_base_type::value_type;
364 /// @brief The key type of the map
365 using key_type = typename map_base_type::key_type;
366 /// @brief The mapped type of the map
367 using mapped_type = typename map_base_type::mapped_type;
368 /// @brief The comparator of the map
369 using key_compare = typename map_base_type::compare_type;
370 /// @brief The size type of the map
371 using size_type = typename map_base_type::size_type;
372 /// @brief The type of a pointer to the value type of the map
374 /// @brief The type of a @c const pointer to the value type of the map
375 using const_pointer = value_type const*;
376 /// @brief The type of a reference to the value type of the map
378 /// @brief The type of a @c const reference to the value type of the map
380
381 /// @brief The type of an iterator that provides non- @c const access to the elements
382 using iterator = iterator_impl<false>;
383 /// @brief The type of an iterator that provides @c const access to the elements
384 using const_iterator = iterator_impl<true>;
385
386 /// @brief The type of an iterator that provides non- @c const access to the elements
387 /// and iterates in reverse through the elements
389 /// @brief The type of an iterator that provides @c const access to the elements
390 /// and iterates in reverse through the elements
392
393 /// @brief The difference type of the map
394 using difference_type = typename iterator::difference_type;
395
396 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property"
397 /// @brief map capacity
399 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
400
401 /// @brief @c inline_map_base type
402 using inline_map_base_type = map_base_type;
403
404 private:
405 /// @brief A type for the source of the copy-assignment operator: if the comparator
406 /// is copy assignable and the values are copy-constructible, then this the
407 /// map is copy-assignable, so this is @c inline_map, otherwise it is @c
408 /// non_constructible_dummy so the copy-assignment operator is deleted.
409 using copy_assign_source = conditional_t<
413
414 /// @brief A type to use for a deleted assignment operator: if the map should not be
415 /// copy-assignable, this is @c inline_map, otherwise @c
416 /// non_constructible_dummy
417 using dummy_copy_assign_source = conditional_t<
421
422 /// @brief A type for the source of the move-assignment operator: if the comparator
423 /// is move assignable and the values are move-constructible, then this the
424 /// map is move-assignable, so this is @c inline_map, otherwise it is @c
425 /// non_constructible_dummy so the move-assignment operator is deleted.
426 using move_assign_source = conditional_t<
430 /// @brief A type to use for a deleted assignment operator: if the map should not be
431 /// move-assignable, this is @c inline_map, otherwise @c
432 /// non_constructible_dummy
433 using dummy_move_assign_source = conditional_t<
437
438 /// @brief A type for the source of the move constructor: if the comparator
439 /// is move constructible and the values are move-constructible, then this the
440 /// map is move-constructible, so this is @c inline_map, otherwise it is @c
441 /// non_constructible_dummy so the move constructor is deleted.
442 using move_construct_source = conditional_t<
446
447 public:
448 /// @brief Construct an empty map with a default-constructed comparator
449 /// @tparam C The comparator type of the map, used for constraints
450 /// @throws Any exception thrown by the default constructor of the comparator,
451 /// @return optional<inline_map> holding a default-constructed map
452 template <typename C = Compare, constraints<std::enable_if_t<std::is_default_constructible<C>::value>> = nullptr>
453 ARENE_NODISCARD static auto try_construct() noexcept(std::is_nothrow_default_constructible<Compare>::value)
454 -> optional<inline_map> {
455 return optional<inline_map>{in_place};
456 }
457
458 /// @brief Construct a map with a comparator copied from the supplied value
459 /// @tparam C The comparator type of the map, used so this function is not viable if @c Compare cannot be copy
460 /// constructed.
461 /// @param comparator A comparator instance to copy
462 /// @throws Any exception thrown by the copy constructor of the comparator
463 /// @return optional<inline_map> holding a map constructed from the comparator
464 template <typename C = Compare, constraints<std::enable_if_t<std::is_copy_constructible<C>::value>> = nullptr>
465 ARENE_NODISCARD static auto try_construct(Compare const& comparator
467 return optional<inline_map>{in_place, comparator};
468 }
469
470 /// @brief Copy construct a map
471 /// @tparam V The value type of the map, used for constraints
472 /// @tparam C The comparator type of the map, used for constraints
473 /// @param other The source container
474 /// @throws Any exception thrown by the copy constructor of the comparator, or the values
475 /// @return optional<inline_map> holding a copy-constructed map
476 template <
477 typename V = value_type,
478 typename C = Compare,
487
488 /// @brief Copy construct a map with a different size
489 /// @tparam OtherCapacity The capacity of the other map
490 /// @tparam V The value_type
491 /// @tparam C The comparator type
492 /// @param other The source map
493 /// @throws Any exception thrown by the copy constructors of the comparator, keys or values
494 /// @return optional<inline_map> holding the copied map, or @c nullopt if there were too many elements
495 template <
496 std::size_t OtherCapacity,
497 typename V = value_type,
498 typename C = Compare,
506 if (other.size() > Capacity) {
507 return {};
508 }
509 return optional<inline_map>{in_place, other};
510 }
511
512 /// @brief Move construct a map
513 /// @tparam K The key type
514 /// @tparam V The value type
515 /// @tparam C The comparator type of the map, used for constraints
516 /// @param other The source container
517 /// @throws Any exception thrown by the move constructor of the comparator, or the values
518 /// @return optional<inline_map> holding a move-constructed map
519 template <
520 typename K = Key,
521 typename V = Value,
522 typename C = Compare,
533
534 /// @brief Move construct a map with a different size
535 /// @tparam OtherCapacity The capacity of the other map
536 /// @tparam K The key type
537 /// @tparam V The value type
538 /// @tparam C The comparator type
539 /// @param other The source map
540 /// @throws Any exception thrown by the copy constructor of the comparator, or the move constructor of the keys or
541 /// values
542 /// @return optional<inline_map> holding the copied map, or @c nullopt if there were too many elements
543 template <
544 std::size_t OtherCapacity,
545 typename K = Key,
546 typename V = Value,
547 typename C = Compare,
562
563 /// @brief Construct a map with a default-constructed comparator and copies of the elements from the provided
564 /// initializer list. If there are too many elements, return an empty @c optional
565 /// @tparam T The value type of the map, used so this function is not viable if @c value_type cannot be copy
566 /// constructed.
567 /// @tparam C The comparator type of the map, used so this function is not viable if @c Compare cannot be default
568 /// constructed.
569 /// @param init_list The initializer list
570 /// @throws Any exception thrown by the default constructor of the comparator,
571 /// the copy constructor of the keys or values, or the comparisons
572 /// @return optional<inline_map> holding a map constructed with the elements from the initializer list, or @c
573 /// nullopt if there were too many elements.
574 template <
575 typename T = value_type,
576 typename C = Compare,
581 std::is_nothrow_default_constructible<Compare>::value && comparison_is_noexcept<> &&
584 optional<inline_map> res{in_place};
585 if (!res->insert_elements_if_they_fit(init_list)) {
586 res.reset();
587 }
588 return res;
589 }
590
591 /// @brief Construct a map with a comparator copied from the supplied value and copies of the elements from the
592 /// provided initializer list. If there are too many elements, return an empty @c optional
593 /// @tparam T The value type of the map, used so this function is not viable if @c value_type cannot be copy
594 /// constructed.
595 /// @tparam C The comparator type of the map, used so this function is not viable if @c Compare cannot be default
596 /// constructed.
597 /// @param init_list The initializer list
598 /// @param comparator A comparator instance to copy
599 /// @throws Any exception thrown by the copy constructor of the comparator,
600 /// the copy constructor of the keys or values, or the comparisons
601 /// @return optional<inline_map> holding a map constructed with the elements from the initializer list, or @c
602 /// nullopt if there were too many elements.
603 template <
604 typename T = value_type,
605 typename C = Compare,
609 ARENE_NODISCARD static auto
610 try_construct(std::initializer_list<value_type> init_list, Compare const& comparator) noexcept(
611 std::is_nothrow_copy_constructible<Compare>::value && comparison_is_noexcept<> &&
614 optional<inline_map> res{in_place, comparator};
615 if (!res->insert_elements_if_they_fit(init_list)) {
616 res.reset();
617 }
618 return res;
619 }
620
621 /// @brief Construct the map with a default-constructed comparator and no elements
622 /// @throws Any exception thrown by the default constructor of the comparator
623 inline_map() = default;
624
625 /// @brief Default destructor
626 ~inline_map() = default;
627
628 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
629 // initialize the base class"
630 /// @brief Construct the map with a default-constructed comparator and copies of the elements from the provided
631 /// initializer list
632 /// @tparam T The value type of the map, used so this constructor is not viable if @c value_type cannot be copy
633 /// constructed.
634 /// @tparam C The comparator type of the map, used so this constructor is not viable if @c Compare cannot be default
635 /// constructed.
636 /// @param init_list The initializer list
637 /// @throws Any exception thrown by the default constructor of the comparator,
638 /// the copy constructor of the keys or values, or the comparisons
639 /// @pre There are no more than @c Capacity elements in @c init_list with unique keys, else @c ARENE_PRECONDITION
640 /// violation.
641 template <
642 typename T = value_type,
643 typename C = Compare,
648 : inline_map() {
649 for (auto const& element : init_list) {
650 std::ignore = try_emplace(element.first, element.second);
651 }
652 }
653 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
654
655 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
656 // initialize the base class"
657 /// @brief Construct the map with a copy of the specified comparator and copies of
658 /// the elements from the provided initializer list
659 /// @tparam T The value type of the map, used so this constructor is not
660 /// viable if @c value_type cannot be copy constructed.
661 /// @tparam C The comparator type of the map, used so this constructor is not
662 /// viable if @c Compare cannot be copy constructed.
663 /// @param init_list The initializer list
664 /// @param compare The comparator to copy
665 /// @throws Any exception thrown by the copy-constructor of the comparator,
666 /// the copy constructor of the keys or values, or the comparisons
667 /// @pre There are no more than @c Capacity elements in @c init_list with unique keys, else @c ARENE_PRECONDITION
668 /// violation.
669 template <
670 typename T = Value,
671 typename C = Compare,
675 inline_map(std::initializer_list<value_type> init_list, Compare const& compare)
676 : inline_map(compare) {
677 for (auto const& element : init_list) {
678 std::ignore = try_emplace(element.first, element.second);
679 }
680 }
681 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
682
683 /// @brief Construct the map with a copy of the specified comparator and no elements.
684 /// @param compare The comparator to copy#
685 /// @throws Any exception thrown by the copy-constructor of the comparator
686 explicit inline_map(Compare const& compare) noexcept(std::is_nothrow_copy_constructible<Compare>::value)
687 : comparator_base{compare},
688 ordering_base{} {}
689
690 /// @brief Copy the source map, so the new map has the same size, comparator and
691 /// elements as the source.
692 /// @param other The instance to be copied.
693 /// @throws Any exception thrown by the copy constructor of the comparator,
694 /// the keys, or values
695 inline_map(inline_map const& other) = default;
696
697 // parasoft-begin-suppress AUTOSAR-A15_5_1-b-2 "False positive: Conditionally noxecept"
698 /// @brief Move the source map into the new instance, so the new map has the same
699 /// size, comparator and elements as the source did before-hand.
700 ///
701 /// All the keys from the source map are copy-constructed, and all
702 /// the mapped values are move-constructed.
703 /// @param other The instance to be copied.
704 /// @throws Any exception thrown by the copy constructor of the comparator or
705 /// the keys, or the move-constructor of the values
706 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
707 inline_map(move_construct_source&& other) noexcept(
710 )
711 : comparator_base(std::move(static_cast<comparator_base&>(other))),
712 ordering_base{},
713 size_(other.size_),
714 indices_(other.indices_),
715 values_(move_values(other, std::make_index_sequence<Capacity>())) {}
716 // parasoft-end-suppress AUTOSAR-A15_5_1-b-2
717
718 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
719 // initialize the base class"
720 /// @brief Copy from a map with a different capacity
721 /// @tparam OtherCapacity The capacity of the other map
722 /// @tparam SfinaeKey Dummy key type for SFINAE
723 /// @tparam SfinaeValue Dummy value type for SFINAE
724 /// @tparam SfinaeCompare Dummy compare type for SFINAE
725 /// @param other The source map
726 /// @throws Any exception thrown by the copy constructors of the comparator, keys or values
727 /// @pre @c other.size()<=Capacity, else @c ARENE_PRECONDITION violation.
728 template <
729 std::size_t OtherCapacity,
730 typename SfinaeKey = Key,
731 typename SfinaeValue = Value,
732 typename SfinaeCompare = Compare,
738 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
740 : inline_map(other.key_comp()) {
741 ARENE_PRECONDITION(other.size() <= Capacity);
742 for (auto const& element : other) {
743 std::ignore = try_emplace(element.first, element.second);
744 }
745 }
746 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
747
748 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
749 // initialize the base class"
750 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "False positive: Elements are moved"
751 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: Elements are moved"
752 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: Elements are moved"
753 /// @brief Move from a map with a different capacity
754 /// @tparam OtherCapacity The capacity of the other map
755 /// @tparam SfinaeKey Dummy key type for SFINAE
756 /// @tparam SfinaeValue Dummy value type for SFINAE
757 /// @tparam SfinaeCompare Dummy compare type for SFINAE
758 /// @param other The source map
759 /// @throws Any exception thrown by the copy constructors of the comparator or keys or the move constructor of the
760 /// values
761 /// @pre @c other.size()<=Capacity, else @c ARENE_PRECONDITION violation.
762 template <
763 std::size_t OtherCapacity,
764 typename SfinaeKey = Key,
765 typename SfinaeValue = Value,
766 typename SfinaeCompare = Compare,
772 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
774 : inline_map(other.key_comp()) {
775 ARENE_PRECONDITION(other.size() <= Capacity);
776 // parasoft-begin-suppress AUTOSAR-M0_1_3-a-2 "False positive: RAII class"
777 auto const clear_on_exit = clear_on_scope_exit(other);
778 // parasoft-end-suppress AUTOSAR-M0_1_3-a-2
779 for (auto& element : other) {
780 std::ignore = try_emplace(element.first, std::move(element.second));
781 }
782 }
783 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
784 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
785 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
786 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
787
788 /// @brief Deleted copy-assignment if the map should not be copy-assignable
789 auto operator=(dummy_copy_assign_source const&) -> inline_map& = delete;
790
791 /// @brief Deleted move-assignment if the map should not be move-assignable
792 auto operator=(dummy_move_assign_source&&) -> inline_map& = delete;
793
794 /// @brief copy-assignment of a map with the same capacity.
795 ///
796 /// If an exception is thrown then @c *this is left in a valid state containing the subset of elements copied from the
797 /// source prior to the exception being thrown.
798 /// @param other The instance to be copied.
799 /// @return inline_map& A reference to @c *this
800 /// @throws Any exception thrown by the copy assignment of the comparator, or
801 /// the copy constructors of the keys, or values
802 auto operator=(copy_assign_source const& other) noexcept(
805 ) -> inline_map& {
806 if (this != &other) {
807 do_copy(other);
808 }
809 return *this;
810 }
811
812 /// @brief copy-assignment of a map with a greater capacity.
813 ///
814 /// If an exception is thrown then @c *this is left in a valid state containing the subset of elements copied from the
815 /// source prior to the exception being thrown.
816 /// @tparam OtherCapacity The capacity of the other map
817 /// @tparam SfinaeCompare Dummy key type for SFINAE
818 /// @tparam SfinaeValue Dummy value type for SFINAE
819 /// @tparam SfinaeCompare Dummy compare type for SFINAE
820 /// @param other The instance to be copied.
821 /// @return inline_map& A reference to @c *this
822 /// @throws Any exception thrown by the copy assignment of the comparator, or
823 /// the copy constructors of the keys, or values.
824 /// @pre @c other.size()<=Capacity, else @c ARENE_PRECONDITION violation.
825 template <
826 std::size_t OtherCapacity,
827 typename SfinaeKey = Key,
828 typename SfinaeValue = Value,
829 typename SfinaeCompare = Compare,
831 std::enable_if_t<(OtherCapacity > Capacity)>,
836 ARENE_PRECONDITION(other.size() <= Capacity);
837 do_copy(other);
838 return *this;
839 }
840
841 /// @brief copy-assignment of a map with a smaller capacity.
842 ///
843 /// If an exception is thrown then @c *this is left in a valid state containing the subset of elements copied from the
844 /// source prior to the exception being thrown.
845 /// @tparam OtherCapacity The capacity of the other map
846 /// @tparam SfinaeKey Dummy key type for SFINAE
847 /// @tparam SfinaeValue Dummy value type for SFINAE
848 /// @tparam SfinaeCompare Dummy comparator type for SFINAE
849 /// @param other The instance to be copied.
850 /// @return inline_map& A reference to @c *this
851 /// @throws Any exception thrown by the copy assignment of the comparator, or the copy constructors of the keys, or
852 /// values
853 template <
854 std::size_t OtherCapacity,
855 typename SfinaeKey = Key,
856 typename SfinaeValue = Value,
857 typename SfinaeCompare = Compare,
859 std::enable_if_t<(OtherCapacity < Capacity)>,
864 do_copy(other);
865 return *this;
866 }
867
868 // parasoft-begin-suppress AUTOSAR-A15_5_1-b-2 "False positive: Conditionally noxecept"
869 /// @brief Move-assignment of a map with the same capacity.
870 ///
871 /// All the keys from the source map are copy-constructed, and all the mapped values are move-constructed. The source
872 /// map is cleared, so all elements are destroyed and this size is zero. If an exception is thrown then @c *this is
873 /// left in a valid state containing the subset of elements moved from the source prior to the exception being thrown,
874 /// and the source is left empty.
875 /// @param other The instance to be moved.
876 /// @return inline_map& A reference to @c *this
877 /// @throws Any exception thrown by the move-assignment of the comparator or the copy-constructor of the keys, or the
878 /// move-constructor of the values
879 auto operator=(move_assign_source&& other
881 -> inline_map& {
882 if (this != &other) {
883 do_move(std::move(other));
884 }
885 return *this;
886 }
887 // parasoft-end-suppress AUTOSAR-A15_5_1-b-2
888
889 // parasoft-begin-suppress AUTOSAR-A0_1_4-a "False positive: parameter 'other' is used"
890
891 /// @brief Move-assignment of a map with a greater capacity.
892 ///
893 /// All the keys from the source map are copy-constructed, and all the mapped values are move-constructed. The source
894 /// map is cleared, so all elements are destroyed and this size is zero. If an exception is thrown then @c *this is
895 /// left in a valid state containing the subset of elements moved from the source prior to the exception being thrown,
896 /// and the source is left empty.
897 /// @tparam OtherCapacity The capacity of the other map
898 /// @tparam SfinaeKey Dummy key type for SFINAE
899 /// @tparam SfinaeValue Dummy value type for SFINAE
900 /// @tparam SfinaeCompare Dummy comparator type for SFINAE
901 /// @param other The instance to be moved.
902 /// @return inline_map& A reference to @c *this
903 /// @pre @c other.size()<=Capacity, else @c ARENE_PRECONDITION violation.
904 /// @throws Any exception thrown by the move-assignment of the comparator or the copy-constructor of the keys, or the
905 /// move-constructor of the values
906 template <
907 std::size_t OtherCapacity,
908 typename SfinaeKey = Key,
909 typename SfinaeValue = Value,
910 typename SfinaeCompare = Compare,
912 std::enable_if_t<(OtherCapacity > Capacity)>,
917 ARENE_PRECONDITION(other.size() <= Capacity);
918 do_move(std::move(other));
919 return *this;
920 }
921
922 // parasoft-end-suppress AUTOSAR-A0_1_4-a
923
924 /// @brief Move-assignment of a map with a lesser capacity.
925 ///
926 /// All the keys from the source map are copy-constructed, and all the mapped values are move-constructed. The source
927 /// map is cleared, so all elements are destroyed and this size is zero. If an exception is thrown then @c *this is
928 /// left in a valid state containing the subset of elements moved from the source prior to the exception being thrown,
929 /// and the source is left empty.
930 /// @tparam OtherCapacity The capacity of the other map
931 /// @tparam SfinaeKey Dummy key type for SFINAE
932 /// @tparam SfinaeValue Dummy value type for SFINAE
933 /// @tparam SfinaeCompare Dummy comparator type for SFINAE
934 /// @param other The instance to be moved.
935 /// @return inline_map& A reference to @c *this
936 /// @throws Any exception thrown by the move-assignment of the comparator or the copy-constructor of the keys, or the
937 /// move-constructor of the values
938 template <
939 std::size_t OtherCapacity,
940 typename SfinaeKey = Key,
941 typename SfinaeValue = Value,
942 typename SfinaeCompare = Compare,
944 std::enable_if_t<(OtherCapacity < Capacity)>,
949 do_move(std::move(other));
950 return *this;
951 }
952
953 /// @brief Obtain a copy of the comparator
954 /// @return The comparator
955 /// @throws Any exception thrown by the copy-constructor of the comparator
956 ARENE_NODISCARD auto key_comp() const noexcept(std::is_nothrow_copy_constructible<Compare>::value) -> Compare {
957 return comparator_base::get_comparator();
958 }
959
960 /// @brief Check if the map is empty
961 /// @return @c true if the map is empty, @c false otherwise
962 ARENE_NODISCARD auto empty() const noexcept -> bool { return size_ == 0U; }
963 /// @brief Get the number of elements in the map
964 /// @return The number of elements
965 ARENE_NODISCARD auto size() const noexcept -> size_type { return size_; }
966 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
967 /// @brief Get the maximum number of elements in the map, @c Capacity
969 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
970
971 /// @brief Obtain an iterator referring to the element equivalent to the supplied key, if there is one.
972 ///
973 /// @param key The key to find
974 /// @return iterator to the equivalent element, or @c end() if the element is not found
975 auto find(Key const& key) noexcept(comparison_is_noexcept<>) -> iterator { return do_find(*this, key); }
976 /// @brief Obtain an iterator referring to the element equivalent to the supplied key, if there is one.
977 ///
978 /// @param key The key to find
979 /// @return const_iterator to the equivalent element, or @c end() if the element is not found
980 auto find(Key const& key) const noexcept(comparison_is_noexcept<>) -> const_iterator { return do_find(*this, key); }
981 /// @brief Obtain an iterator referring to the element equivalent to the supplied key, if there is one.
982 ///
983 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
984 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
985 /// @param key The key to find
986 /// @return iterator to the equivalent element, or @c end() if the element is not found
987 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported<OtherKey>>> = nullptr>
988 auto find(OtherKey const& key) noexcept(comparison_is_noexcept<OtherKey>) -> iterator {
989 static_assert(
990 transparent_comparison_supported_for<OtherKey>,
991 "Compare must provide a valid comparison for (const Key&, const K&)"
992 );
993 return do_find(*this, key);
994 }
995 /// @brief Obtain an iterator referring to the element equivalent to the supplied key, if there is one.
996 ///
997 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
998 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
999 /// @param key The key to find
1000 /// @return const_iterator to the equivalent element, or @c end() if the element is not found
1001 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported<OtherKey>>> = nullptr>
1002 auto find(OtherKey const& key) const noexcept(comparison_is_noexcept<OtherKey>) -> const_iterator {
1003 static_assert(
1004 transparent_comparison_supported_for<OtherKey>,
1005 "Compare must provide a valid comparison for (const Key&, const K&)"
1006 );
1007 return do_find(*this, key);
1008 }
1009
1010 /// @brief Check if the set contains a specific key
1011 ///
1012 /// @param key The key to search for
1013 /// @return true if @c find(key)!=end() .
1014 /// @return false if @c find(key)==end() .
1015 auto contains(Key const& key) const noexcept(comparison_is_noexcept<>) -> bool { return do_contains(key); }
1016 /// @brief Check if the set contains a key equivalent to a specific value.
1017 ///
1018 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
1019 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
1020 /// @param key The key to search for
1021 /// @return true if @c find(key)!=end() .
1022 /// @return false if @c find(key)==end() .
1023 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported<OtherKey>>> = nullptr>
1024 auto contains(OtherKey const& key) const noexcept(comparison_is_noexcept<OtherKey>) -> bool {
1025 static_assert(
1026 transparent_comparison_supported_for<OtherKey>,
1027 "Compare must provide a valid comparison for (const Key&, const K&)"
1028 );
1029 return do_contains(key);
1030 }
1031
1032 /// @brief Return the number of elements in the map equivalent to a specific key.
1033 ///
1034 /// @param key The key to search for.
1035 /// @return std::size_t @c 0 if the element was not in the map, else @c 1 .
1036 auto count(Key const& key) const noexcept(comparison_is_noexcept<>) -> size_type { return do_count(key); }
1037 /// @brief Return the number of elements in the map equivalent to a specific key.
1038 ///
1039 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
1040 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
1041 /// @param key The key to search for.
1042 /// @return std::size_t @c 0 if the element was not in the map, else @c 1 .
1043 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported<OtherKey>>> = nullptr>
1044 auto count(OtherKey const& key) const noexcept(comparison_is_noexcept<OtherKey>) -> size_type {
1045 static_assert(
1046 transparent_comparison_supported_for<OtherKey>,
1047 "Compare must provide a valid comparison for (const Key&, const K&)"
1048 );
1049 return do_count(key);
1050 }
1051
1052 /// @brief Find the first element which is _not less than_ a given key.
1053 ///
1054 /// @param key The key to find the lower bound for.
1055 /// @return iterator to the first element which is _not less than_ @c key , or @c end() if there is no
1056 /// such element.
1057 auto lower_bound(Key const& key) noexcept(comparison_is_noexcept<>) -> iterator { return do_lower_bound(*this, key); }
1058 /// @brief Find the first element which is _not less than_ a given key.
1059 ///
1060 /// @param key The key to find the lower bound for.
1061 /// @return const_iterator to the first element which is _not less than_ @c key , or @c end() if there is no
1062 /// such element.
1063 auto lower_bound(Key const& key) const noexcept(comparison_is_noexcept<>) -> const_iterator {
1064 return do_lower_bound(*this, key);
1065 }
1066 /// @brief Find the first element which is _not less than_ a given key.
1067 ///
1068 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
1069 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
1070 /// @param key The key to find the lower bound for.
1071 /// @return iterator to the first element which is _not less than_ @c key , or @c end() if there is no such element.
1072 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported<OtherKey>>> = nullptr>
1073 auto lower_bound(OtherKey const& key) noexcept(comparison_is_noexcept<OtherKey>) -> iterator {
1074 static_assert(
1075 transparent_comparison_supported_for<OtherKey>,
1076 "Compare must provide a valid comparison for (const Key&, const K&)"
1077 );
1078 return do_lower_bound(*this, key);
1079 }
1080 /// @brief Find the first element which is _not less than_ a given key.
1081 ///
1082 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
1083 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
1084 /// @param key The key to find the lower bound for.
1085 /// @return const_iterator to the first element which is _not less than_ @c key , or @c end() if there is no such
1086 /// element.
1087 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported<OtherKey>>> = nullptr>
1088 auto lower_bound(OtherKey const& key) const noexcept(comparison_is_noexcept<OtherKey>) -> const_iterator {
1089 static_assert(
1090 transparent_comparison_supported_for<OtherKey>,
1091 "Compare must provide a valid comparison for (const Key&, const K&)"
1092 );
1093 return do_lower_bound(*this, key);
1094 }
1095
1096 /// @brief Find the first element which is _greater than_ a given key.
1097 ///
1098 /// @param key The key to search for.
1099 /// @return iterator to the first element which is _greater than_ @c key , or @c end() if there is no such element.
1100 auto upper_bound(Key const& key) noexcept(comparison_is_noexcept<>) -> iterator { return do_upper_bound(*this, key); }
1101 /// @brief Find the first element which is _greater than_ a given key.
1102 ///
1103 /// @param key The key to search for.
1104 /// @return const_iterator to the first element which is _greater than_ @c key , or @c end() if there is no such
1105 /// element.
1106 auto upper_bound(Key const& key) const noexcept(comparison_is_noexcept<>) -> const_iterator {
1107 return do_upper_bound(*this, key);
1108 }
1109 /// @brief Find the first element which is _greater than_ a given key.
1110 ///
1111 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
1112 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
1113 /// @param key The key to search for.
1114 /// @return iterator to the first element which is _greater than_ @c key , or @c end() if there is no such element.
1115 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported<OtherKey>>> = nullptr>
1116 auto upper_bound(OtherKey const& key) noexcept(comparison_is_noexcept<OtherKey>) -> iterator {
1117 static_assert(
1118 transparent_comparison_supported_for<OtherKey>,
1119 "Compare must provide a valid comparison for (const Key&, const K&)"
1120 );
1121 return do_upper_bound(*this, key);
1122 }
1123 /// @brief Find the first element which is _greater than_ a given key.
1124 ///
1125 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
1126 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
1127 /// @param key The key to search for.
1128 /// @return const_iterator to the first element which is _greater than_ @c key , or @c end() if there is no such
1129 /// element.
1130 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported<OtherKey>>> = nullptr>
1131 auto upper_bound(OtherKey const& key) const noexcept(comparison_is_noexcept<OtherKey>) -> const_iterator {
1132 static_assert(
1133 transparent_comparison_supported_for<OtherKey>,
1134 "Compare must provide a valid comparison for (const Key&, const K&)"
1135 );
1136 return do_upper_bound(*this, key);
1137 }
1138
1139 /// @brief Finds the sequence of elements whose keys compare equivalent to a given key.
1140 ///
1141 /// @param key The key to search for
1142 /// @return std::pair<iterator, iterator> A pair of iterators such that all elements in the range @c [first,second)
1143 /// have keys which compare equal to @c key if there was a key equivalent to @c key in the map. Otherwise both
1144 /// iterators will be @c end() .
1145 auto equal_range(Key const& key) noexcept(comparison_is_noexcept<>) -> std::pair<iterator, iterator> {
1146 return do_equal_range(*this, key);
1147 }
1148 /// @brief Finds the sequence of elements whose keys compare equivalent to a given key.
1149 ///
1150 /// @param key The key to search for
1151 /// @return std::pair<iterator, iterator> A pair of iterators such that all elements in the range @c [first,second)
1152 /// have keys which compare equal to @c key if there was a key equivalent to @c key in the map. Otherwise both
1153 /// iterators will be @c end() .
1154 auto equal_range(Key const& key) const noexcept(comparison_is_noexcept<>)
1155 -> std::pair<const_iterator, const_iterator> {
1156 return do_equal_range(*this, key);
1157 }
1158 /// @brief Finds the sequence of elements whose keys compare equivalent to a given key.
1159 ///
1160 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
1161 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
1162 /// @param key The key to search for
1163 /// @return std::pair<iterator, iterator> A pair of iterators such that all elements in the range @c [first,second)
1164 /// have keys which compare equal to @c key if there was a key equivalent to @c key in the map. Otherwise both
1165 /// iterators will be @c end() .
1166 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported<OtherKey>>> = nullptr>
1167 auto equal_range(OtherKey const& key) noexcept(comparison_is_noexcept<OtherKey>) -> std::pair<iterator, iterator> {
1168 static_assert(
1169 transparent_comparison_supported_for<OtherKey>,
1170 "Compare must provide a valid comparison for (const Key&, const K&)"
1171 );
1172 return do_equal_range(*this, key);
1173 }
1174 /// @brief Finds the sequence of elements whose keys compare equivalent to a given key.
1175 ///
1176 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
1177 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
1178 /// @param key The key to search for
1179 /// @return std::pair<const_iterator, const_iterator> A pair of iterators such that all elements in the range @c
1180 /// [first,second) have keys which compare equal to @c key if there was a key equivalent to @c key in the map.
1181 /// Otherwise both iterators will be @c end() .
1182 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported<OtherKey>>> = nullptr>
1183 auto equal_range(OtherKey const& key) const noexcept(comparison_is_noexcept<OtherKey>)
1184 -> std::pair<const_iterator, const_iterator> {
1185 static_assert(
1186 transparent_comparison_supported_for<OtherKey>,
1187 "Compare must provide a valid comparison for (const Key&, const K&)"
1188 );
1189 return do_equal_range(*this, key);
1190 }
1191
1192 /// @brief Obtain a reference to the mapped value for the specified key
1193 ///
1194 /// @param key The key to obtain the value for
1195 /// @return A reference to the mapped value. If @c key did not exist in the map, then a default constructed @c Value
1196 /// is inserted into the map at @c key and a reference to it is returned.
1197 /// @throws Any exception thrown by the comparisons, and exception throw by the copy-constructor of @c Key, or the
1198 /// default-constructor of @c Value
1199 /// @pre @c size()<Capacity if @c key is not in @c *this
1200 auto operator[](Key const& key) -> Value& { return do_operator_index(key); }
1201 /// @brief Obtain a reference to the mapped value for the specified key
1202 ///
1203 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
1204 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> , and
1205 /// <c>std::is_constructible<Key,const K&></c> .
1206 /// @param key The key to obtain the value for
1207 /// @return A reference to the mapped value. If @c key did not exist in the map, then a default constructed @c Value
1208 /// is inserted into the map at @c key and a reference to it is returned.
1209 /// @throws Any exception thrown by the comparisons, and exception throw by the copy-constructor of @c Key, or the
1210 /// default-constructor of @c Value, or
1211 /// @pre @c size()<Capacity if @c key is not in @c *this
1212 template <
1213 typename OtherKey,
1217 auto operator[](OtherKey const& key) -> Value& {
1218 static_assert(
1219 transparent_comparison_supported_for<OtherKey>,
1220 "Compare must provide a valid comparison for (const Key&, const K&)"
1221 );
1222 return do_operator_index(key);
1223 }
1224
1225 /// @brief Obtain a reference to the mapped value for the specified key or throw.
1226 ///
1227 /// @param key The key to obtain the value for
1228 /// @return Value& A reference to the mapped value
1229 /// @throws std::out_of_range if @c find(key)==end() .
1230 /// @throws Any exception thrown by the comparisons
1231 template <
1232 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
1234 ARENE_NODISCARD auto at(Key const& key) -> Value& {
1235 return do_at(*this, key);
1236 }
1237 /// @brief Obtain a reference to the mapped value for the specified key or throw.
1238 ///
1239 /// @param key The key to obtain the value for
1240 /// @return Value const& A reference to the mapped value
1241 /// @throws std::out_of_range if @c find(key)==end() .
1242 /// @throws Any exception thrown by the comparisons
1243 template <
1244 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
1246 ARENE_NODISCARD auto at(Key const& key) const -> Value const& {
1247 return do_at(*this, key);
1248 }
1249
1250 /// @brief Obtain a reference to the mapped value for the specified key or throw.
1251 ///
1252 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
1253 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
1254 /// @param key The key to obtain the value for
1255 /// @return Value& A reference to the mapped value
1256 /// @throws std::out_of_range if @c find(key)==end() .
1257 /// @throws Any exception thrown by the comparisons
1258 template <
1259 typename OtherKey,
1260 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
1264 ARENE_NODISCARD auto at(OtherKey const& key) -> Value& {
1265 static_assert(
1266 transparent_comparison_supported_for<OtherKey>,
1267 "Compare must provide a valid comparison for (const Key&, const K&)"
1268 );
1269 return do_at(*this, key);
1270 }
1271 /// @brief Obtain a reference to the mapped value for the specified key or throw.
1272 ///
1273 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
1274 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
1275 /// @param key The key to obtain the value for
1276 /// @return Value& A reference to the mapped value
1277 /// @throws std::out_of_range if @c find(key)==end() .
1278 /// @throws Any exception thrown by the comparisons
1279 template <
1280 typename OtherKey,
1281 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
1285 ARENE_NODISCARD auto at(OtherKey const& key) const -> Value const& {
1286 static_assert(
1287 transparent_comparison_supported_for<OtherKey>,
1288 "Compare must provide a valid comparison for (const Key&, const K&)"
1289 );
1290 return do_at(*this, key);
1291 }
1292
1293 // parasoft-begin-suppress AUTOSAR-A13_3_1-a-2 "Constrained via SFINAE, permitted by A13-3-1 Permit #1"
1294 /// @brief Insert a new element in the map if there is not already one with the corresponding key.
1295 ///
1296 /// Copy constructs the provided value into the new element if an appropriate element does not already exist.
1297 /// @tparam SfinaeKey Dummy key type for SFINAE.
1298 /// @tparam SfinaeValue Dummy value type for SFINAE.
1299 /// @param value The value to insert
1300 /// @return std::pair<iterator, bool> whose first element is the key equivalent to @c v.first, and whose second
1301 /// element is a boolean with a value of @c true if the element was inserted, or @c false otherwise.
1302 /// @pre @c contains(value.first) is @c true, or @c size()<Capacity, else @c ARENE_PRECONDITION violation.
1303 /// @throws Any exception thrown by the comparisons, or the copy constructor of @c value_type
1304 template <
1305 typename SfinaeKey = Key,
1306 typename SfinaeValue = Value,
1310 auto insert(value_type const& value) -> std::pair<iterator, bool> {
1311 return try_emplace(value.first, value.second);
1312 }
1313 // parasoft-end-suppress AUTOSAR-A13_3_1-a-2
1314
1315 /// @brief Insert a new element in the map if there is not already one with the corresponding key.
1316 ///
1317 /// If an element does not already exist with the given key, the key is copy-constructed into the map while the value
1318 /// is move-constructed.
1319 /// @tparam SfinaeKey Dummy key type for SFINAE.
1320 /// @tparam SfinaeValue Dummy value type for SFINAE.
1321 /// @param value The value to insert
1322 /// @return std::pair<iterator, bool> whose first element is the key equivalent to @c v.first, and whose second
1323 /// element is a boolean with a value of @c true if the element was inserted, or @c false otherwise.
1324 /// @pre @c contains(value.first) is @c true, or @c size()<Capacity, else @c ARENE_PRECONDITION violation.
1325 /// @throws Any exception thrown by the comparisons, or the copy constructor of @c value_type
1326 template <
1327 typename SfinaeKey = Key,
1328 typename SfinaeValue = Value,
1332 auto insert(value_type&& value) -> std::pair<iterator, bool> {
1333 return try_emplace(value.first, std::move(value.second));
1334 }
1335
1336 /// @brief Insert a new element in the map if there is not already one with the corresponding key.
1337 ///
1338 /// If an element does not already exist with the given key, the key is copy-constructed into the map while the value
1339 /// is move-constructed.
1340 /// @tparam P The type of the provided initializer
1341 /// @param value The value to insert
1342 /// @return std::pair<iterator, bool> whose first element is the key equivalent to @c v.first, and whose second
1343 /// element is a boolean with a value of @c true if the element was inserted, or @c false otherwise.
1344 /// @pre @c contains(value.first) is @c true, or @c size()<Capacity, else @c ARENE_PRECONDITION violation.
1345 /// @throws Any exception thrown by the comparisons, or the copy constructor of @c value_type
1346 template <
1347 typename P,
1351 auto insert(P&& value) -> std::pair<iterator, bool> {
1352 return emplace(std::forward<P>(value));
1353 }
1354
1355 /// @brief Insert a new element in the map if there is not already one with the corresponding key, otherwise assigns
1356 /// the new value to the existing one.
1357 ///
1358 /// Perfectly forwards the provided key and value into the constructor of the new element if an appropriate element
1359 /// does not already exist; perfectly forwards into the assignment operator for the existing element if there is one.
1360 /// @tparam OtherMapped The type of the initializer for the mapped type
1361 /// @tparam SfinaeKey The key type, used to delete this overload if the key is not copy constructible
1362 /// @param key The key for which to insert or assign an element
1363 /// @param mapped_value The value with which to construct or assign the mapped value
1364 /// @return A pair of an iterator to the element with a key equivalent to @c key, and a boolean with a value of
1365 /// @c true if the element was inserted, or @c false otherwise.
1366 /// @pre @c contains(key) is @c true, or @c size()<Capacity, else @c ARENE_PRECONDITION violation.
1367 /// @throws Any exception thrown by the comparisons, the move constructor of @c Key or the constructor or assignment
1368 /// operator of @c Value .
1369 template <
1370 typename OtherMapped,
1371 typename SfinaeKey = Key,
1376 auto insert_or_assign(Key const& key, OtherMapped&& mapped_value) -> std::pair<iterator, bool> {
1377 return do_insert_or_assign(key, std::forward<OtherMapped>(mapped_value));
1378 }
1379 /// @brief Insert a new element in the map if there is not already one with the corresponding key, otherwise assigns
1380 /// the new value to the existing one.
1381 ///
1382 /// Perfectly forwards the provided key and value into the constructor of the new element if an appropriate element
1383 /// does not already exist; perfectly forwards into the assignment operator for the existing element if there is one.
1384 /// @tparam OtherMapped The type of the initializer for the mapped type
1385 /// @tparam SfinaeKey The key type, used to delete this overload if the key is not move constructible
1386 /// @param key The key for which to insert or assign an element
1387 /// @param mapped_value The value with which to construct or assign the mapped value
1388 /// @return A pair of an iterator to the element with a key equivalent to @c key, and a boolean with a value of
1389 /// @c true if the element was inserted, or @c false otherwise.
1390 /// @pre @c contains(key) is @c true, or @c size()<Capacity, else @c ARENE_PRECONDITION violation.
1391 /// @throws Any exception thrown by the comparisons, the move constructor of @c Key or the constructor or assignment
1392 /// operator of @c Value .
1393 template <
1394 typename OtherMapped,
1395 typename SfinaeKey = Key,
1400 auto insert_or_assign(Key&& key, OtherMapped&& mapped_value) -> std::pair<iterator, bool> {
1401 return do_insert_or_assign(std::move(key), std::forward<OtherMapped>(mapped_value));
1402 }
1403 /// @brief Insert a new element in the map if there is not already one with an equivalent key, otherwise assigns the
1404 /// new value to the existing one.
1405 ///
1406 /// Perfectly forwards the provided key and value into the constructor of the new element if an appropriate element
1407 /// does not already exist; perfectly forwards into the assignment operator for the existing element if there is one.
1408 /// @tparam OtherKey The key type. Must satisfy <c>decays_to_v<K, Key> || transparent_comparison_supported<K></c> and
1409 /// <c>std::is_constructible<Key, K&&></c>
1410 /// @tparam OtherMapped The type of the initializer for the mapped type
1411 /// @param key The key for which to insert or assign an element
1412 /// @param mapped_value The value with which to construct or assign the mapped value
1413 /// @return A pair of an iterator to the element with a key equivalent to @c key, and a boolean with a value of
1414 /// @c true if the element was inserted, or @c false otherwise.
1415 /// @pre @c contains(key) is @c true, or @c size()<Capacity, else @c ARENE_PRECONDITION violation.
1416 /// @throws Any exception thrown by the comparisons, the move constructor of @c Key or the constructor or assignment
1417 /// operator of @c Value .
1418 template <
1419 typename OtherKey,
1420 typename OtherMapped,
1426 auto insert_or_assign(OtherKey&& key, OtherMapped&& mapped_value) -> std::pair<iterator, bool> {
1427 static_assert(
1428 transparent_comparison_supported_for<OtherKey>,
1429 "Compare must provide a valid comparison for (const Key&, const K&)"
1430 );
1431 return do_insert_or_assign(std::forward<OtherKey>(key), std::forward<OtherMapped>(mapped_value));
1432 }
1433
1434 /// @brief Try to emplace a new element in the map if there is not already one with the corresponding key.
1435 ///
1436 /// Perfectly forwards the provided arguments into the constructor of the key and value if an appropriate element does
1437 /// not already exist.
1438 /// @tparam Args The types of the initializers for the mapped type. Must satisfy <c>std::is_constructible<Value,
1439 /// Args&&...></c>.
1440 /// @tparam SfinaeKey The key type, used to delete this overload if the key is not copy/move constructible
1441 /// @param key The key for which to insert or assign an element
1442 /// @param args The values with which to construct the mapped value
1443 /// @return std::pair<iterator, bool> A pair whose second element will be @c true if the emplace happened. The first
1444 /// element will be an iterator pointing to the element corresponding to @c key : the existing element if
1445 /// the insert did not happen, or the new element if it did.
1446 /// @pre @c contains(key) is @c true, or @c size()<Capacity, else @c ARENE_PRECONDITION violation.
1447 /// @throws Any exception thrown by the comparisons or constructors of @c Key and @c Value .
1448 template <
1449 typename... Args,
1450 typename SfinaeKey = Key,
1453 std::enable_if_t<std::is_constructible<Value, Args&&...>::value>> = nullptr>
1454 auto try_emplace(Key const& key, Args&&... args) -> std::pair<iterator, bool> {
1455 return do_try_emplace(key, std::forward<Args>(args)...);
1456 }
1457 /// @brief Try to emplace a new element in the map if there is not already one with the corresponding key.
1458 ///
1459 /// Perfectly forwards the provided arguments into the constructor of the key and value if an appropriate element does
1460 /// not already exist.
1461 /// @tparam Args The types of the initializers for the mapped type. Must satisfy <c>std::is_constructible<Value,
1462 /// Args&&...></c>.
1463 /// @tparam SfinaeKey The key type, used to delete this overload if the key is not copy/move constructible
1464 /// @param key The key for which to insert or assign an element
1465 /// @param args The values with which to construct the mapped value
1466 /// @return std::pair<iterator, bool> A pair whose second element will be @c true if the emplace happened. The first
1467 /// element will be an iterator pointing to the element corresponding to @c key : the existing element if
1468 /// the insert did not happen, or the new element if it did.
1469 /// @pre @c contains(key) is @c true, or @c size()<Capacity, else @c ARENE_PRECONDITION violation.
1470 /// @throws Any exception thrown by the comparisons or constructors of @c Key and @c Value .
1471 template <
1472 typename... Args,
1473 typename SfinaeKey = Key,
1476 std::enable_if_t<std::is_constructible<Value, Args&&...>::value>> = nullptr>
1477 auto try_emplace(Key&& key, Args&&... args) -> std::pair<iterator, bool> {
1478 return do_try_emplace(std::move(key), std::forward<Args>(args)...);
1479 }
1480 /// @brief Try to emplace a new element in the map if there is not already one with an equivalent key.
1481 ///
1482 /// Perfectly forwards the provided arguments into the constructor of the key and value if an appropriate element does
1483 /// not already exist.
1484 /// @tparam Args The types of the initializers for the mapped type. Must satisfy <c>std::is_constructible<Value,
1485 /// Args&&...></c>.
1486 /// @tparam OtherKey The key type. Must satisfy <c>decays_to_v<K, Key> || transparent_comparison_supported<K></c> and
1487 /// <c>std::is_constructible<Key, K&&></c>
1488 /// @param key The key for which to insert or assign an element
1489 /// @param args The values with which to construct the mapped value
1490 /// @return std::pair<iterator, bool> A pair whose second element will be @c true if the emplace happened. The first
1491 /// element will be an iterator pointing to the element corresponding to @c key : the existing element if
1492 /// the insert did not happen, or the new element if it did.
1493 /// @pre @c contains(key) is @c true, or @c size()<Capacity, else @c ARENE_PRECONDITION violation.
1494 /// @throws Any exception thrown by the comparisons or constructors of @c Key and @c Value .
1495 template <
1496 typename OtherKey,
1497 typename... Args,
1502 std::enable_if_t<std::is_constructible<Value, Args&&...>::value>> = nullptr>
1503 auto try_emplace(OtherKey&& key, Args&&... args) -> std::pair<iterator, bool> {
1504 static_assert(
1505 transparent_comparison_supported_for<OtherKey>,
1506 "Compare must provide a valid comparison for (const Key&, const K&)"
1507 );
1508 return do_try_emplace(std::forward<OtherKey>(key), std::forward<Args>(args)...);
1509 }
1510
1511 /// @brief Construct a new @c value_type object and try to insert it in the map if
1512 /// there is not already one with the corresponding key.
1513 ///
1514 /// Perfectly forwards the provided arguments into the constructor
1515 /// of the new element if an appropriate element does not already
1516 /// exist.
1517 /// @tparam Args The types of the initializers for the value type
1518 /// @param args The values with which to construct the value value
1519 /// @return A pair of an iterator to the element with a key equivalent to @c
1520 /// key, and a boolean with a value of @c true if the element was
1521 /// inserted, or @c false otherwise.
1522 /// @throws Any exception thrown by the comparisons, the constructor
1523 /// of @c value_type
1524 /// @pre @c size()<Capacity or there is already a corresponding element in the map, else @c ARENE_PRECONDITION
1525 /// violation.
1526 template <
1527 typename... Args,
1528 constraints<std::enable_if_t<std::is_constructible<value_type, Args&&...>::value>> = nullptr>
1529 auto emplace(Args&&... args) -> std::pair<iterator, bool> {
1530 if (size_ == Capacity) {
1532 auto const existing_element = find(temp.first);
1533 ARENE_PRECONDITION(existing_element != end());
1534 return {existing_element, false};
1535 }
1536 auto const new_index = indices_[size_];
1537 auto& potentially_inserted_element = values_[new_index];
1538 potentially_inserted_element.emplace(std::forward<Args>(args)...);
1539 optional_resetter<value_type> destroy_if_not_inserted{potentially_inserted_element};
1540 auto const pos_info = lower_bound_index(potentially_inserted_element->first);
1541 bool const do_insert{pos_info.order != strong_ordering::equal};
1542 if (do_insert) {
1543 insert_index_at(pos_info.index, new_index);
1544 destroy_if_not_inserted.dismiss();
1545 }
1546 return {make_iterator(*this, pos_info.index), do_insert};
1547 }
1548
1549 /// @brief Erase the element with the corresponding key, if there is one.
1550 ///
1551 /// @param key The key to erase.
1552 /// @return iterator An iterator which points to the position after the removed element.
1553 auto erase(Key const& key) noexcept(comparison_is_noexcept<>) -> iterator { return do_erase(key); }
1554 /// @brief Erase the element with the corresponding key, if there is one.
1555 ///
1556 /// @tparam OtherKey the type of the key to find. Must satisfy @c is_transparent_comparator_for<Compare,Key,K> or
1557 /// @c is_transparent_three_way_comparator_for<Compare,Key,K> .
1558 /// @param key The key to erase.
1559 /// @return iterator An iterator which points to the position after the removed element.
1560 template <typename OtherKey, constraints<std::enable_if_t<transparent_comparison_supported<OtherKey>>> = nullptr>
1561 auto erase(OtherKey const& key) noexcept(comparison_is_noexcept<OtherKey>) -> iterator {
1562 static_assert(
1563 transparent_comparison_supported_for<OtherKey>,
1564 "Compare must provide a valid comparison for (const Key&, const K&)"
1565 );
1566 return do_erase(key);
1567 }
1568
1569 /// @brief Erase the element at the specified position.
1570 /// @param pos An iterator referring to the element to erase
1571 /// @return An iterator referring to the element after the erased element, or
1572 /// @c end() if there is no such element.
1573 /// @pre @c pos must be a valid dereferencable iterator referring to an element in @c *this, else @c
1574 /// ARENE_PRECONDITION violation.
1575 auto erase(iterator pos) noexcept -> iterator {
1576 ARENE_PRECONDITION(pos.is_iterator_for(this));
1577 ARENE_PRECONDITION(pos != end());
1578 return erase_at_index(pos.get_index(inline_map_passkey{}));
1579 }
1580
1581 /// @brief Erase the element at the specified position.
1582 /// @param pos An iterator referring to the element to erase
1583 /// @return An iterator referring to the element after the erased element, or
1584 /// @c end() if there is no such element.
1585 /// @pre @c pos must be a valid dereferencable iterator referring to an element in @c *this, else @c
1586 /// ARENE_PRECONDITION violation.
1587 auto erase(const_iterator pos) noexcept -> iterator {
1588 ARENE_PRECONDITION(pos.is_iterator_for(this));
1589 ARENE_PRECONDITION(pos != end());
1590 return erase_at_index(pos.get_index(inline_map_passkey{}));
1591 }
1592
1593 /// @brief Erase all the elements in the specified iterator range
1594 /// @param first An iterator referring to the start of the range to erase
1595 /// @param last An iterator referring to the end of the range to erase
1596 /// @return An iterator referring to the element after the erased elements,
1597 /// or @c end() if there is no such element.
1598 /// @pre @c [first,last) must be a valid iterator range referring to @c *this, else @c ARENE_PRECONDITION violation.
1599 // NOLINTNEXTLINE(readability-function-cognitive-complexity)
1600 auto erase(const_iterator first, const_iterator last) noexcept -> iterator {
1601 ARENE_PRECONDITION(first.is_iterator_for(this));
1602 ARENE_PRECONDITION(last.is_iterator_for(this));
1604 auto const first_index = first.get_index(inline_map_passkey{});
1605 auto const last_index = last.get_index(inline_map_passkey{});
1606 return erase_index_range(first_index, static_cast<index_type>(last_index - first_index));
1607 }
1608
1609 /// @brief Destroy all elements in @c *this and set the size to zero.
1610 /// @post @c size()==0 .
1611 /// @post The destructors of all elements in the range @c [begin(),end()) will have been called once.
1612 void clear() noexcept {
1613 for (index_type index{0U}; index < size_; ++index) {
1614 entry_at_index(index).reset();
1615 }
1616 size_ = 0U;
1617 }
1618
1619 /// @brief Obtain an iterator referring to the beginning of the sorted range of elements.
1620 /// @return iterator Points to the first element in the sequence, or @c end() if @c empty() .
1621 ARENE_NODISCARD auto begin() noexcept -> iterator { return make_iterator(*this, 0U); }
1622 /// @brief Obtain an iterator referring to the beginning of the sorted range of elements.
1623 /// @return const_iterator Points to the first element in the sequence, or @c end() if @c empty() .
1624 ARENE_NODISCARD auto begin() const noexcept -> const_iterator { return make_iterator(*this, 0U); }
1625 /// @brief Obtain an iterator referring to the beginning of the sorted range of elements.
1626 /// @return const_iterator Points to the first element in the sequence, or @c end() if @c empty() .
1627 ARENE_NODISCARD auto cbegin() const noexcept -> const_iterator { return make_iterator(*this, 0U); }
1628
1629 /// @brief Obtain an iterator referring to one past the last element in the sorted range of elements.
1630 /// @return iterator An iterator pointing to one past the last element in the sequence.
1631 ARENE_NODISCARD auto end() noexcept -> iterator { return make_iterator(*this, size_); }
1632 /// @brief Obtain an iterator referring to one past the last element in the sorted range of elements.
1633 /// @return const_iterator Points to one past the last element in the sequence.
1634 ARENE_NODISCARD auto end() const noexcept -> const_iterator { return make_iterator(*this, size_); }
1635 /// @brief Obtain an iterator referring to one past the last element in the sorted range of elements.
1636 /// @return const_iterator Points to one past the last element in the sequence.
1637 ARENE_NODISCARD auto cend() const noexcept -> const_iterator { return make_iterator(*this, size_); }
1638
1639 /// @brief Obtain an iterator referring to the beginning of a reversed traversal of the sorted range of elements.
1640 /// @return reverse_iterator Points to the last element in the sequence, or @c rend() if @c empty() .
1642 /// @brief Obtain an iterator referring to the beginning of a reversed traversal of the sorted range of elements.
1643 /// @return const_reverse_iterator Points to the last element in the sequence, or @c rend() if @c empty() .
1645 /// @brief Obtain an iterator referring to the beginning of a reversed traversal of the sorted range of elements.
1646 /// @return const_reverse_iterator Points to the last element in the sequence, or @c rend() if @c empty() .
1648
1649 /// @brief Obtain an iterator referring to one past the last element in a reversed traversal of the sorted range of
1650 /// elements.
1651 /// @return reverse_iterator An iterator pointing to one before the first element in the sequence.
1653 /// @brief Obtain an iterator referring to one past the last element in a reversed traversal of the sorted range of
1654 /// elements.
1655 /// @return const_reverse_iterator An iterator pointing to one before the first element in the sequence.
1657 /// @brief Obtain an iterator referring to one past the last element in a reversed traversal of the sorted range of
1658 /// elements.
1659 /// @return const_reverse_iterator An iterator pointing to one before the first element in the sequence.
1661
1662 /// @brief Fast inequality heuristic to shortcut on different sized containers.
1663 ///
1664 /// @tparam OtherCapacity the capacity of @c rhs
1665 /// @param lhs The left-hand operand to the check
1666 /// @param rhs The right-hand operand to the check
1667 /// @return inequality_heuristic::may_be_equal_or_not_equal if @c lhs.size()==rhs.size()
1668 /// @return inequality_heuristic::definitely_not_equal if @c lhs.size()!=rhs.size()
1669 template <size_type OtherCapacity>
1670 ARENE_NODISCARD static auto
1676
1677 /// @brief Compares two maps lexicographically .
1678 ///
1679 /// @note Lexicographic comparison between maps ignores the order of keys as defined by @c Compare . That is, it is
1680 /// a lexicographic comparison between the @c value_type elements of each container, in iteration order, using the
1681 /// standard @c compare_three_way facility. This means that for all possible maps which result in element sequences
1682 /// <c>{{1,"a"}, {2, "b"}, {3,"c"}}</c> and <c>{{1,"a"}, {2, "b"}, {5,"d"}}</c>, when compared against each other
1683 /// the result of the comparison will always be the same, @c strong_ordering::less.
1684 ///
1685 /// @tparam OtherCapacity the capacity of @c rhs
1686 /// @tparam SfinaeKey dummy template parameter to disable the operator if @c key_Type is not three way comparable.
1687 /// @tparam SfinaeMappedType dummy template parameter to disable the operator if @c mapped_type is not three way
1688 /// comparable.
1689 /// @param lhs The left hand operand to the comparison.
1690 /// @param rhs The right hand operand to the comparison.
1691 /// @return strong_ordering Equivalent to
1692 /// @c arene::base::lexicographical_compare_three_way(lhs.begin(),lhs.end(),rhs.begin(),rhs.end())
1693 template <
1694 size_type OtherCapacity,
1695 typename SfinaeKey = key_type,
1696 typename SfinaeMappedType = mapped_type,
1700 ARENE_NODISCARD static auto
1702 -> strong_ordering {
1703 return ::arene::base::lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1704 }
1705
1706 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "False positive: It is allowed to declare comparison operators as
1707 // friend functions"
1708 // parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
1709 /// @brief Compares two maps for equality of _elements_ when @c mapped_value is not three-way-comparable.
1710 ///
1711 ///
1712 /// @tparam OtherCapacity the capacity of @c rhs
1713 /// @tparam SfinaeValue dummy template parameter to disable the operator if @c value_type is not equality comparable.
1714 /// @tparam SfinaeKey dummy template parameter to enable the operator if @c key_type is not three way comparable.
1715 /// @tparam SfinaeMappedType dummy template parameter to enable the operator if @c mapped_type is not three way
1716 /// comparable.
1717 /// @param lhs The left hand operand to the comparison.
1718 /// @param rhs The right hand operand to the comparison.
1719 /// @return bool Equivalent to @c arene::base::equal(lhs.begin(),lhs.end(),rhs.begin(),rhs.end())
1720 template <
1721 size_type OtherCapacity,
1722 typename SfinaeValue = value_type,
1724 ARENE_NODISCARD friend auto
1727 ::arene::base::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1728 }
1729 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
1730 // parasoft-end-suppress AUTOSAR-M3_3_2-a-2
1731
1732 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "False positive: It is allowed to declare comparison operators as
1733 // friend functions"
1734 // parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
1735 /// @brief Compares two maps for inequality of _elements_ when @c mapped_value is not three-way-comparable.
1736 ///
1737 /// @tparam OtherCapacity the capacity of @c rhs
1738 /// @tparam SfinaeValue dummy template parameter to disable the operator if @c value_type is not equality comparable.
1739 /// @tparam SfinaeKey dummy template parameter to enable the operator if @c key_Type is not three way comparable.
1740 /// @tparam SfinaeMappedType dummy template parameter to enable the operator if @c mapped_type is not three way
1741 /// comparable.
1742 /// @param lhs The left hand operand to the comparison.
1743 /// @param rhs The right hand operand to the comparison.
1744 /// @return bool Equivalent to @c !arene::base::equal(lhs.begin(),lhs.end(),rhs.begin(),rhs.end())
1745 template <
1746 size_type OtherCapacity,
1747 typename SfinaeValue = value_type,
1749 ARENE_NODISCARD friend auto
1751 return !(lhs == rhs);
1752 }
1753 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
1754 // parasoft-end-suppress AUTOSAR-M3_3_2-a-2
1755
1756 private:
1757 /// @brief The type of the storage for each entry
1758 using entry_type = optional<value_type>;
1759
1760 /// @brief Insert the values from @c init_list into the map.
1761 /// @param init_list The elements to insert
1762 /// @throws Any exception thrown by the copy constructor of the keys or values, or the comparisons
1763 /// @return bool @c true if the values fit, @c false if there is insufficient capacity
1764 auto insert_elements_if_they_fit(std::initializer_list<value_type> const& init_list) noexcept(
1765 comparison_is_noexcept<> && std::is_nothrow_copy_constructible<Key>::value &&
1767 ) -> bool {
1768 for (auto const& element : init_list) {
1769 auto pos_info = lower_bound_index(element.first);
1770 if (pos_info.order == strong_ordering::equal) {
1771 continue;
1772 }
1773 if (size() == Capacity) {
1774 return false;
1775 }
1776 std::ignore = insert_at(pos_info.index, element.first, element.second);
1777 }
1778 return true;
1779 }
1780
1781 /// @brief Gets a reference to the entry corrsponding to a given index.
1782 /// @param index Index of the element in iteration order.
1783 /// @return A reference to the element for the given index.
1784 /// @pre @c index<indicies.size()
1785 auto entry_at_index(index_type index) noexcept -> entry_type& { return values_[indices_[index]]; }
1786 /// @brief Gets a reference to the entry corrsponding to a given index.
1787 /// @param index Index of the element in iteration order.
1788 /// @return A reference to the element for the given index.
1789 /// @pre @c index<indicies.size()
1790 auto entry_at_index(index_type index) const noexcept -> entry_type const& { return values_[indices_[index]]; }
1791
1792 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "Use of a friend function with
1793 // passkey improves encapsulation. It allows data members to remain private
1794 // and does not unnecessarily expose a public member function."
1795
1796 // parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
1797
1798 /// @brief Gets the value at an index
1799 /// @tparam Self Deduced-this type of the map.
1800 /// @param self The map
1801 /// @param index the index in the map
1802 /// @return reference to the value at the given index
1803 /// @note this is primarily used to provide minimal access to @c inline_map_reference_iterator
1804 ///
1805 template <typename Self, constraints<std::enable_if_t<decays_to_v<Self, inline_map>>> = nullptr>
1806 friend auto value_at_index(inline_map_passkey, Self& self, std::size_t index)
1808 return *self.entry_at_index(static_cast<index_type>(index));
1809 }
1810
1811 // parasoft-end-suppress AUTOSAR-M3_3_2-a
1812 // parasoft-end-suppress AUTOSAR-A11_3_1-a
1813
1814 /// @brief Insert a new element at the specified position, constructed by perfectly forwarding the key and
1815 /// initialization arguments.
1816 ///
1817 /// @tparam OtherKey The type of the key to insert
1818 /// @tparam Args The types of the initialization arguments for the mapped type
1819 /// @param pos The position of the new element
1820 /// @param key The key for the element to insert
1821 /// @param args The initialization arguments for the mapped type
1822 /// @return A reference to the newly constructed element
1823 /// @pre @c size()<Capacity, else @c ARENE_PRECONDITION violation.
1824 template <typename OtherKey, typename... Args>
1825 auto insert_at(index_type pos, OtherKey&& key, Args&&... args) -> entry_type& {
1826 ARENE_PRECONDITION(size_ < Capacity);
1827 index_type const new_index{indices_[size_]};
1828 auto& entry = values_[new_index];
1829 entry.emplace(
1833 );
1834 insert_index_at(pos, new_index);
1835 return entry;
1836 }
1837
1838 /// @brief Insert a new index at the specified position
1839 /// @param pos The position for the new index
1840 /// @param new_index The new index value to insert
1841 void insert_index_at(index_type pos, index_type new_index) noexcept {
1842 for (index_type i{size_}; i > pos; --i) {
1843 indices_[i] = indices_[static_cast<index_type>(i - 1U)];
1844 }
1845 indices_[pos] = new_index;
1846 ++size_;
1847 }
1848
1849 /// @brief Obtain the index of the first entry such that @c entry.first < @c key
1850 ///
1851 /// @tparam OtherKey the type of the key to search for
1852 /// @param key The key to search for
1853 /// @return inline_container::detail::lower_bound_index_info<index_type> The index of the element, and the
1854 /// strong_ordering between that element and @c key . If @c key is greater than all elements, then the index
1855 /// is @c size() and the ordering is @c strong_ordering::greater .
1856 /// @throws Any exception thrown by the comparisons
1857 template <typename OtherKey>
1858 auto lower_bound_index(OtherKey const& key) const noexcept(comparison_is_noexcept<OtherKey>)
1859 -> inline_container::detail::lower_bound_index_info<index_type> {
1860 auto const compare = [this](key_type const& lhs, OtherKey const& rhs) noexcept(comparison_is_noexcept<OtherKey>) {
1861 return this->key_ordering(lhs, rhs);
1862 };
1863 auto const accessor = [this](index_type const index) noexcept -> key_type const& {
1864 return this->entry_at_index(index)->first;
1865 };
1866 return inline_container::detail::lower_bound_index<key_type, OtherKey, index_type>(key, size_, compare, accessor);
1867 }
1868
1869 /// @brief A type alias for the appropriate iterator for @c Self
1870 /// @tparam Self the type of the container
1871 template <typename Self>
1872 using self_iterator = iterator_impl<std::is_const<std::remove_reference_t<Self>>::value>;
1873
1874 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "The universal reference is used to detect the value category"
1875 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: Self is a template parameter"
1876 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: this is not a move constructor"
1877 /// @brief Deduced-this helper for universally constructing iterators.
1878 ///
1879 /// @tparam Self Deduced-this type of the map.
1880 /// @param self The map
1881 /// @param index The index to construct the iterator pointing to.
1882 /// @return auto An iterator of the correct constness for @c Self which points to @c index .
1883 template <typename Self, constraints<std::enable_if_t<decays_to_v<Self, inline_map>>> = nullptr>
1884 static auto make_iterator(Self&& self, index_type index) noexcept -> self_iterator<Self> {
1885 return {inline_map_passkey{}, &self, index};
1886 }
1887 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
1888 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
1889 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
1890
1891 /// @brief Deduced-this helper that detemplitizes find iterator generation from key type.
1892 ///
1893 /// @tparam Self Deduced-this type of the map.
1894 /// @param self The map
1895 /// @param lb_info An instance of the return from @c lower_bound_index()
1896 /// @return auto If @c lb_info.order==strong_ordering::equal , then an iterator constructed as if via @c
1897 /// make_iterator(self,lb_info.index) , otherwise @c self.end() .
1898 template <typename Self, constraints<std::enable_if_t<decays_to_v<Self, inline_map>>> = nullptr>
1899 static auto make_find_iterator(Self&& self, inline_container::detail::lower_bound_index_info<index_type> lb_info)
1900 -> self_iterator<Self> {
1901 if (lb_info.order == strong_ordering::equal) {
1902 return make_iterator(std::forward<Self>(self), lb_info.index);
1903 }
1904 return self.end();
1905 }
1906
1907 /// @brief Deduced-this helper implementation for @c find() which works for all comparators and iterator types.
1908 ///
1909 /// @tparam OtherKey the type of the key to search for.
1910 /// @tparam Self Deduced-this type of the map.
1911 /// @param self The map
1912 /// @param key The key to search for.
1913 /// @return The iterator at the position of @c value if it is found, else @c end() .
1914 template <typename Self, typename OtherKey, constraints<std::enable_if_t<decays_to_v<Self, inline_map>>> = nullptr>
1915 static auto do_find(Self&& self, OtherKey const& key) noexcept(comparison_is_noexcept<OtherKey>)
1916 -> self_iterator<Self> {
1917 return make_find_iterator(std::forward<Self>(self), self.lower_bound_index(key));
1918 }
1919
1920 /// @brief Helper implementation for @c contains which works for all comparators.
1921 ///
1922 /// @tparam OtherKey the type of the key to find
1923 /// @param key The value to search for
1924 /// @return true if @c find(key)!=end() .
1925 /// @return false if @c find(key)==end() .
1926 template <typename OtherKey>
1927 auto do_contains(OtherKey const& key) const noexcept(comparison_is_noexcept<OtherKey>) -> bool {
1928 return lower_bound_index(key).order == strong_ordering::equal;
1929 }
1930
1931 /// @brief Helper implementation for @c count which works for all comparators.
1932 ///
1933 /// @tparam OtherKey the type of the key to find.
1934 /// @param key The value to search for.
1935 /// @return std::size_t @c 0 if the element was not in the map, else @c 1 .
1936 template <typename OtherKey>
1937 auto do_count(OtherKey const& key) const noexcept(comparison_is_noexcept<OtherKey>) -> std::size_t {
1938 return static_cast<std::size_t>(do_contains(key));
1939 }
1940
1941 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "The universal reference is used to detect the value category"
1942 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False Positive: Self is a template parameter"
1943 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: this is not a move constructor"
1944 /// @brief Helper implementation for @c lower_bound which works for all comparators and iterator types.
1945 ///
1946 /// @tparam OtherKey the type of the key to find.
1947 /// @tparam Self Deduced-this type of the map.
1948 /// @param self The map
1949 /// @param key The key to find the lower bound for.
1950 /// @return iterator An iterator to the first element which is _not less than_ @c value.
1951 template <typename Self, typename OtherKey, constraints<std::enable_if_t<decays_to_v<Self, inline_map>>> = nullptr>
1952 static auto do_lower_bound(Self&& self, OtherKey const& key) noexcept(comparison_is_noexcept<OtherKey>)
1953 -> self_iterator<Self> {
1954 return make_iterator(self, self.lower_bound_index(key).index);
1955 }
1956 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
1957 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
1958 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
1959
1960 /// @brief Deduced-this helper that detemplitizes upper_bound iterator generation from key type.
1961 ///
1962 /// @tparam Self Deduced-this type of the map.
1963 /// @param self The instance of the map to operate on.
1964 /// @param lb_info An instance of the return from @c lower_bound_index()
1965 /// @return auto If @c lb_info.order==strong_ordering::equal , then an iterator constructed as if via @c
1966 /// make_iterator(self,lb_info.index + 1) , otherwise @c make_iterator(self,lb_info.index) .
1967 template <typename Self, constraints<std::enable_if_t<decays_to_v<Self, inline_map>>> = nullptr>
1968 static auto
1969 make_upper_bound_iterator(Self&& self, inline_container::detail::lower_bound_index_info<index_type> lb_info) noexcept
1970 -> self_iterator<Self> {
1971 if (lb_info.order == strong_ordering::equal) {
1972 ++lb_info.index;
1973 }
1974 return make_iterator(std::forward<Self>(self), lb_info.index);
1975 }
1976
1977 /// @brief Helper implementation for @c upper_bound which works for all comparators and iterator types.
1978 ///
1979 /// @tparam OtherKey the type of the key to find
1980 /// @tparam Self Deduced-this type of the map.
1981 /// @param self The map
1982 /// @param key The key to search for.
1983 /// @return An iterator to the first element which is _greater than_ @c key , or @c end() if there is no such
1984 /// element.
1985 template <typename Self, typename OtherKey, constraints<std::enable_if_t<decays_to_v<Self, inline_map>>> = nullptr>
1986 static auto do_upper_bound(Self&& self, OtherKey const& key) noexcept(comparison_is_noexcept<OtherKey>)
1987 -> self_iterator<Self> {
1988 return make_upper_bound_iterator(std::forward<Self>(self), self.lower_bound_index(key));
1989 }
1990
1991 /// @brief Deduced-this helper that detemplitizes equal_range iterator generation from key type.
1992 ///
1993 /// @tparam Self Deduced-this type of the map.
1994 /// @param self The map
1995 /// @param lb_info An instance of the return from @c lower_bound_index()
1996 /// @return auto A pair of iterators where the first element is @c make_find_iterator(self,lb_info) , and the second
1997 /// element is either that iterator incremented by one if the iterator was not @c self.end() , otherwise @c self.end()
1998 template <typename Self, constraints<std::enable_if_t<decays_to_v<Self, inline_map>>> = nullptr>
1999 static auto
2000 make_equal_range_iterator(Self&& self, inline_container::detail::lower_bound_index_info<index_type> lb_info)
2001 -> std::pair<self_iterator<Self>, self_iterator<Self>> {
2002 auto first = make_find_iterator(std::forward<Self>(self), lb_info);
2003 auto last = first == self.end() ? first : ::arene::base::next(first);
2004 return std::make_pair(first, last);
2005 }
2006
2007 /// @brief Helper implementation for @c equal_range which works for all comparators and iterator types.
2008 ///
2009 /// @tparam OtherKey the type of the value to find
2010 /// @tparam Self Deduced-this type of the map.
2011 /// @param self The map
2012 /// @param key The value to search for
2013 /// @return std::pair<iterator, iterator> A pair of iterators such that all values in the range @c [first,second)
2014 /// compare equal to @c value if there was an element equivalent to @c value in the set. Otherwise both
2015 /// iterators will be @c end() .
2016 template <typename Self, typename OtherKey, constraints<std::enable_if_t<decays_to_v<Self, inline_map>>> = nullptr>
2017 static auto do_equal_range(Self&& self, OtherKey const& key) noexcept(comparison_is_noexcept<OtherKey>)
2018 -> std::pair<self_iterator<Self>, self_iterator<Self>> {
2019 return make_equal_range_iterator(std::forward<Self>(self), self.lower_bound_index(key));
2020 }
2021
2022 // parasoft-begin-suppress AUTOSAR-A7_5_1-a-2 "False positive: Returns reference to element"
2023 /// @brief Helper implementation for @c operator[] which works for all comparators.
2024 ///
2025 /// @tparam OtherKey the type of the key to find.
2026 /// @param key The key to obtain the value for
2027 /// @return Value& A reference to the mapped value. If @c key did not exist in the map, then a default constructed
2028 /// @c Value is inserted into the map at @c key and a reference to it is returned.
2029 template <typename OtherKey>
2030 auto do_operator_index(OtherKey const& key) -> Value& {
2031 auto pos_info = lower_bound_index(key);
2032 if (pos_info.order == strong_ordering::equal) {
2033 return entry_at_index(pos_info.index)->second;
2034 }
2035 return insert_at(pos_info.index, key)->second;
2036 }
2037 // parasoft-end-suppress AUTOSAR-A7_5_1-a-2
2038
2039 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "The universal reference is used to detect the value category"
2040 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "The universal reference is used to detect the value category"
2041 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: Self is a template parameter"
2042 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: this is not a move constructor"
2043 /// @brief Helper implementation for @c at which works for all comparators and const-ness.
2044 ///
2045 /// @tparam OtherKey the type of the key to find
2046 /// @tparam Self Deduced-this type of the map.
2047 /// @param self The map
2048 /// @param key The key to obtain the value for
2049 /// @return A reference to the mapped value
2050 /// @throws std::out_of_range if @c find(key)==end() .
2051 /// @throws Any exception thrown by the comparisons
2052 template <typename Self, typename OtherKey, constraints<std::enable_if_t<decays_to_v<Self, inline_map>>> = nullptr>
2053 ARENE_NODISCARD static auto do_at(Self&& self, OtherKey const& key)
2055 auto maybe_element = do_find(self, key);
2056 if (maybe_element == self.end()) {
2057 inline_map_detail::throw_out_of_range();
2058 }
2059 return maybe_element->second;
2060 }
2061 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
2062 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
2063 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
2064
2065 /// @brief Helper for @c insert_or_assign which works for all comparators and key types.
2066 ///
2067 /// Perfectly forwards the provided key and value into the constructor of the new element if an appropriate element
2068 /// does not already exist; perfectly forwards into the assignment operator for the existing element if there is one.
2069 /// @tparam OtherKey The key type.
2070 /// @tparam OtherMapped The type of the initializer for the mapped type
2071 /// @param key The key for which to insert or assign an element
2072 /// @param mapped_value The value with which to construct or assign the mapped value
2073 /// @return A pair of an iterator to the element with a key equivalent to @c key, and a boolean with a value of
2074 /// @c true if the element was inserted, or @c false otherwise.
2075 /// @pre If insertion is required, @c size()<Capacity else @c ARENE_PRECONDITION violation.
2076 /// @throws Any exception thrown by the comparisons, the move constructor of @c Key or the constructor or assignment
2077 /// operator of @c Value .
2078 template <typename OtherKey, typename OtherMapped>
2079 auto do_insert_or_assign(OtherKey&& key, OtherMapped&& mapped_value) -> std::pair<iterator, bool> {
2080 auto res = do_try_emplace(std::forward<OtherKey>(key), std::forward<OtherMapped>(mapped_value));
2081 if (!res.second) {
2082 res.first->second = std::forward<OtherMapped>(mapped_value);
2083 }
2084 return res;
2085 }
2086
2087 /// @brief Helper for @c try_emplace which works for all comparators and keys.
2088 ///
2089 /// Perfectly forwards the provided arguments into the constructor of the key and value if an appropriate element does
2090 /// not already exist.
2091 /// @tparam Args The types of the initializers for the mapped type.
2092 /// @tparam OtherKey The key type.
2093 /// @param key The key for which to insert or assign an element
2094 /// @param args The values with which to construct the mapped value
2095 /// @return std::pair<iterator, bool> A pair whose second element will be @c true if the emplace happened. The first
2096 /// element will be an iterator pointing to the element corresponding to @c key : the existing element if
2097 /// the insert did not happen, or the new element if it did.
2098 /// @pre If emplacement is required, @c size()<Capacity else @c ARENE_PRECONDITION violation.
2099 /// @throws Any exception thrown by the comparisons or constructors of @c Key and @c Value .
2100 template <typename OtherKey, typename... Args>
2101 auto do_try_emplace(OtherKey&& key, Args&&... args) -> std::pair<iterator, bool> {
2102 auto const pos_info = lower_bound_index(key);
2103 bool const needs_insert{pos_info.order != strong_ordering::equal};
2104 if (needs_insert) {
2105 std::ignore = insert_at(pos_info.index, std::forward<OtherKey>(key), std::forward<Args>(args)...);
2106 }
2107 // parasoft-begin-suppress AUTOSAR-A8_4_2-a CERT_C-MSC37-a CERT_CPP-MSC52-a "False positive: returns a value"
2108 return {make_iterator(*this, pos_info.index), needs_insert};
2109 // parasoft-end-suppress AUTOSAR-A8_4_2-a CERT_C-MSC37-a CERT_CPP-MSC52-a
2110 }
2111
2112 /// @brief helper for @c erase(key) which works for all comparators.
2113 ///
2114 /// @tparam OtherKey The type of the key to find
2115 /// @param key The key to erase.
2116 /// @return iterator An iterator which points to the position after the removed element.
2117 template <typename OtherKey>
2118 auto do_erase(OtherKey const& key) noexcept(comparison_is_noexcept<OtherKey>) -> iterator {
2119 return erase_at_index(do_find(*this, key).get_index(inline_map_passkey{}));
2120 }
2121
2122 /// @brief Erase the element at the specified index.
2123 ///
2124 /// @param index The index of the element to erase
2125 /// @return An iterator to the element after the erased element, or @c end() if @c index>=size_.
2126 auto erase_at_index(index_type index) noexcept -> iterator {
2127 return index < size_ ? erase_index_range(index, 1U) : end();
2128 }
2129
2130 /// @brief Erase the elements in the specified index range.
2131 ///
2132 /// @param from The position in the index of the first element to erase
2133 /// @param erase_count The number of elements to erase
2134 /// @return An iterator to the element after the specified elements, or @c end() if there is no such element.
2135 // NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
2136 auto erase_index_range(index_type from, index_type erase_count) noexcept -> iterator {
2137 // We used this odd syntax because GCC8/9 are convinced that from + erase_count results in integer promotion, even
2138 // though they're guaranteed to be the same type.
2139 auto const last_index = static_cast<index_type>(from + erase_count);
2140 for (auto index = from; index < last_index; ++index) {
2141 entry_at_index(index).reset();
2142 }
2143 std::ignore = arene::base::rotate(indices_.begin() + from, indices_.begin() + last_index, indices_.begin() + size_);
2144 size_ = static_cast<index_type>(size_ - (last_index - from));
2145
2146 return make_iterator(*this, from);
2147 }
2148
2149 /// @brief Move-construct a new element from the specified element, and clear the old
2150 /// element.
2151 /// @param other The element to move from
2152 /// @return The new element
2153 /// @throws Any exception thrown by the copy-constructor of @c Key or the
2154 /// move-constructor of @c Value
2155 static auto move_value(entry_type& other
2157 -> entry_type {
2158 entry_type res{std::move(other)};
2159 other.reset();
2160 return res;
2161 }
2162
2163 /// @brief Create a new array of elements which is a move-constructed copy of the
2164 /// elements from the provided map.
2165 /// @tparam Indices The indices of the elements from @c 0 to @c Capacity-1
2166 /// @param other The source map
2167 /// @return A new value array
2168 /// @throws Any exception thrown by the copy-constructor of @c Key or the
2169 /// move-constructor of @c Value
2170 template <std::size_t... Indices>
2171 static auto move_values(inline_map& other, std::index_sequence<Indices...>) noexcept(
2173 ) -> array<entry_type, Capacity> {
2174 // parasoft-begin-suppress AUTOSAR-M0_1_3-a-2 "False positive: RAII class"
2175 auto const clear_on_exit = clear_on_scope_exit(other);
2176 // parasoft-end-suppress AUTOSAR-M0_1_3-a-2
2177 array<entry_type, Capacity> res{{move_value(other.values_[Indices])...}};
2178 return res;
2179 }
2180
2181 // parasoft-begin-suppress AUTOSAR-A7_1_5-a-2 "Return type cannot be named"
2182 /// @brief Helper to create a scope-guard which clears the input source on scope exit.
2183 ///
2184 /// @param source The container to clear on scope exit.
2185 /// @return A @c scope_guard which will call @c clear() on @c source .
2186 template <std::size_t OtherCapacity>
2187 static auto clear_on_scope_exit(inline_map<Key, Value, OtherCapacity, Compare>& source) noexcept {
2188 return on_scope_exit([&source]() noexcept { //
2189 source.clear();
2190 });
2191 }
2192 // parasoft-end-suppress AUTOSAR-A7_1_5-a-2
2193
2194 // parasoft-begin-suppress AUTOSAR-M9_3_3-a-2 "False positive: Uses this"
2195 // parasoft-begin-suppress AUTOSAR-A7_1_5-a-2 "Return type cannot be named"
2196 /// @brief Helper to create a scope-guard which resets all values between the current size_ and an index.
2197 ///
2198 /// @param end_index One past the last index to reset to.
2199 /// @return A @c scope_guard which will call @c reset() on every element fetched via @c entry_at_index() in the range
2200 /// @c [size_,end) .
2201 auto reset_trailing_values_on_scope_exit(index_type const end_index) noexcept {
2202 return on_scope_exit([this, end_index]() noexcept {
2203 for (index_type idx = this->size_; idx < end_index; ++idx) {
2204 this->entry_at_index(idx).reset();
2205 }
2206 });
2207 }
2208 // parasoft-end-suppress AUTOSAR-A7_1_5-a-2
2209 // parasoft-end-suppress AUTOSAR-M9_3_3-a-2
2210
2211 /// @brief Copy the elements from the other map over those in the current set.
2212 ///
2213 /// @tparam OtherMap The type of the map to copy from
2214 /// @param other The source map to copy from.
2215 /// @throws Any exception thrown by the copy of the elements or comparator
2216 /// @post @c size()==other.size() , or the index of the first element which throws during copy construction if a throw
2217 /// occurs.
2218 /// @post @c The elements from @c other will have been copy-emplaced into @c this , up to the first element which
2219 /// threw during move-construction, if any.
2220 /// @post @c The elements in the range @c [size(),other.size()) will have been reset if @c other.size() was smaller
2221 /// than the original size of @c this .
2222 template <typename OtherMap>
2223 void do_copy(OtherMap const& other
2225 do_assignment(other);
2226 }
2227
2228 // parasoft-begin-suppress AUTOSAR-A0_1_4-a "False positive: parameter 'other' is used"
2229 // parasoft-begin-suppress AUTOSAR-M0_1_8-b "False positive: function 'do_move' is not empty"
2230
2231 /// @brief Move the elements from the other map over those in the current map.
2232 ///
2233 /// @tparam OtherMap The type of the map to move from,
2234 /// @param other The source map to move from.
2235 /// @throws Any exception thrown by the move of the elements or comparator.
2236 /// @post @c size()==other.size() , or the index of the first element which throws during move construction if a throw
2237 /// occurs.
2238 /// @post @c other.clear() will have been executed.
2239 /// @post @c The elements from @c other will have been move-emplaced into @c this , up to the first element which
2240 /// threw during move-construction, if any.
2241 /// @post @c The elements in the range @c [size(),other.size()) will have been reset if @c other.size() was smaller
2242 /// than the original size of @c this .
2243 template <typename OtherMap>
2244 void do_move(OtherMap&& other
2246 // parasoft-begin-suppress AUTOSAR-M0_1_3-a-2 "False positive: RAII class"
2247 auto const clear_on_exit = clear_on_scope_exit(other);
2248 // parasoft-end-suppress AUTOSAR-M0_1_3-a-2
2249 do_assignment(std::forward<OtherMap>(other));
2250 }
2251
2252 // parasoft-end-suppress AUTOSAR-A0_1_4-a
2253 // parasoft-end-suppress AUTOSAR-M0_1_8-b
2254
2255 // parasoft-begin-suppress AUTOSAR-A0_1_4-a "False positive: parameter 'other' is used"
2256 // parasoft-begin-suppress AUTOSAR-M0_1_8-b "False positive: function 'do_assignment' is not empty"
2257
2258 /// @brief Helper for @c do_copy and @c do_move with non-copy/move dependent logic.
2259 ///
2260 /// @tparam OtherMap The type of the map to copy/move from
2261 /// @param other The source map top copy/move from.
2262 /// @throws Any exception thrown by the copy/move of the elements or comparator.
2263 /// @post @c size()==other.size() , or the index of the first element which throws during move construction if a throw
2264 /// occurs.
2265 /// @post @c The elements from @c other will have been move-emplaced into @c this , up to the first element which
2266 /// threw during copy/move-construction, if any.
2267 /// @post @c The elements in the range @c [size(),other.size()) will have been reset if @c other.size() was smaller
2268 /// than the original size of @c this .
2269 template <typename OtherMap>
2270 void do_assignment(OtherMap&& other) noexcept(
2273 ) {
2274 static_cast<comparator_base&>(*this) = std::forward<OtherMap>(other);
2275 // parasoft-begin-suppress AUTOSAR-M0_1_3-a-2 "False positive: RAII class"
2276 auto const reset_trailing_values = reset_trailing_values_on_scope_exit(size_);
2277 // parasoft-end-suppress AUTOSAR-M0_1_3-a-2
2278 size_ = 0U;
2279 while (size_ != other.size_) {
2280 this->entry_at_index(size_).emplace(forward_like<OtherMap>(*other.entry_at_index(size_)));
2281 ++size_;
2282 }
2283 }
2284
2285 // parasoft-end-suppress AUTOSAR-A0_1_4-a
2286 // parasoft-end-suppress AUTOSAR-M0_1_8-b
2287
2288 /// @brief The current number of elements in the map
2289 index_type size_{0};
2290 /// @brief The indices of the elements in sorted order
2291 array<index_type, Capacity> indices_{inline_container_detail::make_index_array<index_type, Capacity>()};
2292 // parasoft-begin-suppress AUTOSAR-M8_5_2-b-2 "False Positive: all elements default-initialized"
2293 /// @brief The storage of the actual elements themselves
2294 array<entry_type, Capacity> values_{};
2295 // parasoft-end-suppress AUTOSAR-M8_5_2-b-2
2296};
2297// parasoft-end-suppress AUTOSAR-A13_5_1-a-2
2298// parasoft-end-suppress AUTOSAR-A10_1_1-a-2
2299// parasoft-end-suppress AUTOSAR-A12_0_1-b-2
2300// parasoft-end-suppress AUTOSAR-A12_0_1-a-2
2301// parasoft-end-suppress AUTOSAR-A1_1_1-b-2
2302
2303template <typename Key, typename Value, std::size_t Capacity, typename Compare>
2304constexpr std::integral_constant<typename inline_map<Key, Value, Capacity, Compare>::size_type, Capacity>
2306
2307template <typename Key, typename Value, std::size_t Capacity, typename Compare>
2310
2312namespace detail {
2313
2314/// @brief specialization for @c inline_map
2315/// @tparam Key key type of @c inline_map
2316/// @tparam Value mapped type of @c inline_map
2317/// @tparam Capacity capacity of @c inline_map
2318/// @tparam Compare compare type of @c inline_map
2319///
2320template <class Key, class Value, std::size_t Capacity, class Compare>
2321struct container_base_type<inline_map<Key, Value, Capacity, Compare>> {
2322 /// @brief container capacity-erased base type
2323 ///
2324 using type = inline_map_detail::inline_map_base<Key, Value, Compare>;
2325};
2326
2327} // namespace detail
2328} // namespace inline_container
2329
2330} // namespace base
2331} // namespace arene
2332
2333// parasoft-end-suppress AUTOSAR-M2_10_1-a-2
2334// parasoft-end-suppress AUTOSAR-A13_5_5-b-2
2335
2336#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_MAP_HPP_
A container similar to std::map that has a fixed capacity.
Definition map.hpp:153
inline_map()=default
Construct the map with a default-constructed comparator and no elements.
auto erase(OtherKey const &key) noexcept(comparison_is_noexcept< OtherKey >) -> iterator
Erase the element with the corresponding key, if there is one.
Definition map.hpp:1561
ARENE_NODISCARD 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 map.hpp:1660
inline_map(Compare const &compare) noexcept(std::is_nothrow_copy_constructible< Compare >::value)
Construct the map with a copy of the specified comparator and no elements.
Definition map.hpp:686
auto upper_bound(Key const &key) noexcept(comparison_is_noexcept<>) -> iterator
Find the first element which is greater than a given key.
Definition map.hpp:1100
value_type * pointer
The type of a pointer to the value type of the map.
Definition map.hpp:373
typename iterator::difference_type difference_type
The difference type of the map.
Definition map.hpp:394
auto operator[](Key const &key) -> Value &
Obtain a reference to the mapped value for the specified key.
Definition map.hpp:1200
typename map_base_type::key_type key_type
The key type of the map.
Definition map.hpp:365
~inline_map()=default
Default destructor.
ARENE_NODISCARD 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 map.hpp:1656
ARENE_NODISCARD auto cend() const noexcept -> const_iterator
Obtain an iterator referring to one past the last element in the sorted range of elements.
Definition map.hpp:1637
auto lower_bound(OtherKey const &key) noexcept(comparison_is_noexcept< OtherKey >) -> iterator
Find the first element which is not less than a given key.
Definition map.hpp:1073
ARENE_NODISCARD auto at(OtherKey const &key) const -> Value const &
Obtain a reference to the mapped value for the specified key or throw.
Definition map.hpp:1285
auto operator=(move_assign_source &&other) noexcept(std::is_nothrow_move_assignable< Compare >::value &&std::is_nothrow_move_constructible< value_type >::value) -> inline_map &
Move-assignment of a map with the same capacity.
Definition map.hpp:879
auto insert(value_type const &value) -> std::pair< iterator, bool >
Insert a new element in the map if there is not already one with the corresponding key.
Definition map.hpp:1310
static ARENE_NODISCARD auto try_construct(inline_map const &other) noexcept(std::is_nothrow_copy_constructible< C >::value &&std::is_nothrow_copy_constructible< V >::value) -> optional< inline_map >
Copy construct a map.
Definition map.hpp:482
auto operator=(inline_map< Key, Value, OtherCapacity, Compare > const &other) -> inline_map &
copy-assignment of a map with a smaller capacity.
Definition map.hpp:863
inline_map(std::initializer_list< value_type > init_list, Compare const &compare)
Construct the map with a copy of the specified comparator and copies of the elements from the provide...
Definition map.hpp:675
ARENE_NODISCARD auto end() const noexcept -> const_iterator
Obtain an iterator referring to one past the last element in the sorted range of elements.
Definition map.hpp:1634
iterator_impl< false > iterator
The type of an iterator that provides non- const access to the elements.
Definition map.hpp:382
inline_map(move_construct_source &&other) noexcept(std::is_nothrow_move_constructible< Compare >::value &&std::is_nothrow_copy_constructible< Key >::value &&std::is_nothrow_move_constructible< Value >::value)
Move the source map into the new instance, so the new map has the same size, comparator and elements ...
Definition map.hpp:707
map_base_type inline_map_base_type
inline_map_base type
Definition map.hpp:402
ARENE_NODISCARD auto at(Key const &key) const -> Value const &
Obtain a reference to the mapped value for the specified key or throw.
Definition map.hpp:1246
ARENE_NODISCARD auto at(Key const &key) -> Value &
Obtain a reference to the mapped value for the specified key or throw.
Definition map.hpp:1234
friend class inline_map
Definition map.hpp:162
auto erase(iterator pos) noexcept -> iterator
Erase the element at the specified position.
Definition map.hpp:1575
auto insert_or_assign(Key const &key, OtherMapped &&mapped_value) -> std::pair< iterator, bool >
Insert a new element in the map if there is not already one with the corresponding key,...
Definition map.hpp:1376
void clear() noexcept
Destroy all elements in *this and set the size to zero.
Definition map.hpp:1612
static ARENE_NODISCARD auto try_construct(Compare const &comparator) noexcept(std::is_nothrow_copy_constructible< Compare >::value) -> optional< inline_map >
Construct a map with a comparator copied from the supplied value.
Definition map.hpp:465
ARENE_NODISCARD auto rbegin() noexcept -> reverse_iterator
Obtain an iterator referring to the beginning of a reversed traversal of the sorted range of elements...
Definition map.hpp:1641
ARENE_NODISCARD friend auto operator!=(inline_map const &lhs, inline_map< Key, Value, OtherCapacity, Compare > const &rhs) noexcept -> bool
Compares two maps for inequality of elements when mapped_value is not three-way-comparable.
Definition map.hpp:1750
inline_map(inline_map< Key, Value, OtherCapacity, Compare > &&other)
Move from a map with a different capacity.
Definition map.hpp:773
friend auto value_at_index(inline_map_passkey, Self &self, std::size_t index) -> conditional_t< std::is_const< std::remove_reference_t< Self > >::value, value_type const &, value_type & >
Gets the value at an index.
Definition map.hpp:1806
inline_map(std::initializer_list< value_type > init_list)
Construct the map with a default-constructed comparator and copies of the elements from the provided ...
Definition map.hpp:647
value_type const & const_reference
The type of a const reference to the value type of the map.
Definition map.hpp:379
auto insert(P &&value) -> std::pair< iterator, bool >
Insert a new element in the map if there is not already one with the corresponding key.
Definition map.hpp:1351
auto count(OtherKey const &key) const noexcept(comparison_is_noexcept< OtherKey >) -> size_type
Return the number of elements in the map equivalent to a specific key.
Definition map.hpp:1044
auto insert_or_assign(OtherKey &&key, OtherMapped &&mapped_value) -> std::pair< iterator, bool >
Insert a new element in the map if there is not already one with an equivalent key,...
Definition map.hpp:1426
static ARENE_NODISCARD auto three_way_compare(inline_map const &lhs, inline_map< Key, Value, OtherCapacity, Compare > const &rhs) noexcept -> strong_ordering
Compares two maps lexicographically .
Definition map.hpp:1701
auto find(Key const &key) const noexcept(comparison_is_noexcept<>) -> const_iterator
Obtain an iterator referring to the element equivalent to the supplied key, if there is one.
Definition map.hpp:980
ARENE_NODISCARD auto begin() const noexcept -> const_iterator
Obtain an iterator referring to the beginning of the sorted range of elements.
Definition map.hpp:1624
auto upper_bound(Key const &key) const noexcept(comparison_is_noexcept<>) -> const_iterator
Find the first element which is greater than a given key.
Definition map.hpp:1106
ARENE_NODISCARD auto cbegin() const noexcept -> const_iterator
Obtain an iterator referring to the beginning of the sorted range of elements.
Definition map.hpp:1627
static ARENE_NODISCARD auto try_construct(std::initializer_list< value_type > init_list, Compare const &comparator) noexcept(std::is_nothrow_copy_constructible< Compare >::value &&comparison_is_noexcept<> &&std::is_nothrow_copy_constructible< Key >::value &&std::is_nothrow_copy_constructible< Value >::value) -> optional< inline_map >
Construct a map with a comparator copied from the supplied value and copies of the elements from the ...
Definition map.hpp:610
ARENE_NODISCARD friend auto operator==(inline_map const &lhs, inline_map< Key, Value, OtherCapacity, Compare > const &rhs) noexcept -> bool
Compares two maps for equality of elements when mapped_value is not three-way-comparable.
Definition map.hpp:1725
auto try_emplace(Key &&key, Args &&... args) -> std::pair< iterator, bool >
Try to emplace a new element in the map if there is not already one with the corresponding key.
Definition map.hpp:1477
::arene::base::reverse_iterator< const_iterator > const_reverse_iterator
The type of an iterator that provides const access to the elements and iterates in reverse through th...
Definition map.hpp:391
ARENE_NODISCARD auto size() const noexcept -> size_type
Get the number of elements in the map.
Definition map.hpp:965
auto upper_bound(OtherKey const &key) const noexcept(comparison_is_noexcept< OtherKey >) -> const_iterator
Find the first element which is greater than a given key.
Definition map.hpp:1131
auto try_emplace(OtherKey &&key, Args &&... args) -> std::pair< iterator, bool >
Try to emplace a new element in the map if there is not already one with an equivalent key.
Definition map.hpp:1503
static ARENE_NODISCARD auto fast_inequality_check(inline_map const &lhs, inline_map< Key, Value, OtherCapacity, Compare > const &rhs) noexcept -> inequality_heuristic
Fast inequality heuristic to shortcut on different sized containers.
Definition map.hpp:1671
auto emplace(Args &&... args) -> std::pair< iterator, bool >
Construct a new value_type object and try to insert it in the map if there is not already one with th...
Definition map.hpp:1529
typename map_base_type::value_type value_type
The value type of the map.
Definition map.hpp:363
auto lower_bound(Key const &key) const noexcept(comparison_is_noexcept<>) -> const_iterator
Find the first element which is not less than a given key.
Definition map.hpp:1063
auto operator=(dummy_move_assign_source &&) -> inline_map &=delete
Deleted move-assignment if the map should not be move-assignable.
static ARENE_NODISCARD auto try_construct() noexcept(std::is_nothrow_default_constructible< Compare >::value) -> optional< inline_map >
Construct an empty map with a default-constructed comparator.
Definition map.hpp:453
auto lower_bound(OtherKey const &key) const noexcept(comparison_is_noexcept< OtherKey >) -> const_iterator
Find the first element which is not less than a given key.
Definition map.hpp:1088
static ARENE_NODISCARD auto try_construct(inline_map &&other) noexcept(std::is_nothrow_move_constructible< C >::value &&std::is_nothrow_copy_constructible< K >::value &&std::is_nothrow_move_constructible< V >::value) -> optional< inline_map >
Move construct a map.
Definition map.hpp:527
auto contains(Key const &key) const noexcept(comparison_is_noexcept<>) -> bool
Check if the set contains a specific key.
Definition map.hpp:1015
static constexpr std::integral_constant< size_type, Capacity > capacity
map capacity
Definition map.hpp:398
static ARENE_NODISCARD auto try_construct(inline_map< Key, Value, OtherCapacity, Compare > &&other) noexcept(std::is_nothrow_copy_constructible< C >::value &&std::is_nothrow_copy_constructible< K >::value &&std::is_nothrow_move_constructible< V >::value) -> optional< inline_map >
Move construct a map with a different size.
Definition map.hpp:553
typename map_base_type::mapped_type mapped_type
The mapped type of the map.
Definition map.hpp:367
auto erase(const_iterator pos) noexcept -> iterator
Erase the element at the specified position.
Definition map.hpp:1587
ARENE_NODISCARD 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 map.hpp:1647
ARENE_NODISCARD auto begin() noexcept -> iterator
Obtain an iterator referring to the beginning of the sorted range of elements.
Definition map.hpp:1621
auto contains(OtherKey const &key) const noexcept(comparison_is_noexcept< OtherKey >) -> bool
Check if the set contains a key equivalent to a specific value.
Definition map.hpp:1024
auto try_emplace(Key const &key, Args &&... args) -> std::pair< iterator, bool >
Try to emplace a new element in the map if there is not already one with the corresponding key.
Definition map.hpp:1454
auto find(OtherKey const &key) const noexcept(comparison_is_noexcept< OtherKey >) -> const_iterator
Obtain an iterator referring to the element equivalent to the supplied key, if there is one.
Definition map.hpp:1002
auto equal_range(OtherKey const &key) noexcept(comparison_is_noexcept< OtherKey >) -> std::pair< iterator, iterator >
Finds the sequence of elements whose keys compare equivalent to a given key.
Definition map.hpp:1167
typename map_base_type::compare_type key_compare
The comparator of the map.
Definition map.hpp:369
auto operator=(copy_assign_source const &other) noexcept(std::is_nothrow_copy_assignable< Compare >::value &&std::is_nothrow_copy_constructible< Key >::value &&std::is_nothrow_copy_constructible< Value >::value) -> inline_map &
copy-assignment of a map with the same capacity.
Definition map.hpp:802
ARENE_NODISCARD auto empty() const noexcept -> bool
Check if the map is empty.
Definition map.hpp:962
ARENE_NODISCARD auto at(OtherKey const &key) -> Value &
Obtain a reference to the mapped value for the specified key or throw.
Definition map.hpp:1264
auto find(OtherKey const &key) noexcept(comparison_is_noexcept< OtherKey >) -> iterator
Obtain an iterator referring to the element equivalent to the supplied key, if there is one.
Definition map.hpp:988
auto equal_range(Key const &key) noexcept(comparison_is_noexcept<>) -> std::pair< iterator, iterator >
Finds the sequence of elements whose keys compare equivalent to a given key.
Definition map.hpp:1145
inline_map(inline_map< Key, Value, OtherCapacity, Compare > const &other)
Copy from a map with a different capacity.
Definition map.hpp:739
::arene::base::reverse_iterator< iterator > reverse_iterator
The type of an iterator that provides non- const access to the elements and iterates in reverse throu...
Definition map.hpp:388
static constexpr std::integral_constant< size_type, Capacity > max_size
Get the maximum number of elements in the map, Capacity.
Definition map.hpp:968
ARENE_NODISCARD auto rend() noexcept -> reverse_iterator
Obtain an iterator referring to one past the last element in a reversed traversal of the sorted range...
Definition map.hpp:1652
auto equal_range(OtherKey const &key) const noexcept(comparison_is_noexcept< OtherKey >) -> std::pair< const_iterator, const_iterator >
Finds the sequence of elements whose keys compare equivalent to a given key.
Definition map.hpp:1183
auto erase(const_iterator first, const_iterator last) noexcept -> iterator
Erase all the elements in the specified iterator range.
Definition map.hpp:1600
auto insert(value_type &&value) -> std::pair< iterator, bool >
Insert a new element in the map if there is not already one with the corresponding key.
Definition map.hpp:1332
typename map_base_type::size_type size_type
The size type of the map.
Definition map.hpp:371
auto count(Key const &key) const noexcept(comparison_is_noexcept<>) -> size_type
Return the number of elements in the map equivalent to a specific key.
Definition map.hpp:1036
value_type const * const_pointer
The type of a const pointer to the value type of the map.
Definition map.hpp:375
auto erase(Key const &key) noexcept(comparison_is_noexcept<>) -> iterator
Erase the element with the corresponding key, if there is one.
Definition map.hpp:1553
ARENE_NODISCARD auto key_comp() const noexcept(std::is_nothrow_copy_constructible< Compare >::value) -> Compare
Obtain a copy of the comparator.
Definition map.hpp:956
iterator_impl< true > const_iterator
The type of an iterator that provides const access to the elements.
Definition map.hpp:384
ARENE_NODISCARD 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 map.hpp:1644
auto operator=(dummy_copy_assign_source const &) -> inline_map &=delete
Deleted copy-assignment if the map should not be copy-assignable.
inline_map(inline_map const &other)=default
Copy the source map, so the new map has the same size, comparator and elements as the source.
static ARENE_NODISCARD auto try_construct(inline_map< Key, Value, OtherCapacity, Compare > const &other) noexcept(std::is_nothrow_copy_constructible< C >::value &&std::is_nothrow_copy_constructible< V >::value) -> optional< inline_map >
Copy construct a map with a different size.
Definition map.hpp:503
auto find(Key const &key) noexcept(comparison_is_noexcept<>) -> iterator
Obtain an iterator referring to the element equivalent to the supplied key, if there is one.
Definition map.hpp:975
auto insert_or_assign(Key &&key, OtherMapped &&mapped_value) -> std::pair< iterator, bool >
Insert a new element in the map if there is not already one with the corresponding key,...
Definition map.hpp:1400
auto upper_bound(OtherKey const &key) noexcept(comparison_is_noexcept< OtherKey >) -> iterator
Find the first element which is greater than a given key.
Definition map.hpp:1116
auto operator[](OtherKey const &key) -> Value &
Obtain a reference to the mapped value for the specified key.
Definition map.hpp:1217
ARENE_NODISCARD auto end() noexcept -> iterator
Obtain an iterator referring to one past the last element in the sorted range of elements.
Definition map.hpp:1631
auto operator=(inline_map< Key, Value, OtherCapacity, Compare > &&other) -> inline_map &
Move-assignment of a map with a lesser capacity.
Definition map.hpp:948
value_type & reference
The type of a reference to the value type of the map.
Definition map.hpp:377
static ARENE_NODISCARD auto try_construct(std::initializer_list< value_type > init_list) noexcept(std::is_nothrow_default_constructible< Compare >::value &&comparison_is_noexcept<> &&std::is_nothrow_copy_constructible< Key >::value &&std::is_nothrow_copy_constructible< Value >::value) -> optional< inline_map >
Construct a map with a default-constructed comparator and copies of the elements from the provided in...
Definition map.hpp:580
auto equal_range(Key const &key) const noexcept(comparison_is_noexcept<>) -> std::pair< const_iterator, const_iterator >
Finds the sequence of elements whose keys compare equivalent to a given key.
Definition map.hpp:1154
auto lower_bound(Key const &key) noexcept(comparison_is_noexcept<>) -> iterator
Find the first element which is not less than a given key.
Definition map.hpp:1057
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
Implementation of std::initializer_list for brace initialization.
Definition initializer_list.hpp:21
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
a heterogeneous, fixed-size collection of values
Definition tuple.hpp:695
#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.
Provides implementation of a backport of C++20's version of std::equal.
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 map.hpp:2311
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
constexpr bool is_instantiation_of_v
Definition is_instantiation_of.hpp:16
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
constexpr auto distance(Iterator first, Iterator last) noexcept(noexcept(distance_impl::do_distance(first, last, typename std::iterator_traits< Iterator >::iterator_category{}))) -> typename std::iterator_traits< Iterator >::difference_type
Find the number of elements between first and last.
Definition distance.hpp:79
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 bool is_transparent_comparator_v
Trait to determine if a given type is a transparent comparator.
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
constexpr piecewise_construct_t piecewise_construct
Tag constant for piecewise construction.
Definition pair.hpp:42
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
#define ARENE_NORETURN
An alias for [[noreturn]] , or a no-op if the attribute is not supported.
Definition noreturn.hpp:24
Provides a backport of the constexpr implementation of std::reverse_iterator .