| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak
|
|---|
| 3 | *
|
|---|
| 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #ifndef LIBCPP_BITS_TUPLE_TUPLE_OPS
|
|---|
| 8 | #define LIBCPP_BITS_TUPLE_TUPLE_OPS
|
|---|
| 9 |
|
|---|
| 10 | #include <utility>
|
|---|
| 11 |
|
|---|
| 12 | namespace std
|
|---|
| 13 | { // forward declarations
|
|---|
| 14 | template<class... Ts>
|
|---|
| 15 | struct tuple;
|
|---|
| 16 |
|
|---|
| 17 | template<size_t I, class T>
|
|---|
| 18 | struct tuple_element;
|
|---|
| 19 |
|
|---|
| 20 | template<size_t I, class... Ts>
|
|---|
| 21 | constexpr typename tuple_element<I, tuple<Ts...>>::type& get(tuple<Ts...>& tpl) noexcept;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | namespace std::aux
|
|---|
| 25 | {
|
|---|
| 26 | template<size_t I, size_t N>
|
|---|
| 27 | struct tuple_ops
|
|---|
| 28 | {
|
|---|
| 29 | template<class T, class U>
|
|---|
| 30 | static void assign_copy(T& lhs, const U& rhs)
|
|---|
| 31 | {
|
|---|
| 32 | get<I>(lhs) = get<I>(rhs);
|
|---|
| 33 |
|
|---|
| 34 | tuple_ops<I + 1, N>::assign_copy(lhs, rhs);
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | template<class T, class U>
|
|---|
| 38 | static void assign_move(T& lhs, U&& rhs)
|
|---|
| 39 | {
|
|---|
| 40 | get<I>(lhs) = move(get<I>(rhs));
|
|---|
| 41 |
|
|---|
| 42 | tuple_ops<I + 1, N>::assign_move(lhs, move(rhs));
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | template<class T, class U>
|
|---|
| 46 | static void swap(T& lhs, U& rhs)
|
|---|
| 47 | {
|
|---|
| 48 | std::swap(get<I>(lhs), get<I>(rhs));
|
|---|
| 49 |
|
|---|
| 50 | tuple_ops<I + 1, N>::swap(lhs, rhs);
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | template<class T, class U>
|
|---|
| 54 | static bool eq(const T& lhs, const U& rhs)
|
|---|
| 55 | {
|
|---|
| 56 | return (get<I>(lhs) == get<I>(rhs)) && tuple_ops<I + 1, N>::eq(lhs, rhs);
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | template<class T, class U>
|
|---|
| 60 | static bool lt(const T& lhs, const U& rhs)
|
|---|
| 61 | {
|
|---|
| 62 | return (get<I>(lhs) < get<I>(rhs)) ||
|
|---|
| 63 | (!(get<I>(rhs) < get<I>(lhs)) && tuple_ops<I + 1, N>::lt(lhs, rhs));
|
|---|
| 64 | }
|
|---|
| 65 | };
|
|---|
| 66 |
|
|---|
| 67 | template<size_t N>
|
|---|
| 68 | struct tuple_ops<N, N>
|
|---|
| 69 | {
|
|---|
| 70 | template<class T, class U>
|
|---|
| 71 | static void assign_copy(T& lhs, const U& rhs)
|
|---|
| 72 | {
|
|---|
| 73 | get<N>(lhs) = get<N>(rhs);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | template<class T, class U>
|
|---|
| 77 | static void assign_move(T& lhs, U&& rhs)
|
|---|
| 78 | {
|
|---|
| 79 | get<N>(lhs) = move(get<N>(rhs));
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | template<class T, class U>
|
|---|
| 83 | static void swap(T& lhs, U& rhs)
|
|---|
| 84 | {
|
|---|
| 85 | std::swap(get<N>(lhs), get<N>(rhs));
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | template<class T, class U>
|
|---|
| 89 | static bool eq(const T& lhs, const U& rhs)
|
|---|
| 90 | {
|
|---|
| 91 | return get<N>(lhs) == get<N>(rhs);
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | template<class T, class U>
|
|---|
| 95 | static bool lt(const T& lhs, const U& rhs)
|
|---|
| 96 | {
|
|---|
| 97 | return get<N>(lhs) < get<N>(rhs);
|
|---|
| 98 | }
|
|---|
| 99 | };
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | #endif
|
|---|