]> git.saurik.com Git - apple/xnu.git/blob - libkern/os/cpp_util.h
xnu-6153.141.1.tar.gz
[apple/xnu.git] / libkern / os / cpp_util.h
1 #ifndef _OS_CPP_UTIL_H
2 #define _OS_CPP_UTIL_H
3
4 #include <sys/cdefs.h>
5
6 #if __has_feature(cxx_nullptr) && __has_feature(cxx_decltype)
7 # define OS_HAS_NULLPTR 1
8 #endif
9
10 #if __has_feature(cxx_rvalue_references) || __has_extension(cxx_rvalue_references)
11 # define OS_HAS_RVALUE_REFERENCES 1
12 #endif
13
14 namespace os {
15 #if OS_HAS_NULLPTR
16 typedef decltype(nullptr) nullptr_t;
17 #endif
18
19 /*
20 * Reference removal
21 */
22
23 template <class _T> struct remove_reference {typedef _T type;};
24 template <class _T> struct remove_reference<_T&> {typedef _T type;};
25 template <class _T> struct remove_reference<_T &&> {typedef _T type;};
26 template <class _T> using remove_reference_t = typename remove_reference<_T>::type;
27
28 /*
29 * Const removal
30 */
31
32 template <class _T> struct remove_const {typedef _T type;};
33 template <class _T> struct remove_const<const _T> {typedef _T type;};
34 template <class _T> using remove_const_t = typename remove_const<_T>::type;
35
36 /*
37 * Move
38 */
39
40 template <class _T>
41 inline typename remove_reference<_T>::type &&
42 move(_T && _t)
43 {
44 typedef typename os::remove_reference<_T>::type _U;
45 return static_cast<_U &&>(_t);
46 }
47 }
48
49 #endif /* _OS_CPP_UTIL_H */