]> git.saurik.com Git - apple/xnu.git/blame - libkern/os/cpp_util.h
xnu-6153.11.26.tar.gz
[apple/xnu.git] / libkern / os / cpp_util.h
CommitLineData
cb323159
A
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
14namespace os {
15#if OS_HAS_NULLPTR
16typedef decltype(nullptr) nullptr_t;
17#endif
18
19/*
20 * Reference removal
21 */
22
23template <class _T> struct remove_reference {typedef _T type;};
24template <class _T> struct remove_reference<_T&> {typedef _T type;};
25template <class _T> struct remove_reference<_T &&> {typedef _T type;};
26template <class _T> using remove_reference_t = typename remove_reference<_T>::type;
27
28/*
29 * Const removal
30 */
31
32template <class _T> struct remove_const {typedef _T type;};
33template <class _T> struct remove_const<const _T> {typedef _T type;};
34template <class _T> using remove_const_t = typename remove_const<_T>::type;
35
36/*
37 * Move
38 */
39
40template <class _T>
41inline typename remove_reference<_T>::type &&
42move(_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 */