-
Notifications
You must be signed in to change notification settings - Fork 1
/
utility.h
66 lines (52 loc) · 1.71 KB
/
utility.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once
#include "type_traits.h"
namespace firefly::std {
template <typename T>
constexpr remove_reference_t<T>&& move(T&& value) noexcept {
return static_cast<remove_reference_t<T>&&>(value);
};
template <typename T>
void swap(T& a, T& b) {
T temp = std::move(a);
a = std::move(b);
b = std::move(temp);
}
template <typename T>
constexpr T&& forward(typename remove_reference<T>::type& __t) noexcept {
return static_cast<T&&>(__t);
}
template <typename T>
constexpr T&& forward(typename remove_reference<T>::type&& __t) noexcept {
return static_cast<T&&>(__t);
}
// Pair implementation.
template <typename T1, class T2>
struct pair {
constexpr pair() {};
constexpr pair(T1 const& f, T2 const& s) : first { f }, second { s } {};
constexpr pair(T1&& f, T2&& s) : first { f }, second { s } {};
constexpr pair& operator=(const pair& other) {
first = other.first;
second = other.second;
}
template <typename U1, class U2>
constexpr pair& operator=(const pair<U1, U2>& other) {
first = other.first;
second = other.second;
}
constexpr pair& operator=(pair&& other) = default;
template <typename U1, class U2>
constexpr pair& operator=(pair<U1, U2>&& other) {
first = forward<U1>(other.first);
second = forward<U2>(other.second);
}
template <typename T>
void swap(T& one, T& two) {
auto temp = one;
one = two;
two = temp;
}
T1 first;
T2 second;
};
} // namespace firefly::std