2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-10-20 16:08:13 +00:00
|
|
|
constexpr unsigned round_up_to_power_of_two(unsigned value, unsigned power_of_two)
|
2019-05-06 12:04:54 +00:00
|
|
|
{
|
2019-05-28 09:53:16 +00:00
|
|
|
return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
|
2019-05-06 12:04:54 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
namespace AK {
|
|
|
|
|
2020-08-18 18:37:27 +00:00
|
|
|
template<typename T>
|
|
|
|
auto declval() -> T;
|
|
|
|
|
2020-08-16 09:04:00 +00:00
|
|
|
template<typename T, typename SizeType = decltype(sizeof(T)), SizeType N>
|
|
|
|
constexpr SizeType array_size(T (&)[N])
|
|
|
|
{
|
|
|
|
return N;
|
|
|
|
}
|
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
template<typename T>
|
2020-10-20 16:08:13 +00:00
|
|
|
constexpr T min(const T& a, const T& b)
|
2018-10-10 09:53:07 +00:00
|
|
|
{
|
2020-08-06 07:58:45 +00:00
|
|
|
return b < a ? b : a;
|
2018-10-10 09:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2020-10-20 16:08:13 +00:00
|
|
|
constexpr T max(const T& a, const T& b)
|
2018-10-10 09:53:07 +00:00
|
|
|
{
|
|
|
|
return a < b ? b : a;
|
|
|
|
}
|
|
|
|
|
2020-01-20 08:54:15 +00:00
|
|
|
template<typename T>
|
2020-10-20 16:08:13 +00:00
|
|
|
constexpr T clamp(const T& value, const T& min, const T& max)
|
2020-01-20 08:54:15 +00:00
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(max >= min);
|
2020-01-20 08:54:15 +00:00
|
|
|
if (value > max)
|
|
|
|
return max;
|
|
|
|
if (value < min)
|
|
|
|
return min;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2018-11-08 14:39:26 +00:00
|
|
|
template<typename T, typename U>
|
2020-10-20 16:08:13 +00:00
|
|
|
constexpr T ceil_div(T a, U b)
|
2018-10-10 09:53:07 +00:00
|
|
|
{
|
2018-11-08 14:39:26 +00:00
|
|
|
static_assert(sizeof(T) == sizeof(U));
|
2018-10-10 09:53:07 +00:00
|
|
|
T result = a / b;
|
|
|
|
if ((a % b) != 0)
|
|
|
|
++result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
template<typename T>
|
2020-10-19 16:30:30 +00:00
|
|
|
constexpr T&& move(T& arg)
|
2018-10-16 10:10:01 +00:00
|
|
|
{
|
|
|
|
return static_cast<T&&>(arg);
|
|
|
|
}
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2018-10-16 12:33:16 +00:00
|
|
|
template<typename T, typename U>
|
2020-01-19 09:28:58 +00:00
|
|
|
inline void swap(T& a, U& b)
|
2018-10-16 12:33:16 +00:00
|
|
|
{
|
|
|
|
U tmp = move((U&)a);
|
2019-05-28 09:53:16 +00:00
|
|
|
a = (T &&) move(b);
|
2018-10-16 12:33:16 +00:00
|
|
|
b = move(tmp);
|
|
|
|
}
|
2018-10-16 10:20:51 +00:00
|
|
|
|
2018-10-17 08:55:43 +00:00
|
|
|
template<bool B, class T = void>
|
2019-05-28 09:53:16 +00:00
|
|
|
struct EnableIf {
|
2018-10-17 08:55:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
2019-05-28 09:53:16 +00:00
|
|
|
struct EnableIf<true, T> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2018-10-17 08:55:43 +00:00
|
|
|
};
|
|
|
|
|
2020-07-24 00:38:01 +00:00
|
|
|
template<class T>
|
|
|
|
struct AddConst {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = const T;
|
2020-07-24 00:38:01 +00:00
|
|
|
};
|
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
template<class T>
|
|
|
|
struct RemoveConst {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2019-05-28 09:53:16 +00:00
|
|
|
};
|
2020-07-26 14:25:02 +00:00
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
template<class T>
|
|
|
|
struct RemoveConst<const T> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2019-05-28 09:53:16 +00:00
|
|
|
};
|
2020-07-26 14:25:02 +00:00
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
template<class T>
|
|
|
|
struct RemoveVolatile {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2019-05-28 09:53:16 +00:00
|
|
|
};
|
|
|
|
template<class T>
|
2019-06-27 14:01:24 +00:00
|
|
|
struct RemoveVolatile<volatile T> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2019-05-28 09:53:16 +00:00
|
|
|
};
|
|
|
|
template<class T>
|
|
|
|
struct RemoveCV {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = typename RemoveVolatile<typename RemoveConst<T>::Type>::Type;
|
2018-10-17 08:55:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T, T v>
|
|
|
|
struct IntegralConstant {
|
|
|
|
static constexpr T value = v;
|
2020-11-11 22:21:01 +00:00
|
|
|
using ValueType = T;
|
|
|
|
using Type = IntegralConstant;
|
2018-10-17 08:55:43 +00:00
|
|
|
constexpr operator ValueType() const { return value; }
|
|
|
|
constexpr ValueType operator()() const { return value; }
|
|
|
|
};
|
|
|
|
|
2020-11-11 22:21:01 +00:00
|
|
|
using FalseType = IntegralConstant<bool, false>;
|
|
|
|
using TrueType = IntegralConstant<bool, true>;
|
AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safe
This makes most operations thread safe, especially so that they
can safely be used in the Kernel. This includes obtaining a strong
reference from a weak reference, which now requires an explicit
call to WeakPtr::strong_ref(). Another major change is that
Weakable::make_weak_ref() may require the explicit target type.
Previously we used reinterpret_cast in WeakPtr, assuming that it
can be properly converted. But WeakPtr does not necessarily have
the knowledge to be able to do this. Instead, we now ask the class
itself to deliver a WeakPtr to the type that we want.
Also, WeakLink is no longer specific to a target type. The reason
for this is that we want to be able to safely convert e.g. WeakPtr<T>
to WeakPtr<U>, and before this we just reinterpret_cast the internal
WeakLink<T> to WeakLink<U>, which is a bold assumption that it would
actually produce the correct code. Instead, WeakLink now operates
on just a raw pointer and we only make those constructors/operators
available if we can verify that it can be safely cast.
In order to guarantee thread safety, we now use the least significant
bit in the pointer for locking purposes. This also means that only
properly aligned pointers can be used.
2020-09-29 22:26:13 +00:00
|
|
|
template<typename...>
|
|
|
|
using VoidType = void;
|
2018-10-17 08:55:43 +00:00
|
|
|
|
2020-04-07 12:31:49 +00:00
|
|
|
template<class T>
|
|
|
|
struct IsLvalueReference : FalseType {
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct IsLvalueReference<T&> : TrueType {
|
|
|
|
};
|
|
|
|
|
2018-10-17 08:55:43 +00:00
|
|
|
template<class T>
|
2019-05-28 09:53:16 +00:00
|
|
|
struct __IsPointerHelper : FalseType {
|
|
|
|
};
|
2018-10-17 08:55:43 +00:00
|
|
|
|
|
|
|
template<class T>
|
2019-05-28 09:53:16 +00:00
|
|
|
struct __IsPointerHelper<T*> : TrueType {
|
|
|
|
};
|
2018-10-17 08:55:43 +00:00
|
|
|
|
|
|
|
template<class T>
|
2019-05-28 09:53:16 +00:00
|
|
|
struct IsPointer : __IsPointerHelper<typename RemoveCV<T>::Type> {
|
|
|
|
};
|
2018-10-17 08:55:43 +00:00
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
template<class>
|
|
|
|
struct IsFunction : FalseType {
|
|
|
|
};
|
2018-10-17 08:55:43 +00:00
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args...)> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args..., ...)> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args...) const> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args..., ...) const> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args...) volatile> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args..., ...) volatile> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args...) const volatile> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args..., ...) const volatile> : TrueType {
|
|
|
|
};
|
2018-10-17 08:55:43 +00:00
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args...)&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args..., ...)&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args...) const&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args..., ...) const&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args...) volatile&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args..., ...) volatile&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args...) const volatile&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args..., ...) const volatile&> : TrueType {
|
|
|
|
};
|
2018-10-17 08:55:43 +00:00
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args...) &&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args..., ...) &&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args...) const&&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args..., ...) const&&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args...) volatile&&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args..., ...) volatile&&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args...) const volatile&&> : TrueType {
|
|
|
|
};
|
|
|
|
template<class Ret, class... Args>
|
|
|
|
struct IsFunction<Ret(Args..., ...) const volatile&&> : TrueType {
|
|
|
|
};
|
2018-10-17 08:55:43 +00:00
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
template<class T>
|
|
|
|
struct IsRvalueReference : FalseType {
|
|
|
|
};
|
|
|
|
template<class T>
|
|
|
|
struct IsRvalueReference<T&&> : TrueType {
|
|
|
|
};
|
2018-10-17 08:55:43 +00:00
|
|
|
|
2019-05-28 09:53:16 +00:00
|
|
|
template<class T>
|
|
|
|
struct RemovePointer {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2019-05-28 09:53:16 +00:00
|
|
|
};
|
|
|
|
template<class T>
|
|
|
|
struct RemovePointer<T*> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2019-05-28 09:53:16 +00:00
|
|
|
};
|
|
|
|
template<class T>
|
|
|
|
struct RemovePointer<T* const> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2019-05-28 09:53:16 +00:00
|
|
|
};
|
|
|
|
template<class T>
|
|
|
|
struct RemovePointer<T* volatile> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2019-05-28 09:53:16 +00:00
|
|
|
};
|
|
|
|
template<class T>
|
|
|
|
struct RemovePointer<T* const volatile> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2019-05-28 09:53:16 +00:00
|
|
|
};
|
2018-10-17 08:55:43 +00:00
|
|
|
|
2019-02-20 11:28:41 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct IsSame {
|
2020-12-26 11:11:58 +00:00
|
|
|
static constexpr bool value = false;
|
2019-02-20 11:28:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct IsSame<T, T> {
|
2020-12-26 11:11:58 +00:00
|
|
|
static constexpr bool value = true;
|
2019-02-20 11:28:41 +00:00
|
|
|
};
|
|
|
|
|
2020-03-08 09:36:11 +00:00
|
|
|
template<bool condition, class TrueType, class FalseType>
|
|
|
|
struct Conditional {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = TrueType;
|
2020-03-08 09:36:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class TrueType, class FalseType>
|
|
|
|
struct Conditional<false, TrueType, FalseType> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = FalseType;
|
2020-03-08 09:36:11 +00:00
|
|
|
};
|
|
|
|
|
2020-09-23 16:17:43 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsNullPointer : IsSame<decltype(nullptr), typename RemoveCV<T>::Type> {
|
|
|
|
};
|
|
|
|
|
2020-04-07 12:31:49 +00:00
|
|
|
template<typename T>
|
|
|
|
struct RemoveReference {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2020-04-07 12:31:49 +00:00
|
|
|
};
|
|
|
|
template<class T>
|
|
|
|
struct RemoveReference<T&> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2020-04-07 12:31:49 +00:00
|
|
|
};
|
|
|
|
template<class T>
|
|
|
|
struct RemoveReference<T&&> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = T;
|
2020-04-07 12:31:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
2020-10-20 16:08:13 +00:00
|
|
|
constexpr T&& forward(typename RemoveReference<T>::Type& param)
|
2020-04-07 12:31:49 +00:00
|
|
|
{
|
|
|
|
return static_cast<T&&>(param);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2020-10-20 16:08:13 +00:00
|
|
|
constexpr T&& forward(typename RemoveReference<T>::Type&& param) noexcept
|
2020-04-07 12:31:49 +00:00
|
|
|
{
|
|
|
|
static_assert(!IsLvalueReference<T>::value, "Can't forward an rvalue as an lvalue.");
|
|
|
|
return static_cast<T&&>(param);
|
|
|
|
}
|
|
|
|
|
2020-04-15 14:51:36 +00:00
|
|
|
template<typename T>
|
|
|
|
struct MakeUnsigned {
|
2020-12-20 16:00:50 +00:00
|
|
|
using Type = void;
|
2020-04-15 14:51:36 +00:00
|
|
|
};
|
|
|
|
template<>
|
2020-07-18 15:19:59 +00:00
|
|
|
struct MakeUnsigned<signed char> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = unsigned char;
|
2020-04-15 14:51:36 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<short> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = unsigned short;
|
2020-04-15 14:51:36 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<int> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = unsigned int;
|
2020-04-15 14:51:36 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<long> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = unsigned long;
|
2020-04-15 14:51:36 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<long long> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = unsigned long long;
|
2020-04-15 14:51:36 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<unsigned char> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = unsigned char;
|
2020-04-15 14:51:36 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<unsigned short> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = unsigned short;
|
2020-04-15 14:51:36 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<unsigned int> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = unsigned int;
|
2020-04-15 14:51:36 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<unsigned long> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = unsigned long;
|
2020-04-15 14:51:36 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<unsigned long long> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = unsigned long long;
|
2020-04-15 14:51:36 +00:00
|
|
|
};
|
2020-08-27 13:36:55 +00:00
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<char> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = unsigned char;
|
2020-08-27 13:36:55 +00:00
|
|
|
};
|
2020-12-30 05:44:59 +00:00
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<char8_t> {
|
|
|
|
using Type = char8_t;
|
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<char16_t> {
|
|
|
|
using Type = char16_t;
|
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<char32_t> {
|
|
|
|
using Type = char32_t;
|
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeUnsigned<bool> {
|
|
|
|
using Type = bool;
|
|
|
|
};
|
2020-04-15 14:51:36 +00:00
|
|
|
|
2020-05-23 10:39:51 +00:00
|
|
|
template<typename T>
|
|
|
|
struct MakeSigned {
|
|
|
|
};
|
|
|
|
template<>
|
2020-07-18 15:19:59 +00:00
|
|
|
struct MakeSigned<signed char> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = signed char;
|
2020-05-23 10:39:51 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeSigned<short> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = short;
|
2020-05-23 10:39:51 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeSigned<int> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = int;
|
2020-05-23 10:39:51 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeSigned<long> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = long;
|
2020-05-23 10:39:51 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeSigned<long long> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = long long;
|
2020-05-23 10:39:51 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeSigned<unsigned char> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = char;
|
2020-05-23 10:39:51 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeSigned<unsigned short> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = short;
|
2020-05-23 10:39:51 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeSigned<unsigned int> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = int;
|
2020-05-23 10:39:51 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeSigned<unsigned long> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = long;
|
2020-05-23 10:39:51 +00:00
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct MakeSigned<unsigned long long> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = long long;
|
2020-05-23 10:39:51 +00:00
|
|
|
};
|
2020-08-27 13:36:55 +00:00
|
|
|
template<>
|
|
|
|
struct MakeSigned<char> {
|
2020-11-11 22:21:01 +00:00
|
|
|
using Type = signed char;
|
2020-08-27 13:36:55 +00:00
|
|
|
};
|
2020-05-23 10:39:51 +00:00
|
|
|
|
2020-07-24 00:38:01 +00:00
|
|
|
template<class T>
|
|
|
|
struct IsVoid : IsSame<void, typename RemoveCV<T>::Type> {
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct IsConst : FalseType {
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct IsConst<const T> : TrueType {
|
|
|
|
};
|
|
|
|
|
2020-04-22 09:52:26 +00:00
|
|
|
template<typename T, typename U = T>
|
2020-10-19 16:30:30 +00:00
|
|
|
constexpr T exchange(T& slot, U&& value)
|
2020-04-22 09:52:26 +00:00
|
|
|
{
|
|
|
|
T old_value = move(slot);
|
|
|
|
slot = forward<U>(value);
|
|
|
|
return old_value;
|
|
|
|
}
|
|
|
|
|
2021-03-05 07:16:59 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsEnum : public IntegralConstant<bool, __is_enum(T)> {
|
|
|
|
};
|
|
|
|
|
2020-07-26 14:25:02 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsUnion : public IntegralConstant<bool, __is_union(T)> {
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct IsClass : public IntegralConstant<bool, __is_class(T)> {
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Base, typename Derived>
|
|
|
|
struct IsBaseOf : public IntegralConstant<bool, __is_base_of(Base, Derived)> {
|
|
|
|
};
|
|
|
|
|
2020-10-01 01:08:30 +00:00
|
|
|
template<typename T>
|
|
|
|
constexpr bool is_trivial()
|
|
|
|
{
|
|
|
|
return __is_trivial(T);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
constexpr bool is_trivially_copyable()
|
|
|
|
{
|
|
|
|
return __is_trivially_copyable(T);
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:14:37 +00:00
|
|
|
template<typename T>
|
|
|
|
struct __IsIntegral : FalseType {
|
|
|
|
};
|
|
|
|
template<>
|
2020-12-30 05:44:59 +00:00
|
|
|
struct __IsIntegral<bool> : TrueType {
|
|
|
|
};
|
|
|
|
template<>
|
2020-09-22 11:42:30 +00:00
|
|
|
struct __IsIntegral<unsigned char> : TrueType {
|
|
|
|
};
|
|
|
|
template<>
|
2020-12-30 05:44:59 +00:00
|
|
|
struct __IsIntegral<char8_t> : TrueType {
|
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct __IsIntegral<char16_t> : TrueType {
|
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct __IsIntegral<char32_t> : TrueType {
|
|
|
|
};
|
|
|
|
template<>
|
2020-09-22 11:42:30 +00:00
|
|
|
struct __IsIntegral<unsigned short> : TrueType {
|
2020-08-03 18:14:37 +00:00
|
|
|
};
|
|
|
|
template<>
|
2020-09-22 11:42:30 +00:00
|
|
|
struct __IsIntegral<unsigned int> : TrueType {
|
2020-08-03 18:14:37 +00:00
|
|
|
};
|
|
|
|
template<>
|
2020-09-22 11:42:30 +00:00
|
|
|
struct __IsIntegral<unsigned long> : TrueType {
|
2020-08-03 18:14:37 +00:00
|
|
|
};
|
|
|
|
template<>
|
2020-09-22 11:42:30 +00:00
|
|
|
struct __IsIntegral<unsigned long long> : TrueType {
|
2020-08-03 18:14:37 +00:00
|
|
|
};
|
|
|
|
template<typename T>
|
|
|
|
using IsIntegral = __IsIntegral<typename MakeUnsigned<typename RemoveCV<T>::Type>::Type>;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct __IsFloatingPoint : FalseType {
|
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct __IsFloatingPoint<float> : TrueType {
|
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct __IsFloatingPoint<double> : TrueType {
|
|
|
|
};
|
2020-12-30 05:44:59 +00:00
|
|
|
template<>
|
|
|
|
struct __IsFloatingPoint<long double> : TrueType {
|
|
|
|
};
|
2020-08-03 18:14:37 +00:00
|
|
|
template<typename T>
|
|
|
|
using IsFloatingPoint = __IsFloatingPoint<typename RemoveCV<T>::Type>;
|
|
|
|
|
2020-07-26 14:25:02 +00:00
|
|
|
template<typename ReferenceType, typename T>
|
|
|
|
using CopyConst =
|
|
|
|
typename Conditional<IsConst<ReferenceType>::value, typename AddConst<T>::Type, typename RemoveConst<T>::Type>::Type;
|
|
|
|
|
2020-08-22 21:37:10 +00:00
|
|
|
template<typename... Ts>
|
|
|
|
using Void = void;
|
|
|
|
|
2020-10-03 12:56:09 +00:00
|
|
|
template<typename... _Ignored>
|
2020-10-20 16:08:13 +00:00
|
|
|
constexpr auto DependentFalse = false;
|
2020-10-03 12:56:09 +00:00
|
|
|
|
2020-12-20 16:00:50 +00:00
|
|
|
template<typename T>
|
2021-02-10 21:23:24 +00:00
|
|
|
using IsUnsigned = IsSame<T, typename MakeUnsigned<T>::Type>;
|
2020-12-20 16:00:50 +00:00
|
|
|
|
2020-12-30 05:37:36 +00:00
|
|
|
template<typename T>
|
|
|
|
using IsArithmetic = IntegralConstant<bool, IsIntegral<T>::value || IsFloatingPoint<T>::value>;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
using IsFundamental = IntegralConstant<bool, IsArithmetic<T>::value || IsVoid<T>::value || IsNullPointer<T>::value>;
|
|
|
|
|
2020-12-30 05:40:21 +00:00
|
|
|
template<typename T, T... Ts>
|
|
|
|
struct IntegerSequence {
|
|
|
|
using Type = T;
|
|
|
|
static constexpr unsigned size() noexcept { return sizeof...(Ts); };
|
|
|
|
};
|
|
|
|
|
|
|
|
template<unsigned... Indices>
|
|
|
|
using IndexSequence = IntegerSequence<unsigned, Indices...>;
|
|
|
|
|
|
|
|
template<typename T, T N, T... Ts>
|
|
|
|
auto make_integer_sequence_impl()
|
|
|
|
{
|
|
|
|
if constexpr (N == 0)
|
|
|
|
return IntegerSequence<T, Ts...> {};
|
|
|
|
else
|
|
|
|
return make_integer_sequence_impl<T, N - 1, N - 1, Ts...>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, T N>
|
|
|
|
using MakeIntegerSequence = decltype(make_integer_sequence_impl<T, N>());
|
|
|
|
|
|
|
|
template<unsigned N>
|
|
|
|
using MakeIndexSequence = MakeIntegerSequence<unsigned, N>;
|
|
|
|
|
2021-02-21 23:07:24 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IdentityType {
|
|
|
|
using Type = T;
|
2021-01-17 08:22:04 +00:00
|
|
|
};
|
|
|
|
|
2021-03-05 07:16:59 +00:00
|
|
|
template<class T, bool = IsEnum<T>::value>
|
|
|
|
struct __UnderlyingType {
|
|
|
|
using Type = __underlying_type(T);
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct __UnderlyingType<T, false> {
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct UnderlyingType : __UnderlyingType<T> {
|
|
|
|
};
|
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 00:38:01 +00:00
|
|
|
using AK::AddConst;
|
2020-08-16 09:04:00 +00:00
|
|
|
using AK::array_size;
|
2019-05-28 09:53:16 +00:00
|
|
|
using AK::ceil_div;
|
2020-02-09 14:50:13 +00:00
|
|
|
using AK::clamp;
|
2020-04-07 12:31:49 +00:00
|
|
|
using AK::Conditional;
|
2020-08-18 18:37:27 +00:00
|
|
|
using AK::declval;
|
2020-10-03 12:56:09 +00:00
|
|
|
using AK::DependentFalse;
|
2019-05-28 09:53:16 +00:00
|
|
|
using AK::exchange;
|
|
|
|
using AK::forward;
|
2021-02-21 23:07:24 +00:00
|
|
|
using AK::IdentityType;
|
2020-12-30 05:40:21 +00:00
|
|
|
using AK::IndexSequence;
|
|
|
|
using AK::IntegerSequence;
|
2020-10-01 01:08:30 +00:00
|
|
|
using AK::is_trivial;
|
|
|
|
using AK::is_trivially_copyable;
|
2020-12-30 05:37:36 +00:00
|
|
|
using AK::IsArithmetic;
|
2020-07-26 14:25:02 +00:00
|
|
|
using AK::IsBaseOf;
|
|
|
|
using AK::IsClass;
|
2020-07-24 00:38:01 +00:00
|
|
|
using AK::IsConst;
|
2021-03-05 07:16:59 +00:00
|
|
|
using AK::IsEnum;
|
2020-12-30 05:37:36 +00:00
|
|
|
using AK::IsFundamental;
|
|
|
|
using AK::IsNullPointer;
|
2019-05-28 09:53:16 +00:00
|
|
|
using AK::IsSame;
|
2020-07-26 14:25:02 +00:00
|
|
|
using AK::IsUnion;
|
2021-02-10 21:23:24 +00:00
|
|
|
using AK::IsUnsigned;
|
2020-07-24 00:38:01 +00:00
|
|
|
using AK::IsVoid;
|
2020-12-30 05:40:21 +00:00
|
|
|
using AK::MakeIndexSequence;
|
|
|
|
using AK::MakeIntegerSequence;
|
2020-05-23 10:39:51 +00:00
|
|
|
using AK::MakeSigned;
|
2020-04-15 14:51:36 +00:00
|
|
|
using AK::MakeUnsigned;
|
2018-10-10 09:53:07 +00:00
|
|
|
using AK::max;
|
2019-05-28 09:53:16 +00:00
|
|
|
using AK::min;
|
2018-10-16 10:20:51 +00:00
|
|
|
using AK::move;
|
2019-06-01 12:11:31 +00:00
|
|
|
using AK::RemoveConst;
|
2019-06-07 09:46:22 +00:00
|
|
|
using AK::swap;
|
2021-03-05 07:16:59 +00:00
|
|
|
using AK::UnderlyingType;
|
2020-08-22 21:37:10 +00:00
|
|
|
using AK::Void;
|