|
| 1 | +#ifndef __UTILITY__ |
| 2 | +#define __UTILITY__ |
| 3 | + |
| 4 | +#include <type_traits> |
| 5 | + |
| 6 | +namespace std { |
| 7 | + |
| 8 | +template <class T> |
| 9 | +constexpr T&& forward(std::remove_reference_t<T> &t) noexcept { |
| 10 | + return static_cast<T &&>(t); |
| 11 | +} |
| 12 | + |
| 13 | +template <class T> |
| 14 | +constexpr T&& forward(std::remove_reference_t<T> &&t) noexcept { |
| 15 | + return static_cast<T &&>(t); |
| 16 | +} |
| 17 | + |
| 18 | +template <class T1, class T2> |
| 19 | +struct pair { |
| 20 | + using first_type = T1; |
| 21 | + using second_type = T2; |
| 22 | + T1 first; |
| 23 | + T2 second; |
| 24 | + |
| 25 | + pair(const pair &p) = default; |
| 26 | + pair(pair &&p) = default; |
| 27 | + |
| 28 | + constexpr pair(const T1 &x, const T2 &y) : |
| 29 | + first(x), |
| 30 | + second(y) { |
| 31 | + } |
| 32 | + |
| 33 | + template <class U1 = T1, class U2 = T2> |
| 34 | + constexpr pair(U1 &&x, U2 &&y) : |
| 35 | + first(std::forward<U1>(x)), |
| 36 | + second(std::forward<U2>(y)) { |
| 37 | + } |
| 38 | + |
| 39 | + template <class U1, class U2> |
| 40 | + constexpr pair& operator=(const pair<U1, U2> &p) { |
| 41 | + first = p.first; |
| 42 | + second = p.second; |
| 43 | + return *this; |
| 44 | + } |
| 45 | + |
| 46 | + template <class U1, class U2> |
| 47 | + constexpr pair& operator=(pair<U1, U2> &&p) { |
| 48 | + first = std::forward<U1>(p.first); |
| 49 | + second = std::forward<U2>(p.second); |
| 50 | + return *this; |
| 51 | + } |
| 52 | +}; |
| 53 | + |
| 54 | +template <class T1, class T2> |
| 55 | +std::pair<T1, T2> make_pair(T1 x, T2 y) { |
| 56 | + return std::pair<T1, T2>(x, y); |
| 57 | +} |
| 58 | + |
| 59 | +} |
| 60 | + |
| 61 | +#endif // __UTILITY__ |
0 commit comments