4#ifndef GREM_CORE_DATA_PAIR_HPP
5#define GREM_CORE_DATA_PAIR_HPP
20concept default_copy_list_initializable = std::is_default_constructible_v<T> &&
requires(void (*f)(
T)) { f({}); };
23concept boolean_testable_implementation = std::is_convertible_v<B, bool>;
26concept boolean_testable = boolean_testable_implementation<B> &&
requires(
B&& b) {
27 { !std::forward<B>(b) } -> boolean_testable_implementation;
30constexpr auto synthThreeWay = []<
typename T,
typename U>(
const T& t,
const U& u)
requires(
requires {
31 { t < u } -> boolean_testable;
32 { u < t } -> boolean_testable;
34 if constexpr (std::three_way_comparable_with<T, U>) {
38 return std::weak_ordering::less;
41 return std::weak_ordering::greater;
43 return std::weak_ordering::equivalent;
47template <
typename T,
typename U = T>
48using SynthThreeWayResult =
decltype(synthThreeWay(std::declval<T&>(), std::declval<U&>()));
52template <
typename T1,
typename T2 = T1>
60 constexpr explicit(!detail::default_copy_list_initializable<T1> || !detail::default_copy_list_initializable<T2>)
Pair()
61 requires(std::is_default_constructible_v<T1> && std::is_default_constructible_v<T2>)
65 constexpr explicit(!std::is_convertible_v<const T1&, T1> || !std::is_convertible_v<const T2&, T2>)
Pair(
const T1& x,
const T2&
y)
66 requires(std::is_copy_constructible_v<T1> && std::is_copy_constructible_v<T2>)
70 template <
typename U1,
typename U2>
71 constexpr explicit(!std::is_convertible_v<U1, T1> || !std::is_convertible_v<U2, T2>)
Pair(U1&& x, U2&&
y)
72 requires(std::is_constructible_v<T1, U1> && std::is_constructible_v<T2, U2>)
73 :
first(std::forward<U1>(x))
76 template <
typename U1,
typename U2>
77 constexpr explicit(!std::is_convertible_v<U1&, T1> || !std::is_convertible_v<U2&, T2>)
Pair(
Pair<U1, U2>&
p)
78 requires(std::is_constructible_v<T1, U1&> && std::is_constructible_v<T2, U2&>)
82 template <
typename U1,
typename U2>
83 constexpr explicit(!std::is_convertible_v<const U1&, T1> || !std::is_convertible_v<const U2&, T2>)
Pair(
const Pair<U1, U2>&
p)
84 requires(std::is_constructible_v<T1, const U1&> && std::is_constructible_v<T2, const U2&>)
88 template <
typename U1,
typename U2>
89 constexpr explicit(!std::is_convertible_v<U1, T1> || !std::is_convertible_v<U2, T2>)
Pair(
Pair<U1, U2>&&
p)
90 requires(std::is_constructible_v<T1, U1> && std::is_constructible_v<T2, U2>)
94 template <
typename... Args1,
typename... Args2>
95 constexpr Pair(std::piecewise_construct_t piecewiseConstruct, std::tuple<Args1...> firstArgs, std::tuple<Args2...> secondArgs)
96 :
Pair(piecewiseConstruct, firstArgs, std::make_index_sequence<sizeof...(Args1)>{}, secondArgs, std::make_index_sequence<
sizeof...(Args2)>{}) {}
103 constexpr Pair&
operator=(
const Pair& other)
requires(std::is_copy_assignable_v<T1> && std::is_copy_assignable_v<T2>) =
default;
104 constexpr Pair&
operator=(
const Pair& other)
requires(!std::is_copy_assignable_v<T1> || !std::is_copy_assignable_v<T2>) =
delete;
106 template <
typename U1,
typename U2>
107 constexpr Pair&
operator=(
const Pair<U1, U2>& other)
requires(std::is_assignable_v<T1&, const U1&> && std::is_assignable_v<T2&, const U2&>) {
113 constexpr Pair&
operator=(
Pair&& other)
noexcept(std::is_nothrow_move_assignable_v<T1> && std::is_nothrow_move_assignable_v<T2>)
114 requires(std::is_move_assignable_v<T1> && std::is_move_assignable_v<T2>) =
default;
116 template <
typename U1,
typename U2>
118 requires(std::is_assignable_v<T1&, U1> && std::is_assignable_v<T2&, U2>) {
119 first = std::forward<U1>(
p.first);
120 second = std::forward<U2>(
p.second);
123 constexpr void swap(
Pair& other)
noexcept(std::is_nothrow_swappable_v<T1> && std::is_nothrow_swappable_v<T2>) {
129 friend void swap(
Pair& a,
Pair& b)
noexcept(
noexcept(a.swap(b)))
requires(std::is_swappable_v<T1> && std::is_swappable_v<T2>) {
138 template <
typename... Args1,
typename... Args2, std::size_t... Indices1, std::size_t... Indices2>
139 constexpr Pair(std::piecewise_construct_t, std::tuple<Args1...>& firstArgs, std::index_sequence<Indices1...>, std::tuple<Args2...>& secondArgs,
140 std::index_sequence<Indices2...>)
141 :
first(std::forward<Args1>(std::
get<Indices1>(firstArgs))...)
142 ,
second(std::forward<Args2>(std::
get<Indices2>(secondArgs))...) {}
145template <
typename T1,
typename T2>
150template <
typename T1,
typename T2>
151struct std::tuple_size<
grem::Pair<T1, T2>> : std::integral_constant<std::size_t, 2> {};
153template <
typename T1,
typename T2>
154struct std::tuple_element<0,
grem::Pair<T1, T2>> {
158template <
typename T1,
typename T2>
159struct std::tuple_element<1,
grem::Pair<T1, T2>> {
163template <
typename T1,
typename T2,
typename U1,
typename U2>
168template <
typename T1,
typename T2,
typename U1,
typename U2,
template <
typename>
typename TQual,
template <
typename>
typename UQual>
176using std::tuple_element;
177using std::tuple_element_t;
178using std::tuple_size;
179using std::tuple_size_v;
181template <
typename T1,
typename T2,
typename U1,
typename U2>
186template <
typename T1,
typename T2,
typename U1,
typename U2>
187[[nodiscard]]
constexpr std::common_comparison_category_t<detail::SynthThreeWayResult<T1, U1>, detail::SynthThreeWayResult<T2, U2>>
operator<=>(
const Pair<T1, T2>& a,
189 std::common_comparison_category_t<detail::SynthThreeWayResult<T1, U1>, detail::SynthThreeWayResult<T2, U2>> result = a.
first <=> b.
first;
196template <
typename T1,
typename T2>
198 return {std::forward<T1>(x), std::forward<T2>(y)};
201template <std::
size_t Index,
typename T1,
typename T2>
202[[nodiscard]]
constexpr tuple_element_t<Index, Pair<T1, T2>>&
get(
Pair<T1, T2>& t)
noexcept {
203 static_assert(Index == 0 || Index == 1);
204 if constexpr (Index == 0) {
211template <std::
size_t Index,
typename T1,
typename T2>
212[[nodiscard]]
constexpr const tuple_element_t<Index, Pair<T1, T2>>&
get(
const Pair<T1, T2>& t)
noexcept {
213 static_assert(Index == 0 || Index == 1);
214 if constexpr (Index == 0) {
221template <std::
size_t Index,
typename T1,
typename T2>
222[[nodiscard]]
constexpr tuple_element_t<Index, Pair<T1, T2>>&&
get(
Pair<T1, T2>&& t)
noexcept {
223 static_assert(Index == 0 || Index == 1);
224 if constexpr (Index == 0) {
225 return std::move(t).first;
227 return std::move(t).second;
231template <std::
size_t Index,
typename T1,
typename T2>
232[[nodiscard]]
constexpr const tuple_element_t<Index, Pair<T1, T2>>&&
get(
const Pair<T1, T2>&& t)
noexcept {
233 static_assert(Index == 0 || Index == 1);
234 if constexpr (Index == 0) {
235 return std::move(t).first;
237 return std::move(t).second;
241template <
typename T,
typename U>
246template <
typename T,
typename U>
251template <
typename T,
typename U>
253 return std::move(t).first;
256template <
typename T,
typename U>
258 return std::move(t).first;
261template <
typename T,
typename U>
266template <
typename T,
typename U>
271template <
typename T,
typename U>
273 return std::move(t).second;
276template <
typename T,
typename U>
278 return std::move(t).second;
@ U
'u'
Definition keyboard.hpp:91
@ B
'b'
Definition keyboard.hpp:72
@ T
't'
Definition keyboard.hpp:90
constexpr tuple_element_t< Index, Pair< T1, T2 > > & get(Pair< T1, T2 > &t) noexcept
Definition Pair.hpp:202
constexpr Pair< std::unwrap_ref_decay_t< T1 >, std::unwrap_ref_decay_t< T2 > > make_pair(T1 &&x, T2 &&y)
Definition Pair.hpp:197
constexpr bool operator==(const Indirect< A, AllocatorA > &a, const Indirect< B, AllocatorB > &b)
Definition Indirect.hpp:246
Pair(T1, T2) -> Pair< T1, T2 >
constexpr std::compare_three_way_result_t< A, B > operator<=>(const Indirect< A, AllocatorA > &a, const Indirect< B, AllocatorB > &b)
Definition Indirect.hpp:273
constexpr ~Pair()=default
T second
Definition Pair.hpp:58
const Key first_type
Definition Pair.hpp:54
constexpr Pair(Pair &&p)=default
T second_type
Definition Pair.hpp:55
friend void swap(Pair &a, Pair &b) noexcept(noexcept(a.swap(b)))
Definition Pair.hpp:129
constexpr Pair(const Pair &p)=default
constexpr Pair(std::piecewise_construct_t piecewiseConstruct, std::tuple< Args1... > firstArgs, std::tuple< Args2... > secondArgs)
Definition Pair.hpp:95
constexpr U2 & p
Definition Pair.hpp:80
const Key first
Definition Pair.hpp:57
constexpr const T & y
Definition Pair.hpp:68
friend constexpr Pair< T2, T1 > reversed(const Pair &pair)
Definition Pair.hpp:133
constexpr Pair & operator=(const Pair &other)=delete
constexpr void swap(Pair &other) noexcept(std::is_nothrow_swappable_v< T1 > &&std::is_nothrow_swappable_v< T2 >)
Definition Pair.hpp:123
constexpr Pair & operator=(const Pair &other)=default
constexpr Pair & operator=(Pair &&other) noexcept(std::is_nothrow_move_assignable_v< T1 > &&std::is_nothrow_move_assignable_v< T2 >)=default
constexpr Pair & operator=(Pair< U1, U2 > &&p)
Definition Pair.hpp:117
constexpr Pair & operator=(const Pair< U1, U2 > &other)
Definition Pair.hpp:107
grem::Pair< std::common_reference_t< TQual< T1 >, UQual< U1 > >, std::common_reference_t< TQual< T2 >, UQual< U2 > > > type
Definition Pair.hpp:171
grem::Pair< std::common_type_t< T1, U1 >, std::common_type_t< T2, U2 > > type
Definition Pair.hpp:165
T1 type
Definition Pair.hpp:155
T2 type
Definition Pair.hpp:160