Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
pair.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_PAIR_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_PAIR_HPP_
7
8// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
9// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
10
11// IWYU pragma: private, include <utility>
12// IWYU pragma: friend "stdlib_detail/.*"
13
35
36namespace std {
37
38/// @brief Tag type for piecewise construction
40
41/// @brief Tag constant for piecewise construction
43
44// parasoft-begin-suppress AUTOSAR-A12_1_5-a "False positive: delegating constructors would not reduce duplication"
45/// @brief A simple data structure to hold two values.
46/// @tparam T1 The type of the first value
47/// @tparam T2 The type of the second value
48template <typename T1, typename T2>
49class pair {
50 // parasoft-end-suppress AUTOSAR-A12_1_5-a
51 public:
52 /// @brief The type of the first value
53 using first_type = T1;
54 /// @brief The type of the second value
55 using second_type = T2;
56
57 // parasoft-begin-suppress AUTOSAR-M11_0_1-a "This is part of the C++14 standard API"
58 /// @brief The first value
59 first_type first;
60 /// @brief The second value
61 second_type second;
62 // parasoft-end-suppress AUTOSAR-M11_0_1-a
63
64 private:
65 /// @brief Check if the memberwise copy constructor should be explicit
66 /// @tparam Arg1 The type of the initializer for first argument
67 /// @tparam Arg2 The type of the initializer for second argument
68 template <typename Arg1, typename Arg2>
69 static constexpr bool
70 memberwise_copy_constructor_is_explicit{!is_convertible_v<Arg1 const&, Arg1> || !is_convertible_v<Arg2 const&, Arg2>};
71
72 /// @brief Check if the memberwise forward constructor should be explicit
73 /// @tparam Arg1 The type of the initializer for first argument
74 /// @tparam Arg2 The type of the initializer for second argument
75 template <typename Arg1, typename Arg2>
76 static constexpr bool
77 memberwise_forward_constructor_is_explicit{!is_convertible_v<Arg1&&, first_type> || !is_convertible_v<Arg2&&, second_type>};
78
79 /// @brief Check if the copy constructor should be explicit
80 /// @tparam Arg1 The type of the initializer for first argument
81 /// @tparam Arg2 The type of the initializer for second argument
82 template <typename Arg1, typename Arg2>
83 static constexpr bool
85
86 /// @brief Check if the move constructor should be explicit
87 /// @tparam Arg1 The type of the initializer for first argument
88 /// @tparam Arg2 The type of the initializer for second argument
89 template <typename Arg1, typename Arg2>
90 static constexpr bool
92
93 public:
94 // parasoft-begin-suppress AUTOSAR-A12_7_1-a "False positive: Not equivalent, ensures members are value-initialized"
95 /// @brief Default construct a @c pair, with the @c first and @c second members value-initialized.
96 ///
97 /// This is disabled if either @c T1 or @c T2 is not default-constructible
98 /// @tparam CheckType1 Template parameter used for checking constraints on @c T1
99 /// @tparam CheckType2 Template parameter used for checking constraints on @c T2
100 template <
101 typename CheckType1 = T1,
102 typename CheckType2 = T2,
107 : first{},
108 second{} {}
109 // parasoft-end-suppress AUTOSAR-A12_7_1-a
110
111 // parasoft-begin-suppress AUTOSAR-A13_3_1-a "This is part of the C++14 standard API"
112 /// @brief Construct a @c pair from specified values for the two data members.
113 ///
114 /// This is disabled if either @c T1 or @c T2 is not copy-constructible
115 /// @tparam CheckType1 Template parameter used for checking constraints on @c T1
116 /// @tparam CheckType2 Template parameter used for checking constraints on @c T2
117 /// @param val1 The value to use to initialize @c first
118 /// @param val2 The value to use to initialize @c second
119 ///
120 /// @note The constructor is explicit if and only if <tt> is_convertible<const first_type&, first_type>::value </tt>
121 /// is false or <tt> is_convertible<const second_type&, second_type>::value </tt> is false.
122 template <
123 typename CheckType1 = T1,
124 typename CheckType2 = T2,
129 explicit constexpr pair(
130 first_type const& val1,
131 second_type const& val2
133 : first(val1),
134 second(val2) {}
135 // parasoft-end-suppress AUTOSAR-A13_3_1-a
136
137 // parasoft-begin-suppress AUTOSAR-A13_3_1-a "This is part of the C++14 standard API"
138 /// @brief Construct a @c pair from specified values for the two data members.
139 ///
140 /// This is disabled if either @c T1 or @c T2 is not copy-constructible
141 /// @tparam CheckType1 Template parameter used for checking constraints on @c T1
142 /// @tparam CheckType2 Template parameter used for checking constraints on @c T2
143 /// @param val1 The value to use to initialize @c first
144 /// @param val2 The value to use to initialize @c second
145 ///
146 /// @note The constructor is explicit if and only if <tt> is_convertible<const first_type&, first_type>::value </tt>
147 /// is false or <tt> is_convertible<const second_type&, second_type>::value </tt> is false.
148 template <
149 typename CheckType1 = T1,
150 typename CheckType2 = T2,
155 constexpr pair(
156 first_type const& val1,
157 second_type const& val2
159 : first(val1),
160 second(val2) {}
161 // parasoft-end-suppress AUTOSAR-A13_3_1-a
162
163 /// @brief Construct a @c pair from specified values for the two data members using perfect forwarding.
164 ///
165 /// This is disabled if either @c T1 or @c T2 is not constructible from the corresponding initializer.
166 /// @tparam Arg1 The type of the initializer for @c first
167 /// @tparam Arg2 The type of the initializer for @c second
168 /// @param val1 The value to use to initialize @c first
169 /// @param val2 The value to use to initialize @c second
170 ///
171 /// @note The constructor is explicit if and only if <tt> is_convertible<Arg1&&, first_type>::value </tt> is false or
172 /// <tt> is_convertible<Arg2&&, second_type>::value </tt> is false.
173 template <
174 typename Arg1,
175 typename Arg2,
180 explicit constexpr pair(
181 Arg1&& val1,
182 Arg2&& val2
184 : first(std::forward<Arg1>(val1)),
185 second(std::forward<Arg2>(val2)) {}
186
187 /// @brief Construct a @c pair from specified values for the two data members using perfect forwarding.
188 ///
189 /// This is disabled if either @c T1 or @c T2 is not constructible from the corresponding initializer.
190 /// @tparam Arg1 The type of the initializer for @c first
191 /// @tparam Arg2 The type of the initializer for @c second
192 /// @param val1 The value to use to initialize @c first
193 /// @param val2 The value to use to initialize @c second
194 ///
195 /// @note The constructor is explicit if and only if <tt> is_convertible<Arg1&&, first_type>::value </tt> is false or
196 /// <tt> is_convertible<Arg2&&, second_type>::value </tt> is false.
197 template <
198 typename Arg1,
199 typename Arg2,
204 constexpr pair(
205 Arg1&& val1,
206 Arg2&& val2
208 : first(std::forward<Arg1>(val1)),
209 second(std::forward<Arg2>(val2)) {}
210
211 /// @brief Copy a @c pair from another pair with potentially different value types
212 ///
213 /// This is disabled if either @c T1 or @c T2 is not constructible from the corresponding initializer.
214 /// @tparam Arg1 The type of @c first in the source pair
215 /// @tparam Arg2 The type of @c second in the source pair
216 /// @param other The pair to initialize from
217 ///
218 /// @note The constructor is explicit if and only if <tt> is_convertible<const Arg1&, first_type>::value </tt> is
219 /// false or <tt> is_convertible<const Arg2&, second_type>::value </tt> is false.
220 template <
221 typename Arg1,
222 typename Arg2,
227 explicit constexpr pair(pair<Arg1, Arg2> const& other
229 : pair(other.first, other.second) {}
230
231 /// @brief Copy a @c pair from another pair with potentially different value types
232 ///
233 /// This is disabled if either @c T1 or @c T2 is not constructible from the corresponding initializer.
234 /// @tparam Arg1 The type of @c first in the source pair
235 /// @tparam Arg2 The type of @c second in the source pair
236 /// @param other The pair to initialize from
237 ///
238 /// @note The constructor is explicit if and only if <tt> is_convertible<const Arg1&, first_type>::value </tt> is
239 /// false or <tt> is_convertible<const Arg2&, second_type>::value </tt> is false.
240 template <
241 typename Arg1,
242 typename Arg2,
247 // NOLINTNEXTLINE(hicpp-explicit-conversions)
248 constexpr pair(pair<Arg1, Arg2> const& other
250 : pair(other.first, other.second) {}
251
252 // parasoft-begin-suppress AUTOSAR-A8_4_6-a "False positive: Fields are forwarded"
253 // parasoft-begin-suppress AUTOSAR-A8_4_5-a "False positive: Fields are forwarded"
254 // parasoft-begin-suppress AUTOSAR-A12_8_4-a "False positive: Fields are forwarded"
255 // parasoft-begin-suppress AUTOSAR-A18_9_2-a "False positive: Forwarding fields"
256 /// @brief Move-construct a @c pair from another pair with potentially different value types
257 ///
258 /// This is disabled if either @c T1 or @c T2 is not constructible from the corresponding initializer.
259 /// @tparam Arg1 The type of @c first in the source pair
260 /// @tparam Arg2 The type of @c second in the source pair
261 /// @param other The pair to initialize from
262 ///
263 /// @note The constructor is explicit if and only if <tt> is_convertible<Arg1&&, first_type>::value </tt> is false or
264 /// <tt> is_convertible<Arg2&&, second_type>::value </tt> is false.
265 template <
266 typename Arg1,
267 typename Arg2,
272 explicit constexpr pair(pair<Arg1, Arg2>&& other
274 : first(std::forward<Arg1>(other.first)),
275 second(std::forward<Arg2>(other.second)) {}
276 // parasoft-end-suppress AUTOSAR-A18_9_2-a
277 // parasoft-end-suppress AUTOSAR-A8_4_6-a
278 // parasoft-end-suppress AUTOSAR-A8_4_5-a
279 // parasoft-end-suppress AUTOSAR-A12_8_4-a
280
281 // parasoft-begin-suppress AUTOSAR-A8_4_6-a "False positive: Fields are forwarded"
282 // parasoft-begin-suppress AUTOSAR-A8_4_5-a "False positive: Fields are forwarded"
283 // parasoft-begin-suppress AUTOSAR-A12_8_4-a "False positive: Fields are forwarded"
284 // parasoft-begin-suppress AUTOSAR-A18_9_2-a "False positive: Forwarding fields"
285 /// @brief Move-construct a @c pair from another pair with potentially different value types
286 ///
287 /// This is disabled if either @c T1 or @c T2 is not constructible from the corresponding initializer.
288 /// @tparam Arg1 The type of @c first in the source pair
289 /// @tparam Arg2 The type of @c second in the source pair
290 /// @param other The pair to initialize from
291 ///
292 /// @note The constructor is explicit if and only if <tt> is_convertible<Arg1&&, first_type>::value </tt> is false or
293 /// <tt> is_convertible<Arg2&&, second_type>::value </tt> is false.
294 template <
295 typename Arg1,
296 typename Arg2,
301 // NOLINTNEXTLINE(hicpp-explicit-conversions)
302 constexpr pair(pair<Arg1, Arg2>&& other
304 : first(std::forward<Arg1>(other.first)),
305 second(std::forward<Arg2>(other.second)) {}
306 // parasoft-end-suppress AUTOSAR-A18_9_2-a
307 // parasoft-end-suppress AUTOSAR-A8_4_6-a
308 // parasoft-end-suppress AUTOSAR-A8_4_5-a
309 // parasoft-end-suppress AUTOSAR-A12_8_4-a
310
311 private:
312 // parasoft-begin-suppress AUTOSAR-A0_1_4-a "False positive: The parameters are used"
313 // parasoft-begin-suppress AUTOSAR-A2_7_3-b "False positive: The parameters are documented with @brief"
314 // parasoft-begin-suppress AUTOSAR-A18_9_2-a "The type stored in the tuple is defined to be forwarded."
315 /// @brief Helper constructor for piecewise construction
316 /// @tparam Args1 The types of arguments in the tuple for constructing @c first
317 /// @tparam Args2 The types of arguments in the tuple for constructing @c second
318 /// @tparam I1 Indices for the first tuple arguments
319 /// @tparam I2 Indices for the second tuple arguments
320 /// @param first_args Tuple containing arguments to construct @c first
321 /// @param second_args Tuple containing arguments to construct @c second
322 template <typename... Args1, typename... Args2, size_t... I1, size_t... I2>
323 pair(tuple<Args1...>& first_args,index_sequence<I1...>, tuple<Args2...>& second_args, //
325 noexcept(is_nothrow_constructible_v<T1, Args1&&...> && is_nothrow_constructible_v<T2, Args2&&...>)
326 : first{std::forward<Args1>(get<I1>(first_args))...},
327 second{std::forward<Args2>(get<I2>(second_args))...} {}
328 // parasoft-end-suppress AUTOSAR-A18_9_2-a
329 // parasoft-end-suppress AUTOSAR-A2_7_3-b
330 // parasoft-end-suppress AUTOSAR-A0_1_4-a
331
332 public:
333 // parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters"
334 /// @brief Construct a @c pair using piecewise construction from tuples of arguments
335 ///
336 /// This constructor allows constructing each element from a tuple of arguments using perfect forwarding.
337 /// This is disabled if either @c T1 is not constructible from @c Args1&&... or @c T2 is not constructible from @c
338 /// Args2&&...
339 /// @tparam Args1 The types of arguments in the tuple for constructing @c first
340 /// @tparam Args2 The types of arguments in the tuple for constructing @c second
341 /// @param first_args Tuple containing arguments to construct @c first
342 /// @param second_args Tuple containing arguments to construct @c second
343 template <
344 typename... Args1,
345 typename... Args2,
347 enable_if_t<is_constructible_v<T1, Args1&&...>>,
348 enable_if_t<is_constructible_v<T2, Args2&&...>>> = nullptr>
349 pair(
350 piecewise_construct_t,
351 tuple<Args1...> first_args,
352 tuple<Args2...> second_args
353 ) noexcept(is_nothrow_constructible_v<T1, Args1&&...> && is_nothrow_constructible_v<T2, Args2&&...>)
354 : pair{first_args, index_sequence_for<Args1...>{}, second_args, index_sequence_for<Args2...>{}} {}
355 // parasoft-end-suppress CERT_C-EXP37-a
356
357 // parasoft-begin-suppress AUTOSAR-A12_8_6-a "The assignment operator should
358 // *not* be protected as 'pair' is not guaranteed to be a base class"
359 /// @brief Copy-assign a @c pair from another pair with different value types
360 ///
361 /// This is disabled if either @c T1 or @c T2 is not assignable from the corresponding initializer.
362 /// @tparam Arg1 The type of @c first in the source pair
363 /// @tparam Arg2 The type of @c second in the source pair
364 /// @param other The pair to copy from
365 /// @return @c *this
366 template <
367 typename Arg1,
368 typename Arg2,
373 auto operator=(pair<Arg1, Arg2> const& other
375 first = other.first;
376 second = other.second;
377 return *this;
378 }
379 // parasoft-end-suppress AUTOSAR-A12_8_6-a
380
381 // parasoft-begin-suppress AUTOSAR-A12_8_6-a "The assignment operator should
382 // *not* be protected as 'pair' is not guaranteed to be a base class"
383 // parasoft-begin-suppress AUTOSAR-A8_4_6-a "False positive: Fields are forwarded"
384 // parasoft-begin-suppress AUTOSAR-A8_4_5-a "False positive: Fields are forwarded"
385 // parasoft-begin-suppress AUTOSAR-A12_8_4-a "False positive: Fields are forwarded"
386 // parasoft-begin-suppress AUTOSAR-A18_9_2-a "False positive: Forwarding fields"
387 /// @brief Move-assign a @c pair from another pair with different value types
388 ///
389 /// This is disabled if either @c T1 or @c T2 is not assignable from the corresponding initializer.
390 /// @tparam Arg1 The type of @c first in the source pair
391 /// @tparam Arg2 The type of @c second in the source pair
392 /// @param other The pair to move from
393 /// @return @c *this
394 template <
395 typename Arg1,
396 typename Arg2,
401 auto operator=(pair<Arg1, Arg2>&& other
403 first = std::forward<Arg1>(other.first);
404 second = std::forward<Arg2>(other.second);
405 return *this;
406 }
407 // parasoft-end-suppress AUTOSAR-A18_9_2-a
408 // parasoft-end-suppress AUTOSAR-A8_4_6-a
409 // parasoft-end-suppress AUTOSAR-A8_4_5-a
410 // parasoft-end-suppress AUTOSAR-A12_8_4-a
411 // parasoft-end-suppress AUTOSAR-A12_8_6-a
412
413 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: identifier 'swap' does not hide anything"
414 /// @brief Swap a @c pair with another instance of the same type. Swaps @c first with @c other.first and swaps @c
415 /// second with @c other.second
416 ///
417 /// This is disabled if either @c T1 or @c T2 is not swappable
418 /// @param other The pair to swap with
419 template <
420 typename CheckType1 = T1,
421 typename CheckType2 = T2,
425 void swap(pair& other
427 using std::swap;
428 swap(first, other.first);
429 swap(second, other.second);
430 }
431};
432// parasoft-end-suppress AUTOSAR-A2_10_1-d
433
434// parasoft-begin-suppress AUTOSAR-A13_5_5-b-2 "Conditionally noexcept based on underlying comparison"
435// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: Inline function for use in multiple translation units"
436/// @brief Swap a @c pair with another instance of the same type. Swaps @c lhs.first with @c rhs.first and swaps @c
437/// lhs.second with @c rhs.second
438///
439/// This is disabled if either @c T1 or @c T2 is not swappable
440/// @param lhs The first pair to swap
441/// @param rhs The second pair to swap
442template <
443 typename T1,
444 typename T2,
446 enable_if_t<arene::base::is_swappable_v<T1>>,
447 enable_if_t<arene::base::is_swappable_v<T2>>> = nullptr>
448void swap(
449 pair<T1, T2>& lhs,
450 pair<T1, T2>& rhs
452 lhs.swap(rhs);
453}
454// parasoft-end-suppress AUTOSAR-M3_3_2-a
455// parasoft-end-suppress AUTOSAR-A13_5_5-b-2
456
457// parasoft-begin-suppress AUTOSAR-A13_5_5-b-2 "Conditionally noexcept based on underlying comparison"
458// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: Inline function for use in multiple translation units"
459/// @brief Compare two pairs to see if the first is less than the second. Uses lexicographical ordering based on the
460/// less-than comparisons of the members.
461/// @tparam T1 The type of the first data member of the pairs being compared
462/// @tparam T2 The type of the second data member of the pairs being compared
463/// @param lhs The first pair to compare
464/// @param rhs The second pair to compare
465/// @return @c true if @c lhs is less than @c rhs, @c false otherwise
466/// @pre @c T1 and @c T2 must have less than operators that provide a strict weak ordering
467template <typename T1, typename T2>
468constexpr auto operator<(
469 pair<T1, T2> const& lhs,
470 pair<T1, T2> const& rhs
472 -> bool {
473 return (lhs.first < rhs.first) || ((!(rhs.first < lhs.first)) && (lhs.second < rhs.second));
474}
475// parasoft-end-suppress AUTOSAR-M3_3_2-a
476// parasoft-end-suppress AUTOSAR-A13_5_5-b-2
477
478// parasoft-begin-suppress AUTOSAR-A13_5_5-b-2 "Conditionally noexcept based on underlying comparison"
479// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: Inline function for use in multiple translation units"
480/// @brief Compare two pairs to see if the first is greater than the second. Uses lexicographical ordering based on
481/// the less-than comparisons of the members.
482/// @tparam T1 The type of the first data member of the pairs being compared
483/// @tparam T2 The type of the second data member of the pairs being compared
484/// @param lhs The first pair to compare
485/// @param rhs The second pair to compare
486/// @return @c true if @c lhs is greater than @c rhs, @c false otherwise
487/// @pre @c T1 and @c T2 must have less than operators that provide a strict weak ordering
488template <typename T1, typename T2>
489constexpr auto operator>(
490 pair<T1, T2> const& lhs,
491 pair<T1, T2> const& rhs
493 -> bool {
494 return rhs < lhs;
495}
496// parasoft-end-suppress AUTOSAR-M3_3_2-a
497// parasoft-end-suppress AUTOSAR-A13_5_5-b-2
498
499// parasoft-begin-suppress AUTOSAR-A13_5_5-b-2 "Conditionally noexcept based on underlying comparison"
500// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: Inline function for use in multiple translation units"
501/// @brief Compare two pairs to see if the first is less than or equal to the second. Uses lexicographical ordering
502/// based on the less-than comparisons of the members.
503/// @tparam T1 The type of the first data member of the pairs being compared
504/// @tparam T2 The type of the second data member of the pairs being compared
505/// @param lhs The first pair to compare
506/// @param rhs The second pair to compare
507/// @return @c true if @c lhs is less than or equal to @c rhs, @c false otherwise
508/// @pre @c T1 and @c T2 must have less than operators that provide a strict weak ordering
509template <typename T1, typename T2>
510constexpr auto operator<=(
511 pair<T1, T2> const& lhs,
512 pair<T1, T2> const& rhs
514 -> bool {
515 return !(rhs < lhs);
516}
517// parasoft-end-suppress AUTOSAR-M3_3_2-a
518// parasoft-end-suppress AUTOSAR-A13_5_5-b-2
519
520// parasoft-begin-suppress AUTOSAR-A13_5_5-b-2 "Conditionally noexcept based on underlying comparison"
521// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: Inline function for use in multiple translation units"
522/// @brief Compare two pairs to see if the first is greater than or equal to the second. Uses lexicographical ordering
523/// based on the less-than comparisons of the members.
524/// @tparam T1 The type of the first data member of the pairs being compared
525/// @tparam T2 The type of the second data member of the pairs being compared
526/// @param lhs The first pair to compare
527/// @param rhs The second pair to compare
528/// @return @c true if @c lhs is greater than or equal to @c rhs, @c false otherwise
529/// @pre @c T1 and @c T2 must have less than operators that provide a strict weak ordering
530template <typename T1, typename T2>
531constexpr auto operator>=(
532 pair<T1, T2> const& lhs,
533 pair<T1, T2> const& rhs
535 -> bool {
536 return !(lhs < rhs);
537}
538// parasoft-end-suppress AUTOSAR-M3_3_2-a
539// parasoft-end-suppress AUTOSAR-A13_5_5-b-2
540
541// parasoft-begin-suppress AUTOSAR-A13_5_5-b-2 "Conditionally noexcept based on underlying comparison"
542// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: Inline function for use in multiple translation units"
543/// @brief Compare two pairs to see if they are equal, by checking if both members of the first are equal to the
544/// corresponding members of the second using the equality comparison operators of the members.
545/// @tparam T1 The type of the first data member of the pairs being compared
546/// @tparam T2 The type of the second data member of the pairs being compared
547/// @param lhs The first pair to compare
548/// @param rhs The second pair to compare
549/// @return @c true if @c lhs is equal to @c rhs, @c false otherwise
550/// @pre @c T1 and @c T2 must have equality operators that provide an equivalency comparison
551template <typename T1, typename T2>
552constexpr auto operator==(
553 pair<T1, T2> const& lhs,
554 pair<T1, T2> const& rhs
556 -> bool {
557 return (lhs.first == rhs.first) && (lhs.second == rhs.second);
558}
559// parasoft-end-suppress AUTOSAR-M3_3_2-a
560// parasoft-end-suppress AUTOSAR-A13_5_5-b-2
561
562// parasoft-begin-suppress AUTOSAR-A13_5_5-b-2 "Conditionally noexcept based on underlying comparison"
563// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: Inline function for use in multiple translation units"
564/// @brief Compare two pairs to see if the first is not equal to the second. Uses the equality comparison operators of
565/// the members.
566/// @tparam T1 The type of the first data member of the pairs being compared
567/// @tparam T2 The type of the second data member of the pairs being compared
568/// @param lhs The first pair to compare
569/// @param rhs The second pair to compare
570/// @return @c true if @c lhs is not equal to @c rhs, @c false otherwise
571/// @pre @c T1 and @c T2 must have equality operators that provide an equivalency comparison
572template <typename T1, typename T2>
573constexpr auto operator!=(
574 pair<T1, T2> const& lhs,
575 pair<T1, T2> const& rhs
577 -> bool {
578 return !(lhs == rhs);
579}
580// parasoft-end-suppress AUTOSAR-M3_3_2-a
581// parasoft-end-suppress AUTOSAR-A13_5_5-b-2
582
583namespace pair_detail {
584
585/// @brief Internal helper to deduce the expected @c std::pair type
586/// @tparam T1 The first argument type given to @c std::make_pair
587/// @tparam T2 The second argument type given to @c std::make_pair
588template <class T1, class T2>
589using deduced_pair_type_t = pair<::arene::base::unwrap_ref_decay_t<T1>, ::arene::base::unwrap_ref_decay_t<T2>>;
590
591} // namespace pair_detail
592
593// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
594// parasoft-begin-suppress AUTOSAR-A0_1_4-a "False positive: The parameters are used"
595// parasoft-begin-suppress AUTOSAR-A8_4_2-a "False positive: This function does return a value"
596// parasoft-begin-suppress CERT_C-MSC37-a "False positive: This function does return a value"
597// parasoft-begin-suppress CERT_CPP-MSC52-a "False positive: This function does return a value"
598/// @brief Creates a @c std::pair object, deducing the target type from the types of arguments
599/// @tparam T1 The first argument type
600/// @tparam T2 The second argument type
601/// @param first The first argument
602/// @param second The second argument
603///
604/// Given types @c std::decay<T1>::type as @c U1 and @c std::decay<T2>::type as @c U2, the types @c V1 and @c V2 are
605/// defined as follows:
606///
607/// If @c U1 is @c std::reference_wrapper<X>, @c V1 is @c X&; otherwise @c V1 is @c U1.
608/// If @c U2 is @c std::reference_wrapper<Y>, @c V2 is @c Y&; otherwise @c V2 is @c U2.
609/// @return <tt> std::pair<V1, V2>(std::forward<T1>(x), std::forward<T2>(y)) </tt>
610template <class T1, class T2>
618// parasoft-end-suppress CERT_CPP-MSC52-a
619// parasoft-end-suppress CERT_C-MSC37-a
620// parasoft-end-suppress AUTOSAR-A8_4_2-a
621// parasoft-end-suppress AUTOSAR-A0_1_4-a
622// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
623
624// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
625
626namespace pair_detail {
627
628// parasoft-begin-suppress AUTOSAR-A7_5_1-a "Temporary objects are handled by an overload that forwards the reference
629// category, not the const-ref overload"
630
631/// @brief access an element of a @c pair
632/// @tparam Pair specialization of @c pair
633/// @param values lvalue or rvalue reference to a @c pair
634/// @return reference to the first element in @c values
635///
636template <class Pair>
637constexpr auto get_impl(integral_constant<size_t, 0>, Pair&& values) noexcept
638 -> decltype((std::forward<Pair>(values).first)) {
639 return std::forward<Pair>(values).first;
640}
641
642/// @brief access an element of a @c pair
643/// @tparam Pair specialization of @c pair
644/// @param values lvalue or rvalue reference to a @c pair
645/// @return reference to the second element in @c values
646///
647template <class Pair>
648constexpr auto get_impl(integral_constant<size_t, 1>, Pair&& values) noexcept
649 -> decltype((std::forward<Pair>(values).second)) {
650 return std::forward<Pair>(values).second;
651}
652
653// parasoft-end-suppress AUTOSAR-A7_5_1-a
654
655} // namespace pair_detail
656
657/// @brief access an element of a @c pair
658/// @tparam I index of the element to access
659/// @tparam T1 first pair type
660/// @tparam T2 second pair type
661/// @param values reference to a @c pair
662/// @return reference to a value in @c values
663/// @note ill-formed if <tt> I >= 2 </tt>
664template <size_t I, class T1, class T2>
665constexpr auto get(pair<T1, T2>& values) noexcept -> tuple_element_t<I, pair<T1, T2>>& {
667}
668
669/// @brief access an element of a @c pair
670/// @tparam I index of the element to access
671/// @tparam T1 first pair type
672/// @tparam T2 second pair type
673/// @param values reference to a @c pair
674/// @return reference to a value in @c values
675/// @note ill-formed if <tt> I >= 2 </tt>
676template <size_t I, class T1, class T2>
677constexpr auto get(pair<T1, T2> const& values) noexcept -> tuple_element_t<I, pair<T1, T2>> const& {
679}
680
681/// @brief access an element of a @c pair
682/// @tparam I index of the element to access
683/// @tparam T1 first pair type
684/// @tparam T2 second pair type
685/// @param values reference to a @c pair
686/// @return reference to a value in @c values
687/// @note ill-formed if <tt> I >= 2 </tt>
688template <size_t I, class T1, class T2>
689constexpr auto get(pair<T1, T2>&& values) noexcept -> tuple_element_t<I, pair<T1, T2>>&& {
691}
692
693// parasoft-begin-suppress AUTOSAR-A18_9_3-a "We want to ensure the qualifier is preserved"
694/// @brief access an element of a @c pair
695/// @tparam I index of the element to access
696/// @tparam T1 first pair type
697/// @tparam T2 second pair type
698/// @param values reference to a @c pair
699/// @return reference to a value in @c values
700/// @note ill-formed if <tt> I >= 2 </tt>
701template <size_t I, class T1, class T2>
702constexpr auto get(pair<T1, T2> const&& values) noexcept -> tuple_element_t<I, pair<T1, T2>> const&& {
704}
705// parasoft-end-suppress AUTOSAR-A18_9_3-a
706
707/// @brief access an element of a @c pair
708/// @tparam T1 first pair type
709/// @tparam T2 second pair type
710/// @param values reference to a @c pair
711/// @return reference to a value in @c values
712/// @note ill-formed if <tt> std::is_same<T1, T2>::value </tt> is <tt> true </tt>
713template <class T1, class T2>
714constexpr auto get(pair<T1, T2>& values) noexcept -> T1& {
715 return values.first;
716}
717
718// parasoft-begin-suppress AUTOSAR-A7_5_1-a "Temporary objects are handled by an overload that forwards the reference
719// category, not the const-ref overload"
720
721/// @brief access an element of a @c pair
722/// @tparam T1 first pair type
723/// @tparam T2 second pair type
724/// @param values reference to a @c pair
725/// @return reference to a value in @c values
726/// @note ill-formed if <tt> std::is_same<T1, T2>::value </tt> is <tt> true </tt>
727template <class T1, class T2>
728constexpr auto get(pair<T1, T2> const& values) noexcept -> T1 const& {
729 return values.first;
730}
731
732// parasoft-end-suppress AUTOSAR-A7_5_1-a
733
734/// @brief access an element of a @c pair
735/// @tparam T1 first pair type
736/// @tparam T2 second pair type
737/// @param values reference to a @c pair
738/// @return reference to a value in @c values
739/// @note ill-formed if <tt> std::is_same<T1, T2>::value </tt> is <tt> true </tt>
740template <class T1, class T2>
741constexpr auto get(pair<T1, T2>&& values) noexcept -> T1&& {
742 return std::move(values.first);
743}
744
745// parasoft-begin-suppress AUTOSAR-A18_9_3-a "We want to ensure the qualifier is preserved"
746/// @brief access an element of a @c pair
747/// @tparam T1 first pair type
748/// @tparam T2 second pair type
749/// @param values reference to a @c pair
750/// @return reference to a value in @c values
751/// @note ill-formed if <tt> std::is_same<T1, T2>::value </tt> is <tt> true </tt>
752template <class T1, class T2>
753constexpr auto get(pair<T1, T2> const&& values) noexcept -> T1 const&& {
754 return std::move(values.first);
755}
756// parasoft-end-suppress AUTOSAR-A18_9_3-a
757
758/// @brief access an element of a @c pair
759/// @tparam T1 second pair type
760/// @tparam T2 second pair type
761/// The pair to access is passed as @c values.
762/// @cond CPPTEST_PARAMETER_DOCUMENTATION
763/// @param values The pair to access
764/// @endcond
765/// @return reference to a value in @c values
766/// @note ill-formed if <tt> std::is_same<T1, T2>::value </tt> is <tt> true </tt>
767template <class T2, class T1>
768constexpr auto get(pair<T1, T2>& values) noexcept -> T2& {
769 return values.second;
770}
771
772// parasoft-begin-suppress AUTOSAR-A7_5_1-a "Temporary objects are handled by an overload that forwards the reference
773// category, not the const-ref overload"
774
775/// @brief access an element of a @c pair
776/// @tparam T1 second pair type
777/// @tparam T2 second pair type
778/// The pair to access is passed as @c values.
779/// @cond CPPTEST_PARAMETER_DOCUMENTATION
780/// @param values The pair to access
781/// @endcond
782/// @return reference to a value in @c values
783/// @note ill-formed if <tt> std::is_same<T1, T2>::value </tt> is <tt> true </tt>
784template <class T2, class T1>
785constexpr auto get(pair<T1, T2> const& values) noexcept -> T2 const& {
786 return values.second;
787}
788
789// parasoft-end-suppress AUTOSAR-A7_5_1-a
790
791/// @brief access an element of a @c pair
792/// @tparam T1 second pair type
793/// @tparam T2 second pair type
794/// The pair to access is passed as @c values.
795/// @cond CPPTEST_PARAMETER_DOCUMENTATION
796/// @param values The pair to access
797/// @endcond
798/// @return reference to a value in @c values
799/// @note ill-formed if <tt> std::is_same<T1, T2>::value </tt> is <tt> true </tt>
800template <class T2, class T1>
801constexpr auto get(pair<T1, T2>&& values) noexcept -> T2&& {
802 return std::move(values.second);
803}
804
805// parasoft-begin-suppress AUTOSAR-A18_9_3-a "We want to ensure the qualifier is preserved"
806/// @brief access an element of a @c pair
807/// @tparam T1 second pair type
808/// @tparam T2 second pair type
809/// The pair to access is passed as @c values.
810/// @cond CPPTEST_PARAMETER_DOCUMENTATION
811/// @param values The pair to access
812/// @endcond
813/// @return reference to a value in @c values
814/// @note ill-formed if <tt> std::is_same<T1, T2>::value </tt> is <tt> true </tt>
815template <class T2, class T1>
816constexpr auto get(pair<T1, T2> const&& values) noexcept -> T2 const&& {
817 return std::move(values.second);
818}
819// parasoft-end-suppress AUTOSAR-A18_9_3-a
820
821// parasoft-end-suppress AUTOSAR-M3_3_2-a
822
823/// @brief obtain the first type of a @c pair
824/// @tparam T1 first pair type
825/// @tparam T2 second pair type
826template <class T1, class T2>
827class tuple_element<0, pair<T1, T2>> {
828 public:
829 /// @brief type at index 0
830 using type = T1;
831};
832
833/// @brief obtain the second type of a @c pair
834/// @tparam T1 first pair type
835/// @tparam T2 second pair type
836template <class T1, class T2>
837class tuple_element<1, pair<T1, T2>> {
838 public:
839 /// @brief type at index 1
840 using type = T2;
841};
842
843/// @brief obtain the size of a @c pair
844/// @tparam T1 first pair type
845/// @tparam T2 second pair type
846/// @note This is always 2
847template <class T1, class T2>
848class tuple_size<pair<T1, T2>> : public integral_constant<size_t, 2> {};
849
850} // namespace std
851
852#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_PAIR_HPP_
A helper class to represent a compile-time constant with the specified type and value....
Definition integral_constant.hpp:23
T1 type
type at index 0
Definition pair.hpp:830
T2 type
type at index 1
Definition pair.hpp:840
obtains the type of the specified element
Definition tuple_element.hpp:28
obtain the number of elements in a tuple-like type
Definition tuple_size.hpp:22
Public export header for the constraints subpackage.
constexpr bool is_nothrow_swappable_v
Trait query indicating if a type can be noexcept-swapped.
unwrap_reference_t< std::decay_t< T > > unwrap_ref_decay_t
Backport of std::unwrap_ref_decay_t from C++20.
Definition unwrap_reference.hpp:55
constexpr auto get(array< T, N > &arr) noexcept -> T &
Get a reference to the element at the specified index in the array.
Definition array.hpp:885
constexpr bool is_nothrow_equality_comparable_v
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
constexpr bool is_nothrow_less_than_comparable_v
Definition pair.hpp:583
pair<::arene::base::unwrap_ref_decay_t< T1 >, ::arene::base::unwrap_ref_decay_t< T2 > > deduced_pair_type_t
Internal helper to deduce the expected std::pair type.
Definition pair.hpp:589
constexpr auto get_impl(integral_constant< size_t, 0 >, Pair &&values) noexcept ->
access an element of a pair
Definition pair.hpp:637
STL namespace.
auto operator<=(move_iterator< Iterator1 > const &lhs, move_iterator< Iterator2 > const &rhs) -> bool
Check if one iterator is less than or equal to another.
Definition move_iterator.hpp:294
void swap(pair< T1, T2 > &lhs, pair< T1, T2 > &rhs) noexcept(arene::base::is_nothrow_swappable_v< T1 > &&arene::base::is_nothrow_swappable_v< T2 >)
Swap a pair with another instance of the same type. Swaps lhs.first with rhs.first and swaps lhs....
Definition pair.hpp:448
auto operator>=(move_iterator< Iterator1 > const &lhs, move_iterator< Iterator2 > const &rhs) -> bool
Check if one iterator is greater than or equal to another.
Definition move_iterator.hpp:316
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
auto operator!=(move_iterator< Iterator1 > const &lhs, move_iterator< Iterator2 > const &rhs) -> bool
Check if two iterators are not equal.
Definition move_iterator.hpp:271
constexpr bool is_same_v
Trait to detect if the two supplied types are the same or not. The value is true if the types are the...
integer_sequence< size_t, Ints... > index_sequence
A helper alias template for integer_sequence<size_t, Ints>
Definition integer_sequence.hpp:218
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 bool is_nothrow_assignable_v
Type trait to detect if an instance of To is assignable to from arguments of From without throwing.
auto operator<(move_iterator< Iterator1 > const &lhs, move_iterator< Iterator2 > const &rhs) -> bool
Check if one iterator is less than another.
Definition move_iterator.hpp:283
constexpr bool is_convertible_v
Type trait to detect if one type is convertible to another.
constexpr bool is_nothrow_constructible_v
Type trait to detect if a type is constructible from arguments of the specified types and is noexcept...
auto operator==(move_iterator< Iterator1 > const &lhs, move_iterator< Iterator2 > const &rhs) -> bool
Check if two iterators are equal.
Definition move_iterator.hpp:258
constexpr piecewise_construct_t piecewise_construct
Tag constant for piecewise construction.
Definition pair.hpp:42
constexpr bool is_nothrow_copy_constructible_v
Type trait to detect if an instance of T is copy constructible without throwing.
typename tuple_element< I, T >::type tuple_element_t
obtains the type of the specified element
Definition tuple_element.hpp:68
constexpr bool is_constructible_v
Type trait to detect if a type is constructible from arguments of the specified types.
constexpr auto get(pair< T1, T2 > &values) noexcept -> tuple_element_t< I, pair< T1, T2 > > &
access an element of a pair
Definition pair.hpp:665
make_index_sequence< sizeof...(Types)> index_sequence_for
A helper alias template convert any type parameter pack into an index sequence of the same length.
Definition integer_sequence.hpp:230
constexpr bool is_nothrow_default_constructible_v
Type trait to detect if an instance of T is default constructible without throwing.
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
auto operator>(move_iterator< Iterator1 > const &lhs, move_iterator< Iterator2 > const &rhs) -> bool
Check if one iterator is greater than another.
Definition move_iterator.hpp:305
Tag type for piecewise construction.
Definition pair.hpp:39