4#ifndef TETL_UTILITY_PAIR_HPP
5#define TETL_UTILITY_PAIR_HPP
7#include <etl/_tuple/is_tuple_like.hpp>
8#include <etl/_tuple/tuple_element.hpp>
9#include <etl/_tuple/tuple_size.hpp>
10#include <etl/_type_traits/common_reference.hpp>
11#include <etl/_type_traits/decay.hpp>
12#include <etl/_type_traits/integral_constant.hpp>
13#include <etl/_type_traits/is_assignable.hpp>
14#include <etl/_type_traits/is_constructible.hpp>
15#include <etl/_type_traits/is_convertible.hpp>
16#include <etl/_type_traits/is_copy_constructible.hpp>
17#include <etl/_type_traits/is_default_constructible.hpp>
18#include <etl/_type_traits/is_implicit_default_constructible.hpp>
19#include <etl/_type_traits/is_move_assignable.hpp>
20#include <etl/_type_traits/is_nothrow_swappable.hpp>
21#include <etl/_utility/forward.hpp>
22#include <etl/_utility/move.hpp>
23#include <etl/_utility/swap.hpp>
36template <
typename T1,
typename T2>
38 using first_type = T1;
39 using second_type = T2;
43 not is_implicit_default_constructible_v<T1> ||
not is_implicit_default_constructible_v<T2>
45 requires(is_default_constructible_v<T1>
and is_default_constructible_v<T2>)
54 )
constexpr pair(T1
const& t1, T2
const&
t2)
55 requires(is_copy_constructible_v<T1>
and is_copy_constructible_v<T2>)
62 template <
typename U1 = T1,
typename U2 = T2>
63 requires(is_constructible_v<T1, U1 &&>
and is_constructible_v<T2, U2 &&>)
71 template <
typename U1,
typename U2>
72 requires(is_constructible_v<T1, U1
const&>
and is_constructible_v<T2, U2
const&>)
82 template <
typename U1,
typename U2>
83 requires(is_constructible_v<T1, U1 &&>
and is_constructible_v<T2, U2 &&>)
99 ~
pair()
noexcept =
default;
103 template <
typename U1,
typename U2>
105 requires((is_assignable_v<first_type&, U1
const&>
and is_assignable_v<second_type&, U2
const&>))
113 requires(is_move_assignable_v<first_type>
and is_move_assignable_v<second_type>)
120 template <
typename U1,
typename U2>
121 requires(is_assignable_v<first_type&, U1>
and is_assignable_v<second_type&, U2>)
133 swap(
first, other.first);
134 swap(
second, other.second);
145template <
typename T1,
typename T2>
148template <
typename T,
typename U>
149inline constexpr auto is_tuple_like<etl::pair<T, U>> =
true;
152template <
typename T1,
typename T2>
166template <
typename T1,
typename T2>
167[[nodiscard]]
constexpr auto make_pair(T1&& t, T2&& u) ->
pair<decay_t<T1>, decay_t<T2>>
169 return {
etl::forward<T1>(t),
etl::forward<T2>(u)};
174template <
typename T1,
typename T2>
177 return (lhs.first == rhs.first)
and (lhs.second == rhs.second);
183template <
typename T1,
typename T2>
186 if (lhs.first < rhs.first) {
189 if (rhs.first < lhs.first) {
192 if (lhs.second < rhs.second) {
201template <
typename T1,
typename T2>
210template <
typename T1,
typename T2>
219template <
typename T1,
typename T2>
228template <
typename T1,
typename T2>
234template <size_t I,
typename T1,
typename T2>
235struct tuple_element<I,
pair<T1, T2>> {
236 static_assert(I < 2,
"pair index out of range");
237 using type = conditional_t<I == 0, T1, T2>;
245template <size_t I,
typename T1,
typename T2>
246constexpr auto get(
pair<T1, T2>& p)
noexcept -> tuple_element_t<I,
pair<T1, T2>>&
248 if constexpr (I == 0) {
260template <size_t I,
typename T1,
typename T2>
261[[nodiscard]]
constexpr auto get(
pair<T1, T2>
const& p)
noexcept -> tuple_element_t<I,
pair<T1, T2>>
const&
263 if constexpr (I == 0) {
275template <size_t I,
typename T1,
typename T2>
276[[nodiscard]]
constexpr auto get(
pair<T1, T2>&& p)
noexcept -> tuple_element_t<I,
pair<T1, T2>>&&
278 if constexpr (I == 0) {
279 return etl::move(p.first);
281 return etl::move(p.second);
290template <size_t I,
typename T1,
typename T2>
291[[nodiscard]]
constexpr auto get(
pair<T1, T2>
const&& p)
noexcept -> tuple_element_t<I,
pair<T1, T2>>
const&&
293 if constexpr (I == 0) {
294 return etl::move(p.first);
296 return etl::move(p.second);
305 template <
typename>
typename TQual,
306 template <
typename>
typename UQual
309 typename pair<common_reference_t<TQual<T1>, UQual<U1>>, common_reference_t<TQual<T2>, UQual<U2>>>;
312 using type =
pair<common_reference_t<TQual<T1>, UQual<U1>>, common_reference_t<TQual<T2>, UQual<U2>>>;
Definition adjacent_find.hpp:9
pair(T1, T2) -> pair< T1, T2 >
constexpr auto operator<(pair< T1, T2 > const &lhs, pair< T1, T2 > const &rhs) -> bool
Compares lhs and rhs lexicographically by operator<, that is, compares the first elements and only if...
Definition pair.hpp:184
constexpr auto get(pair< T1, T2 > const &p) noexcept -> tuple_element_t< I, pair< T1, T2 > > const &
Extracts an element from the pair using tuple-like interface.
Definition pair.hpp:261
constexpr auto operator==(pair< T1, T2 > const &lhs, pair< T1, T2 > const &rhs) -> bool
Tests if both elements of lhs and rhs are equal, that is, compares lhs.first with rhs....
Definition pair.hpp:175
constexpr auto operator<=(pair< T1, T2 > const &lhs, pair< T1, T2 > const &rhs) -> bool
Compares lhs and rhs lexicographically by operator<, that is, compares the first elements and only if...
Definition pair.hpp:202
constexpr auto swap(pair< T1, T2 > &lhs, pair< T1, T2 > &rhs) noexcept(noexcept(lhs.swap(rhs))) -> void
Swaps the contents of x and y. Equivalent to x.swap(y).
Definition pair.hpp:153
constexpr auto get(pair< T1, T2 > const &&p) noexcept -> tuple_element_t< I, pair< T1, T2 > > const &&
Extracts an element from the pair using tuple-like interface.
Definition pair.hpp:291
constexpr auto operator>=(pair< T1, T2 > const &lhs, pair< T1, T2 > const &rhs) -> bool
Compares lhs and rhs lexicographically by operator<, that is, compares the first elements and only if...
Definition pair.hpp:220
constexpr auto make_pair(T1 &&t, T2 &&u) -> pair< decay_t< T1 >, decay_t< T2 > >
Creates a etl::pair object, deducing the target type from the types of arguments.
Definition pair.hpp:167
constexpr auto get(pair< T1, T2 > &p) noexcept -> tuple_element_t< I, pair< T1, T2 > > &
Extracts an element from the pair using tuple-like interface.
Definition pair.hpp:246
constexpr auto operator>(pair< T1, T2 > const &lhs, pair< T1, T2 > const &rhs) -> bool
Compares lhs and rhs lexicographically by operator<, that is, compares the first elements and only if...
Definition pair.hpp:211
constexpr auto get(pair< T1, T2 > &&p) noexcept -> tuple_element_t< I, pair< T1, T2 > > &&
Extracts an element from the pair using tuple-like interface.
Definition pair.hpp:276
The class template basic_common_reference is a customization point that allows users to influence the...
Definition basic_common_reference.hpp:13
Definition integral_constant.hpp:10
etl::pair is a class template that provides a way to store two heterogeneous objects as a single unit...
Definition pair.hpp:37
U2 && y
Definition pair.hpp:66
explicit(not is_convertible_v< U1 &&, T1 >||not is_convertible_v< U2 &&, T2 >) const expr pair(pair< U1
Initializes first with forward<U1>(p.first) and second with forward<U2>(p.second).
T2 const & t2
Definition pair.hpp:57
U2 const & p
Definition pair.hpp:77
TETL_NO_UNIQUE_ADDRESS T2 second
Definition pair.hpp:138
U2 && p
Definition pair.hpp:86
TETL_NO_UNIQUE_ADDRESS T1 first
Definition pair.hpp:137
constexpr auto operator=(pair< U1, U2 > const &p) -> pair &requires((is_assignable_v< first_type &, U1 const & > and is_assignable_v< second_type &, U2 const & >))
Definition pair.hpp:104
explicit(not is_convertible_v< U1 const &, T1 > or not is_convertible_v< U2 const &, T2 >) const expr pair(pair< U1
Initializes first with p.first and second with p.second.
explicit(not is_convertible_v< U1 &&, T1 >||not is_convertible_v< U2 &&, T2 >) const expr pair(U1 &&x
Initializes first with forward<U1>(x) and second with forward<U2>(y).
constexpr auto operator=(pair const &p) -> pair &=default
constexpr auto operator=(pair &&p) noexcept -> pair &requires(is_move_assignable_v< first_type > and is_move_assignable_v< second_type >)
Definition pair.hpp:112
constexpr auto swap(pair &other) noexcept(is_nothrow_swappable_v< first_type > and is_nothrow_swappable_v< second_type >) -> void
Definition pair.hpp:130
explicit(not is_convertible_v< T1 const &, T1 > or not is_convertible_v< T2 const &, T2 >) const expr pair(T1 const &t1
Initializes first with x and second with y.
constexpr auto operator=(pair< U1, U2 > &&p) -> pair &
Definition pair.hpp:122
constexpr pair(pair const &p)=default
Copy constructor is defaulted, and is constexpr if copying of both elements satisfies the requirement...
~pair() noexcept=default
Defaulted destructor.
constexpr pair(pair &&p) noexcept=default
Move constructor is defaulted, and is constexpr if moving of both elements satisfies the requirements...