20 #ifndef KERNEL_UTILITIES_CPP_H 21 #define KERNEL_UTILITIES_CPP_H 31 #include "pedigree/kernel/processor/types.h" 32 #include "pedigree/kernel/utilities/lib.h" 33 #include "pedigree/kernel/utilities/template.h" 36 #include "pedigree/kernel/utilities/new" 38 namespace pedigree_std
40 template <
typename T1,
typename T2>
43 static const bool value =
false;
46 template <
typename T1,
typename T2>
49 static const bool value =
true;
55 static const bool value =
true;
61 static const bool value =
false;
67 static const bool value =
false;
70 struct is_integral<bool>
72 static const bool value =
true;
75 struct is_integral<char>
77 static const bool value =
true;
80 struct is_integral<unsigned char>
82 static const bool value =
true;
85 struct is_integral<signed char>
87 static const bool value =
true;
90 struct is_integral<short>
92 static const bool value =
true;
95 struct is_integral<unsigned short>
97 static const bool value =
true;
100 struct is_integral<int>
102 static const bool value =
true;
105 struct is_integral<unsigned int>
107 static const bool value =
true;
110 struct is_integral<long>
112 static const bool value =
true;
115 struct is_integral<unsigned long>
117 static const bool value =
true;
120 struct is_integral<long long>
122 static const bool value =
true;
125 struct is_integral<unsigned long long>
127 static const bool value =
true;
130 template <
typename T>
133 static const bool value =
false;
135 template <
typename T>
136 struct is_pointer<T *>
138 static const bool value =
true;
143 struct remove_all_extents
149 struct remove_all_extents<T[]>
151 typedef typename remove_all_extents<T>::type type;
154 template <
class T,
size_t N>
155 struct remove_all_extents<T[N]>
157 typedef typename remove_all_extents<T>::type type;
161 template <
bool,
class T =
void>
167 struct enable_if<true, T>
173 template <
class T, T v>
174 struct integral_constant
176 static constexpr T value = v;
177 typedef T value_type;
178 typedef integral_constant type;
179 constexpr
operator value_type() const noexcept
185 template <
class T, T v>
186 constexpr T integral_constant<T, v>::value;
188 typedef integral_constant<bool, true> true_type;
189 typedef integral_constant<bool, false> false_type;
195 : integral_constant<bool, is_integral<T>::value || is_pointer<T>::value>
201 struct is_trivial :
public integral_constant<bool, __is_trivial(T)>
207 struct is_trivially_copyable
208 :
public integral_constant<
209 bool, is_scalar<typename remove_all_extents<T>::type>::value>
213 template <
class T,
class U>
214 struct is_same : false_type
219 struct is_same<T, T> : true_type
225 typename enable_if<is_trivially_copyable<T>::value>::type *
226 copy(T *dest,
const T *src,
size_t count)
229 return memmove(dest, src, count *
sizeof(T));
231 return MemoryCopy(dest, src, count *
sizeof(T));
237 typename enable_if<!is_trivially_copyable<T>::value>::type *
238 copy(T *dest,
const T *src,
size_t count)
240 if (overlaps(dest, src, count *
sizeof(T)))
242 for (ssize_t i = count - 1; i >= 0; --i)
249 for (
size_t i = 0; i < count; ++i)
259 struct function_traits :
public function_traits<decltype(&T::operator())>
263 template <
class C,
class R,
class... Args>
264 struct function_traits<R (C::*)(Args...) const>
266 typedef R return_type;
267 typedef C class_type;
270 template <
class R,
class... Args>
271 struct function_traits<R (*)(Args...)>
273 typedef R return_type;
276 template <
class R,
class... Args>
277 struct function_traits<R(Args...)>
279 typedef R return_type;
287 Callable(
const F &x) : func(x)
291 template <
class... Args>
292 typename function_traits<F>::return_type operator()(Args... args)
294 return func(args...);
303 Callable<T> make_callable(T &f)
305 return Callable<T>(f);
310 struct remove_pointer
316 struct remove_pointer<T *>
323 struct remove_reference
329 struct remove_reference<T &>
336 typename remove_reference<T>::type &&move(T &&a)
338 return static_cast<typename remove_reference<T>::type &&
>(a);
343 const T &min(
const T& a,
const T &b)
345 return a <= b ? a : b;
350 const T &max(
const T& a,
const T &b)
352 return a >= b ? a : b;
357 using pedigree_std::is_integral;
358 using pedigree_std::is_pointer;
360 #endif // __cplusplus 362 #endif // KERNEL_UTILITIES_CPP_H