-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcpp_utility.h
More file actions
45 lines (38 loc) · 811 Bytes
/
cpp_utility.h
File metadata and controls
45 lines (38 loc) · 811 Bytes
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
#ifndef CPP_UTILITY_H
#define CPP_UTILITY_H
namespace utility {
// remove_reference
template <class T> struct remove_reference
{
using type = T;
};
template <class T> struct remove_reference<T&>
{
using type = T;
};
template <class T> struct remove_reference<T&&>
{
using type = T;
};
// move
template <class T>
constexpr typename remove_reference<T>::type&&
move(T&& t) noexcept
{
return static_cast<typename remove_reference<T>::type&&>(t);
}
// forward (optional, for perfect forwarding)
template <class T>
constexpr T&&
forward(typename remove_reference<T>::type& t) noexcept
{
return static_cast<T&&>(t);
}
template <class T>
constexpr T&&
forward(typename remove_reference<T>::type&& t) noexcept
{
return static_cast<T&&>(t);
}
} // namespace utility
#endif // CPP_UTILITY_H