diff --git a/AK/Atomic.h b/AK/Atomic.h index a41a9a8414..b165435928 100644 --- a/AK/Atomic.h +++ b/AK/Atomic.h @@ -53,13 +53,13 @@ static inline T atomic_exchange(volatile T* var, T desired, MemoryOrder order = return __atomic_exchange_n(var, desired, order); } -template::Type> +template> static inline V* atomic_exchange(volatile T** var, V* desired, MemoryOrder order = memory_order_seq_cst) noexcept { return __atomic_exchange_n(var, desired, order); } -template::Type> +template> static inline V* atomic_exchange(volatile T** var, std::nullptr_t, MemoryOrder order = memory_order_seq_cst) noexcept { return __atomic_exchange_n(const_cast(var), nullptr, order); @@ -74,7 +74,7 @@ template return __atomic_compare_exchange_n(var, &expected, desired, false, order, order); } -template::Type> +template> [[nodiscard]] static inline bool atomic_compare_exchange_strong(volatile T** var, V*& expected, V* desired, MemoryOrder order = memory_order_seq_cst) noexcept { if (order == memory_order_acq_rel || order == memory_order_release) @@ -83,7 +83,7 @@ template::Type> return __atomic_compare_exchange_n(var, &expected, desired, false, order, order); } -template::Type> +template> [[nodiscard]] static inline bool atomic_compare_exchange_strong(volatile T** var, V*& expected, std::nullptr_t, MemoryOrder order = memory_order_seq_cst) noexcept { if (order == memory_order_acq_rel || order == memory_order_release) @@ -128,7 +128,7 @@ static inline T atomic_load(volatile T* var, MemoryOrder order = memory_order_se return __atomic_load_n(var, order); } -template::Type> +template> static inline V* atomic_load(volatile T** var, MemoryOrder order = memory_order_seq_cst) noexcept { return __atomic_load_n(const_cast(var), order); @@ -140,13 +140,13 @@ static inline void atomic_store(volatile T* var, T desired, MemoryOrder order = __atomic_store_n(var, desired, order); } -template::Type> +template> static inline void atomic_store(volatile T** var, V* desired, MemoryOrder order = memory_order_seq_cst) noexcept { __atomic_store_n(var, desired, order); } -template::Type> +template> static inline void atomic_store(volatile T** var, std::nullptr_t, MemoryOrder order = memory_order_seq_cst) noexcept { __atomic_store_n(const_cast(var), nullptr, order); diff --git a/AK/Buffered.h b/AK/Buffered.h index f671bd20fa..f3629cb7ff 100644 --- a/AK/Buffered.h +++ b/AK/Buffered.h @@ -41,7 +41,7 @@ template class Buffered; template -class Buffered::value>::Type> final : public InputStream { +class Buffered>::Type> final : public InputStream { AK_MAKE_NONCOPYABLE(Buffered); public: @@ -137,7 +137,7 @@ private: }; template -class Buffered::value>::Type> final : public OutputStream { +class Buffered>::Type> final : public OutputStream { AK_MAKE_NONCOPYABLE(Buffered); public: diff --git a/AK/CheckedFormatString.h b/AK/CheckedFormatString.h index b4573289e7..c2fd09910e 100644 --- a/AK/CheckedFormatString.h +++ b/AK/CheckedFormatString.h @@ -237,6 +237,6 @@ private: namespace AK { template -using CheckedFormatString = Format::Detail::CheckedFormatString::Type...>; +using CheckedFormatString = Format::Detail::CheckedFormatString...>; } diff --git a/AK/Concepts.h b/AK/Concepts.h index 1df01425d6..95c1d8a045 100644 --- a/AK/Concepts.h +++ b/AK/Concepts.h @@ -33,19 +33,19 @@ namespace AK::Concepts { #if defined(__cpp_concepts) && !defined(__COVERITY__) template -concept Integral = IsIntegral::value; +concept Integral = IsIntegral; template -concept FloatingPoint = IsFloatingPoint::value; +concept FloatingPoint = IsFloatingPoint; template -concept Arithmetic = IsArithmetic::value; +concept Arithmetic = IsArithmetic; template -concept Signed = IsSigned::value; +concept Signed = IsSigned; template -concept Unsigned = IsUnsigned::value; +concept Unsigned = IsUnsigned; #endif diff --git a/AK/DoublyLinkedList.h b/AK/DoublyLinkedList.h index 0450c38faa..2d2ad3266a 100644 --- a/AK/DoublyLinkedList.h +++ b/AK/DoublyLinkedList.h @@ -132,7 +132,7 @@ public: template void prepend(U&& value) { - static_assert(IsSame::value); + static_assert(IsSame); auto* node = new Node(forward(value)); if (!m_head) { VERIFY(!m_tail); diff --git a/AK/EnumBits.h b/AK/EnumBits.h index 57dea9b6b5..2be7226993 100644 --- a/AK/EnumBits.h +++ b/AK/EnumBits.h @@ -44,35 +44,35 @@ \ [[nodiscard]] Prefix constexpr inline Enum operator|(Enum lhs, Enum rhs) \ { \ - using Type = UnderlyingType::Type; \ + using Type = UnderlyingType; \ return static_cast( \ static_cast(lhs) | static_cast(rhs)); \ } \ \ [[nodiscard]] Prefix constexpr inline Enum operator&(Enum lhs, Enum rhs) \ { \ - using Type = UnderlyingType::Type; \ + using Type = UnderlyingType; \ return static_cast( \ static_cast(lhs) & static_cast(rhs)); \ } \ \ [[nodiscard]] Prefix constexpr inline Enum operator^(Enum lhs, Enum rhs) \ { \ - using Type = UnderlyingType::Type; \ + using Type = UnderlyingType; \ return static_cast( \ static_cast(lhs) ^ static_cast(rhs)); \ } \ \ [[nodiscard]] Prefix constexpr inline Enum operator~(Enum rhs) \ { \ - using Type = UnderlyingType::Type; \ + using Type = UnderlyingType; \ return static_cast( \ ~static_cast(rhs)); \ } \ \ Prefix constexpr inline Enum& operator|=(Enum& lhs, Enum rhs) \ { \ - using Type = UnderlyingType::Type; \ + using Type = UnderlyingType; \ lhs = static_cast( \ static_cast(lhs) | static_cast(rhs)); \ return lhs; \ @@ -80,7 +80,7 @@ \ Prefix constexpr inline Enum& operator&=(Enum& lhs, Enum rhs) \ { \ - using Type = UnderlyingType::Type; \ + using Type = UnderlyingType; \ lhs = static_cast( \ static_cast(lhs) & static_cast(rhs)); \ return lhs; \ @@ -88,7 +88,7 @@ \ Prefix constexpr inline Enum& operator^=(Enum& lhs, Enum rhs) \ { \ - using Type = UnderlyingType::Type; \ + using Type = UnderlyingType; \ lhs = static_cast( \ static_cast(lhs) ^ static_cast(rhs)); \ return lhs; \ @@ -96,6 +96,6 @@ \ Prefix constexpr inline bool has_flag(Enum value, Enum mask) \ { \ - using Type = UnderlyingType::Type; \ + using Type = UnderlyingType; \ return static_cast(value & mask) != 0; \ } diff --git a/AK/Format.cpp b/AK/Format.cpp index 1c33e962f5..0fe6f06a2b 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -534,7 +534,7 @@ void Formatter::vformat(FormatBuilder& builder, StringView fmtstr, } template -void Formatter::value>::Type>::format(FormatBuilder& builder, T value) +void Formatter>::Type>::format(FormatBuilder& builder, T value) { if (m_mode == Mode::Character) { // FIXME: We just support ASCII for now, in the future maybe unicode? @@ -587,7 +587,7 @@ void Formatter::value>::Type>::format(FormatB m_width = m_width.value_or(0); - if (IsSame::Type, T>::value) + if constexpr (IsSame, T>) builder.put_u64(value, base, m_alternative_form, upper_case, m_zero_pad, m_align, m_width.value(), m_fill, m_sign_mode); else builder.put_i64(value, base, m_alternative_form, upper_case, m_zero_pad, m_align, m_width.value(), m_fill, m_sign_mode); diff --git a/AK/Format.h b/AK/Format.h index 8da01d3b26..a46b06c4b5 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -93,10 +93,10 @@ struct TypeErasedParameter { template static Type get_type() { - if (IsIntegral::value) - return get_type_from_size(sizeof(T), IsUnsigned::value); - - return Type::Custom; + if constexpr (IsIntegral) + return get_type_from_size(sizeof(T), IsUnsigned); + else + return Type::Custom; } size_t to_size() const; @@ -269,7 +269,7 @@ struct StandardFormatter { }; template -struct Formatter::value>::Type> : StandardFormatter { +struct Formatter>::Type> : StandardFormatter { Formatter() = default; explicit Formatter(StandardFormatter formatter) : StandardFormatter(formatter) @@ -416,11 +416,10 @@ void dmesgln(CheckedFormatString&& fmt, const Parameters&... para #endif template -struct HasFormatter : TrueType { -}; +inline constexpr bool HasFormatter = true; + template -struct HasFormatter::__no_formatter_defined> : FalseType { -}; +inline constexpr bool HasFormatter::__no_formatter_defined> = false; template class FormatIfSupported { @@ -450,7 +449,7 @@ struct __FormatIfSupported : Formatter { } }; template -struct Formatter> : __FormatIfSupported::value> { +struct Formatter> : __FormatIfSupported> { }; // This is a helper class, the idea is that if you want to implement a formatter you can inherit diff --git a/AK/Function.h b/AK/Function.h index d5bef1cb28..ca1ac2e1c8 100644 --- a/AK/Function.h +++ b/AK/Function.h @@ -39,13 +39,13 @@ class Function { public: Function() = default; - template::value && IsFunction::Type>::value) && IsRvalueReference::value>::Type> + template && IsFunction>)&&IsRvalueReference>::Type> Function(CallableType&& callable) : m_callable_wrapper(make>(move(callable))) { } - template::value && IsFunction::Type>::value>::Type> + template && IsFunction>>::Type> Function(FunctionType f) : m_callable_wrapper(make>(move(f))) { @@ -59,14 +59,14 @@ public: explicit operator bool() const { return !!m_callable_wrapper; } - template::value && IsFunction::Type>::value) && IsRvalueReference::value>::Type> + template && IsFunction>)&&IsRvalueReference>::Type> Function& operator=(CallableType&& callable) { m_callable_wrapper = make>(move(callable)); return *this; } - template::value && IsFunction::Type>::value>::Type> + template && IsFunction>>::Type> Function& operator=(FunctionType f) { m_callable_wrapper = make>(move(f)); @@ -103,7 +103,7 @@ private: return m_callable(forward(in)...); } else if constexpr (requires { m_callable(); }) { return m_callable(); - } else if constexpr (IsSame::value) { + } else if constexpr (IsVoid) { return; } else { return {}; diff --git a/AK/Iterator.h b/AK/Iterator.h index 0ee6d1c198..6ef2d58093 100644 --- a/AK/Iterator.h +++ b/AK/Iterator.h @@ -89,9 +89,9 @@ private: static constexpr SimpleIterator begin(Container& container) { return { container, 0 }; } static constexpr SimpleIterator end(Container& container) { - using RawContainerType = typename RemoveCV::Type; + using RawContainerType = RemoveCV; - if constexpr (IsSame::value || IsSame::value) + if constexpr (IsSame || IsSame) return { container, container.length() }; else return { container, container.size() }; diff --git a/AK/RefPtr.h b/AK/RefPtr.h index 2a1720f9ac..a73b81dd50 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -379,7 +379,7 @@ public: ALWAYS_INLINE bool is_null() const { return PtrTraits::is_null(m_bits.load(AK::MemoryOrder::memory_order_relaxed)); } - template::value && !IsNullPointer::value>::Type* = nullptr> + template && !IsNullPointer>::Type* = nullptr> typename PtrTraits::NullType null_value() const { // make sure we are holding a null value @@ -387,7 +387,7 @@ public: VERIFY(PtrTraits::is_null(bits)); return PtrTraits::to_null_value(bits); } - template::value && !IsNullPointer::value>::Type* = nullptr> + template && !IsNullPointer>::Type* = nullptr> void set_null_value(typename PtrTraits::NullType value) { // make sure that new null value would be interpreted as a null value diff --git a/AK/Span.h b/AK/Span.h index 42393f315a..dd719136bb 100644 --- a/AK/Span.h +++ b/AK/Span.h @@ -167,16 +167,16 @@ public: __builtin_memcpy(this->data() + offset, data, data_size); } - ALWAYS_INLINE constexpr size_t copy_to(Span::Type> other) const + ALWAYS_INLINE constexpr size_t copy_to(Span> other) const { VERIFY(other.size() >= size()); - return TypedTransfer::Type>::copy(other.data(), data(), size()); + return TypedTransfer>::copy(other.data(), data(), size()); } - ALWAYS_INLINE constexpr size_t copy_trimmed_to(Span::Type> other) const + ALWAYS_INLINE constexpr size_t copy_trimmed_to(Span> other) const { const auto count = min(size(), other.size()); - return TypedTransfer::Type>::copy(other.data(), data(), count); + return TypedTransfer>::copy(other.data(), data(), count); } ALWAYS_INLINE constexpr size_t fill(const T& value) diff --git a/AK/StdLibExtraDetails.h b/AK/StdLibExtraDetails.h new file mode 100644 index 0000000000..121c3120ae --- /dev/null +++ b/AK/StdLibExtraDetails.h @@ -0,0 +1,498 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2021, Ali Mohammad Pur + * 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. + */ + +#pragma once + +namespace AK::Detail { + +template +struct EnableIf { +}; + +template +struct EnableIf { + using Type = T; +}; + +template +struct IntegralConstant { + static constexpr T value = v; + using ValueType = T; + using Type = IntegralConstant; + constexpr operator ValueType() const { return value; } + constexpr ValueType operator()() const { return value; } +}; + +using FalseType = IntegralConstant; +using TrueType = IntegralConstant; + +template +using AddConst = const T; + +template +struct __RemoveConst { + using Type = T; +}; +template +struct __RemoveConst { + using Type = T; +}; +template +using RemoveConst = typename __RemoveConst::Type; + +template +struct __RemoveVolatile { + using Type = T; +}; + +template +struct __RemoveVolatile { + using Type = T; +}; + +template +using RemoveVolatile = typename __RemoveVolatile::Type; + +template +using RemoveCV = RemoveVolatile>; + +template +using VoidType = void; + +template +inline constexpr bool IsLvalueReference = false; + +template +inline constexpr bool IsLvalueReference = true; + +template +inline constexpr bool __IsPointerHelper = false; + +template +inline constexpr bool __IsPointerHelper = true; + +template +inline constexpr bool IsPointer = __IsPointerHelper>; + +template +inline constexpr bool IsFunction = false; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; +template +inline constexpr bool IsFunction = true; + +template +inline constexpr bool IsRvalueReference = false; +template +inline constexpr bool IsRvalueReference = true; + +template +struct __RemovePointer { + using Type = T; +}; +template +struct __RemovePointer { + using Type = T; +}; +template +struct __RemovePointer { + using Type = T; +}; +template +struct __RemovePointer { + using Type = T; +}; +template +struct __RemovePointer { + using Type = T; +}; +template +using RemovePointer = typename __RemovePointer::Type; + +template +inline constexpr bool IsSame = false; + +template +inline constexpr bool IsSame = true; + +template +struct __Conditional { + using Type = TrueType; +}; + +template +struct __Conditional { + using Type = FalseType; +}; + +template +using Conditional = typename __Conditional::Type; + +template +inline constexpr bool IsNullPointer = IsSame>; + +template +struct __RemoveReference { + using Type = T; +}; +template +struct __RemoveReference { + using Type = T; +}; +template +struct __RemoveReference { + using Type = T; +}; + +template +using RemoveReference = typename __RemoveReference::Type; + +template +struct __MakeUnsigned { + using Type = void; +}; +template<> +struct __MakeUnsigned { + using Type = unsigned char; +}; +template<> +struct __MakeUnsigned { + using Type = unsigned short; +}; +template<> +struct __MakeUnsigned { + using Type = unsigned int; +}; +template<> +struct __MakeUnsigned { + using Type = unsigned long; +}; +template<> +struct __MakeUnsigned { + using Type = unsigned long long; +}; +template<> +struct __MakeUnsigned { + using Type = unsigned char; +}; +template<> +struct __MakeUnsigned { + using Type = unsigned short; +}; +template<> +struct __MakeUnsigned { + using Type = unsigned int; +}; +template<> +struct __MakeUnsigned { + using Type = unsigned long; +}; +template<> +struct __MakeUnsigned { + using Type = unsigned long long; +}; +template<> +struct __MakeUnsigned { + using Type = unsigned char; +}; +template<> +struct __MakeUnsigned { + using Type = char8_t; +}; +template<> +struct __MakeUnsigned { + using Type = char16_t; +}; +template<> +struct __MakeUnsigned { + using Type = char32_t; +}; +template<> +struct __MakeUnsigned { + using Type = bool; +}; + +template +using MakeUnsigned = typename __MakeUnsigned::Type; + +template +struct __MakeSigned { +}; +template<> +struct __MakeSigned { + using Type = signed char; +}; +template<> +struct __MakeSigned { + using Type = short; +}; +template<> +struct __MakeSigned { + using Type = int; +}; +template<> +struct __MakeSigned { + using Type = long; +}; +template<> +struct __MakeSigned { + using Type = long long; +}; +template<> +struct __MakeSigned { + using Type = char; +}; +template<> +struct __MakeSigned { + using Type = short; +}; +template<> +struct __MakeSigned { + using Type = int; +}; +template<> +struct __MakeSigned { + using Type = long; +}; +template<> +struct __MakeSigned { + using Type = long long; +}; +template<> +struct __MakeSigned { + using Type = char; +}; + +template +using MakeSigned = typename __MakeSigned::Type; + +template +inline constexpr bool IsVoid = IsSame>; + +template +inline constexpr bool IsConst = false; + +template +inline constexpr bool IsConst = true; + +template +inline constexpr bool IsEnum = __is_enum(T); + +template +inline constexpr bool IsUnion = __is_union(T); + +template +inline constexpr bool IsClass = __is_class(T); + +template +inline constexpr bool IsBaseOf = __is_base_of(Base, Derived); + +template +inline constexpr bool __IsIntegral = false; + +template<> +inline constexpr bool __IsIntegral = true; +template<> +inline constexpr bool __IsIntegral = true; +template<> +inline constexpr bool __IsIntegral = true; +template<> +inline constexpr bool __IsIntegral = true; +template<> +inline constexpr bool __IsIntegral = true; +template<> +inline constexpr bool __IsIntegral = true; +template<> +inline constexpr bool __IsIntegral = true; +template<> +inline constexpr bool __IsIntegral = true; +template<> +inline constexpr bool __IsIntegral = true; + +template +inline constexpr bool IsIntegral = __IsIntegral>>; + +template +inline constexpr bool __IsFloatingPoint = false; +template<> +inline constexpr bool __IsFloatingPoint = true; +template<> +inline constexpr bool __IsFloatingPoint = true; +template<> +inline constexpr bool __IsFloatingPoint = true; + +template +inline constexpr bool IsFloatingPoint = __IsFloatingPoint>; + +template +using CopyConst = Conditional, AddConst, RemoveConst>; + +template +using Void = void; + +template +constexpr auto DependentFalse = false; + +template +inline constexpr bool IsSigned = IsSame>; + +template +inline constexpr bool IsUnsigned = IsSame>; + +template +inline constexpr bool IsArithmetic = IsIntegral || IsFloatingPoint; + +template +inline constexpr bool IsFundamental = IsArithmetic || IsVoid || IsNullPointer; + +template +struct IntegerSequence { + using Type = T; + static constexpr unsigned size() noexcept { return sizeof...(Ts); }; +}; + +template +using IndexSequence = IntegerSequence; + +template +auto make_integer_sequence_impl() +{ + if constexpr (N == 0) + return IntegerSequence {}; + else + return make_integer_sequence_impl(); +} + +template +using MakeIntegerSequence = decltype(make_integer_sequence_impl()); + +template +using MakeIndexSequence = MakeIntegerSequence; + +template +struct __IdentityType { + using Type = T; +}; + +template +using IdentityType = typename __IdentityType::Type; + +template +requires(IsEnum) using UnderlyingType = __underlying_type(T); + +template +inline constexpr bool IsTrivial = __is_trivial(T); + +template +inline constexpr bool IsTriviallyCopyable = __is_trivially_copyable(T); + +} +using AK::Detail::AddConst; +using AK::Detail::Conditional; +using AK::Detail::CopyConst; +using AK::Detail::DependentFalse; +using AK::Detail::EnableIf; +using AK::Detail::FalseType; +using AK::Detail::IdentityType; +using AK::Detail::IndexSequence; +using AK::Detail::IntegerSequence; +using AK::Detail::IsArithmetic; +using AK::Detail::IsBaseOf; +using AK::Detail::IsClass; +using AK::Detail::IsConst; +using AK::Detail::IsEnum; +using AK::Detail::IsFloatingPoint; +using AK::Detail::IsFunction; +using AK::Detail::IsFundamental; +using AK::Detail::IsIntegral; +using AK::Detail::IsLvalueReference; +using AK::Detail::IsNullPointer; +using AK::Detail::IsPointer; +using AK::Detail::IsRvalueReference; +using AK::Detail::IsSame; +using AK::Detail::IsSigned; +using AK::Detail::IsTrivial; +using AK::Detail::IsTriviallyCopyable; +using AK::Detail::IsUnion; +using AK::Detail::IsUnsigned; +using AK::Detail::IsVoid; +using AK::Detail::MakeIndexSequence; +using AK::Detail::MakeIntegerSequence; +using AK::Detail::MakeSigned; +using AK::Detail::MakeUnsigned; +using AK::Detail::RemoveConst; +using AK::Detail::RemoveCV; +using AK::Detail::RemovePointer; +using AK::Detail::RemoveReference; +using AK::Detail::RemoveVolatile; +using AK::Detail::TrueType; +using AK::Detail::UnderlyingType; +using AK::Detail::Void; diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index c46ad6e86d..8f1845b6d3 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -26,6 +26,8 @@ #pragma once +#include + #include constexpr unsigned round_up_to_power_of_two(unsigned value, unsigned power_of_two) @@ -52,6 +54,19 @@ namespace AK { template auto declval() -> T; +template +constexpr T&& forward(RemoveReference& param) +{ + return static_cast(param); +} + +template +constexpr T&& forward(RemoveReference&& param) noexcept +{ + static_assert(!IsLvalueReference, "Can't forward an rvalue as an lvalue."); + return static_cast(param); +} + template constexpr SizeType array_size(T (&)[N]) { @@ -99,359 +114,6 @@ inline void swap(T& a, U& b) b = move(tmp); } -template -struct EnableIf { -}; - -template -struct EnableIf { - using Type = T; -}; - -template -struct AddConst { - using Type = const T; -}; - -template -struct RemoveConst { - using Type = T; -}; - -template -struct RemoveConst { - using Type = T; -}; - -template -struct RemoveVolatile { - using Type = T; -}; -template -struct RemoveVolatile { - using Type = T; -}; -template -struct RemoveCV { - using Type = typename RemoveVolatile::Type>::Type; -}; - -template -struct IntegralConstant { - static constexpr T value = v; - using ValueType = T; - using Type = IntegralConstant; - constexpr operator ValueType() const { return value; } - constexpr ValueType operator()() const { return value; } -}; - -using FalseType = IntegralConstant; -using TrueType = IntegralConstant; -template -using VoidType = void; - -template -struct IsLvalueReference : FalseType { -}; - -template -struct IsLvalueReference : TrueType { -}; - -template -struct __IsPointerHelper : FalseType { -}; - -template -struct __IsPointerHelper : TrueType { -}; - -template -struct IsPointer : __IsPointerHelper::Type> { -}; - -template -struct IsFunction : FalseType { -}; - -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; - -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; - -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; -template -struct IsFunction : TrueType { -}; - -template -struct IsRvalueReference : FalseType { -}; -template -struct IsRvalueReference : TrueType { -}; - -template -struct RemovePointer { - using Type = T; -}; -template -struct RemovePointer { - using Type = T; -}; -template -struct RemovePointer { - using Type = T; -}; -template -struct RemovePointer { - using Type = T; -}; -template -struct RemovePointer { - using Type = T; -}; - -template -struct IsSame { - static constexpr bool value = false; -}; - -template -struct IsSame { - static constexpr bool value = true; -}; - -template -struct Conditional { - using Type = TrueType; -}; - -template -struct Conditional { - using Type = FalseType; -}; - -template -struct IsNullPointer : IsSame::Type> { -}; - -template -struct RemoveReference { - using Type = T; -}; -template -struct RemoveReference { - using Type = T; -}; -template -struct RemoveReference { - using Type = T; -}; - -template -constexpr T&& forward(typename RemoveReference::Type& param) -{ - return static_cast(param); -} - -template -constexpr T&& forward(typename RemoveReference::Type&& param) noexcept -{ - static_assert(!IsLvalueReference::value, "Can't forward an rvalue as an lvalue."); - return static_cast(param); -} - -template -struct MakeUnsigned { - using Type = void; -}; -template<> -struct MakeUnsigned { - using Type = unsigned char; -}; -template<> -struct MakeUnsigned { - using Type = unsigned short; -}; -template<> -struct MakeUnsigned { - using Type = unsigned int; -}; -template<> -struct MakeUnsigned { - using Type = unsigned long; -}; -template<> -struct MakeUnsigned { - using Type = unsigned long long; -}; -template<> -struct MakeUnsigned { - using Type = unsigned char; -}; -template<> -struct MakeUnsigned { - using Type = unsigned short; -}; -template<> -struct MakeUnsigned { - using Type = unsigned int; -}; -template<> -struct MakeUnsigned { - using Type = unsigned long; -}; -template<> -struct MakeUnsigned { - using Type = unsigned long long; -}; -template<> -struct MakeUnsigned { - using Type = unsigned char; -}; -template<> -struct MakeUnsigned { - using Type = char8_t; -}; -template<> -struct MakeUnsigned { - using Type = char16_t; -}; -template<> -struct MakeUnsigned { - using Type = char32_t; -}; -template<> -struct MakeUnsigned { - using Type = bool; -}; - -template -struct MakeSigned { -}; -template<> -struct MakeSigned { - using Type = signed char; -}; -template<> -struct MakeSigned { - using Type = short; -}; -template<> -struct MakeSigned { - using Type = int; -}; -template<> -struct MakeSigned { - using Type = long; -}; -template<> -struct MakeSigned { - using Type = long long; -}; -template<> -struct MakeSigned { - using Type = char; -}; -template<> -struct MakeSigned { - using Type = short; -}; -template<> -struct MakeSigned { - using Type = int; -}; -template<> -struct MakeSigned { - using Type = long; -}; -template<> -struct MakeSigned { - using Type = long long; -}; -template<> -struct MakeSigned { - using Type = signed char; -}; - -template -struct IsVoid : IsSame::Type> { -}; - -template -struct IsConst : FalseType { -}; - -template -struct IsConst : TrueType { -}; - template constexpr T exchange(T& slot, U&& value) { @@ -460,183 +122,14 @@ constexpr T exchange(T& slot, U&& value) return old_value; } -template -struct IsEnum : public IntegralConstant { -}; - -template -struct IsUnion : public IntegralConstant { -}; - -template -struct IsClass : public IntegralConstant { -}; - -template -struct IsBaseOf : public IntegralConstant { -}; - -template -constexpr bool is_trivial() -{ - return __is_trivial(T); } -template -constexpr bool is_trivially_copyable() -{ - return __is_trivially_copyable(T); -} - -template -struct __IsIntegral : FalseType { -}; -template<> -struct __IsIntegral : TrueType { -}; -template<> -struct __IsIntegral : TrueType { -}; -template<> -struct __IsIntegral : TrueType { -}; -template<> -struct __IsIntegral : TrueType { -}; -template<> -struct __IsIntegral : TrueType { -}; -template<> -struct __IsIntegral : TrueType { -}; -template<> -struct __IsIntegral : TrueType { -}; -template<> -struct __IsIntegral : TrueType { -}; -template<> -struct __IsIntegral : TrueType { -}; -template -using IsIntegral = __IsIntegral::Type>::Type>; - -template -struct __IsFloatingPoint : FalseType { -}; -template<> -struct __IsFloatingPoint : TrueType { -}; -template<> -struct __IsFloatingPoint : TrueType { -}; -template<> -struct __IsFloatingPoint : TrueType { -}; -template -using IsFloatingPoint = __IsFloatingPoint::Type>; - -template -using CopyConst = - typename Conditional::value, typename AddConst::Type, typename RemoveConst::Type>::Type; - -template -using Void = void; - -template -constexpr auto DependentFalse = false; - -template -using IsSigned = IsSame::Type>; - -template -using IsUnsigned = IsSame::Type>; - -template -using IsArithmetic = IntegralConstant::value || IsFloatingPoint::value>; - -template -using IsFundamental = IntegralConstant::value || IsVoid::value || IsNullPointer::value>; - -template -struct IntegerSequence { - using Type = T; - static constexpr unsigned size() noexcept { return sizeof...(Ts); }; -}; - -template -using IndexSequence = IntegerSequence; - -template -auto make_integer_sequence_impl() -{ - if constexpr (N == 0) - return IntegerSequence {}; - else - return make_integer_sequence_impl(); -} - -template -using MakeIntegerSequence = decltype(make_integer_sequence_impl()); - -template -using MakeIndexSequence = MakeIntegerSequence; - -template -struct IdentityType { - using Type = T; -}; - -template::value> -struct __UnderlyingType { - using Type = __underlying_type(T); -}; - -template -struct __UnderlyingType { -}; - -template -struct UnderlyingType : __UnderlyingType { -}; - -} - -using AK::AddConst; using AK::array_size; using AK::ceil_div; using AK::clamp; -using AK::Conditional; using AK::declval; -using AK::DependentFalse; using AK::exchange; using AK::forward; -using AK::IdentityType; -using AK::IndexSequence; -using AK::IntegerSequence; -using AK::is_trivial; -using AK::is_trivially_copyable; -using AK::IsArithmetic; -using AK::IsBaseOf; -using AK::IsClass; -using AK::IsConst; -using AK::IsEnum; -using AK::IsFloatingPoint; -using AK::IsFundamental; -using AK::IsIntegral; -using AK::IsNullPointer; -using AK::IsSame; -using AK::IsSigned; -using AK::IsUnion; -using AK::IsUnsigned; -using AK::IsVoid; -using AK::MakeIndexSequence; -using AK::MakeIntegerSequence; -using AK::MakeSigned; -using AK::MakeUnsigned; using AK::max; using AK::min; -using AK::RemoveConst; using AK::swap; -using AK::UnderlyingType; -using AK::Void; diff --git a/AK/Stream.h b/AK/Stream.h index a1226c44fa..5e6ac3f6ee 100644 --- a/AK/Stream.h +++ b/AK/Stream.h @@ -148,13 +148,13 @@ InputStream& operator>>(InputStream& stream, Optional& value) } template -InputStream& operator>>(InputStream& stream, Integral& value) requires IsIntegral::value +InputStream& operator>>(InputStream& stream, Integral& value) requires IsIntegral { stream.read_or_error({ &value, sizeof(value) }); return stream; } template -OutputStream& operator<<(OutputStream& stream, Integral value) requires IsIntegral::value +OutputStream& operator<<(OutputStream& stream, Integral value) requires IsIntegral { stream.write_or_error({ &value, sizeof(value) }); return stream; @@ -163,13 +163,13 @@ OutputStream& operator<<(OutputStream& stream, Integral value) requires IsIntegr #ifndef KERNEL template -InputStream& operator>>(InputStream& stream, FloatingPoint& value) requires IsFloatingPoint::value +InputStream& operator>>(InputStream& stream, FloatingPoint& value) requires IsFloatingPoint { stream.read_or_error({ &value, sizeof(value) }); return stream; } template -OutputStream& operator<<(OutputStream& stream, FloatingPoint value) requires IsFloatingPoint::value +OutputStream& operator<<(OutputStream& stream, FloatingPoint value) requires IsFloatingPoint { stream.write_or_error({ &value, sizeof(value) }); return stream; diff --git a/AK/String.h b/AK/String.h index 6d7e8f31da..d8f5110d99 100644 --- a/AK/String.h +++ b/AK/String.h @@ -276,7 +276,7 @@ public: } template - static String number(T value) requires IsArithmetic::value + static String number(T value) requires IsArithmetic { return formatted("{}", value); } diff --git a/AK/Tests/TestBadge.cpp b/AK/Tests/TestBadge.cpp index dea46a91b8..fb5d9d86d8 100644 --- a/AK/Tests/TestBadge.cpp +++ b/AK/Tests/TestBadge.cpp @@ -30,7 +30,7 @@ TEST_CASE(should_provide_underlying_type) { - static_assert(IsSame::Type>::value); + static_assert(IsSame::Type>); } TEST_MAIN(Badge) diff --git a/AK/Tests/TestFormat.cpp b/AK/Tests/TestFormat.cpp index 22a754b424..6ee5b8ed55 100644 --- a/AK/Tests/TestFormat.cpp +++ b/AK/Tests/TestFormat.cpp @@ -31,8 +31,8 @@ TEST_CASE(is_integral_works_properly) { - EXPECT(!IsIntegral::value); - EXPECT(IsIntegral::value); + EXPECT(!IsIntegral); + EXPECT(IsIntegral); } TEST_CASE(format_string_literals) diff --git a/AK/Tests/TestIndexSequence.cpp b/AK/Tests/TestIndexSequence.cpp index 8ae15cfea5..296e802674 100644 --- a/AK/Tests/TestIndexSequence.cpp +++ b/AK/Tests/TestIndexSequence.cpp @@ -46,14 +46,14 @@ TEST_CASE(TestIndexSequence) { constexpr auto integer_seq1 = IntegerSequence {}; constexpr auto integer_seq2 = MakeIntegerSequence {}; - static_assert(IsSame::value, ""); + static_assert(IsSame, ""); static_assert(integer_seq1.size() == 5, ""); static_assert(integer_seq2.size() == 5, ""); constexpr auto index_seq1 = IndexSequence<0, 1, 2> {}; constexpr auto index_seq2 = MakeIndexSequence<3> {}; - static_assert(IsSame::value, ""); + static_assert(IsSame, ""); verify_sequence(MakeIndexSequence<10> {}, std::initializer_list { 0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 9U }); verify_sequence(MakeIntegerSequence {}, std::initializer_list { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }); @@ -62,9 +62,9 @@ TEST_CASE(TestIndexSequence) TEST_CASE(TypeList) { using MyTypes = TypeList; - static_assert(IsSame, int>::value, ""); - static_assert(IsSame, bool>::value, ""); - static_assert(IsSame, char>::value, ""); + static_assert(IsSame, int>, ""); + static_assert(IsSame, bool>, ""); + static_assert(IsSame, char>, ""); } TEST_MAIN(IndexSequence); diff --git a/AK/Tests/TestSpan.cpp b/AK/Tests/TestSpan.cpp index 9a4a6d76b1..1b8c3cb14b 100644 --- a/AK/Tests/TestSpan.cpp +++ b/AK/Tests/TestSpan.cpp @@ -49,7 +49,7 @@ TEST_CASE(span_works_with_constant_types) static constexpr u8 buffer[4] { 1, 2, 3, 4 }; constexpr ReadonlyBytes bytes { buffer, 4 }; - static_assert(IsConst::Type>::value); + static_assert(IsConst>); static_assert(bytes[2] == 3); } diff --git a/AK/Tests/TestTypeTraits.cpp b/AK/Tests/TestTypeTraits.cpp index 1b13d71903..d77c995417 100644 --- a/AK/Tests/TestTypeTraits.cpp +++ b/AK/Tests/TestTypeTraits.cpp @@ -29,13 +29,13 @@ #include #define STATIC_EXPECT_EQ(lhs, rhs) \ - static_assert(IsSame::value, ""); + static_assert(IsSame, ""); #define STATIC_EXPECT_FALSE(Expression) \ - static_assert(!Expression::value, ""); + static_assert(!Expression, ""); #define STATIC_EXPECT_TRUE(Expression) \ - static_assert(Expression::value, ""); + static_assert(Expression, ""); #define EXPECT_TRAIT_TRUE(trait, ...) \ for_each_type>([](TypeWrapper) { \ @@ -49,7 +49,7 @@ #define EXPECT_EQ_WITH_TRAIT(trait, ListA, ListB) \ for_each_type_zipped([](TypeWrapper, TypeWrapper) { \ - STATIC_EXPECT_EQ(typename trait::Type, B); \ + STATIC_EXPECT_EQ(trait, B); \ }) struct Empty { @@ -120,7 +120,7 @@ TEST_CASE(AddConst) TEST_CASE(UnderlyingType) { - using Type = UnderlyingType::Type; + using Type = UnderlyingType; STATIC_EXPECT_EQ(Type, u8); } diff --git a/AK/Trie.h b/AK/Trie.h index 190344670e..3ed6d77cbf 100644 --- a/AK/Trie.h +++ b/AK/Trie.h @@ -140,9 +140,9 @@ public: return const_cast(this)->traverse_until_last_accessible_node(it, end); } - Optional metadata() const requires(!IsNullPointer::value) { return m_metadata; } - void set_metadata(MetadataType metadata) requires(!IsNullPointer::value) { m_metadata = move(metadata); } - const MetadataType& metadata_value() const requires(!IsNullPointer::value) { return m_metadata.value(); } + Optional metadata() const requires(!IsNullPointer) { return m_metadata; } + void set_metadata(MetadataType metadata) requires(!IsNullPointer) { m_metadata = move(metadata); } + const MetadataType& metadata_value() const requires(!IsNullPointer) { return m_metadata.value(); } const ValueType& value() const { return m_value; } ValueType& value() { return m_value; } @@ -165,7 +165,7 @@ public: template BaseType& insert( - It& it, const It& end, MetadataType metadata, ProvideMetadataFunction provide_missing_metadata) requires(!IsNullPointer::value) + It& it, const It& end, MetadataType metadata, ProvideMetadataFunction provide_missing_metadata) requires(!IsNullPointer) { Trie* last_root_node = &traverse_until_last_accessible_node(it, end); for (; it != end; ++it) @@ -175,7 +175,7 @@ public: } template - BaseType& insert(It& it, const It& end) requires(IsNullPointer::value) + BaseType& insert(It& it, const It& end) requires(IsNullPointer) { Trie* last_root_node = &traverse_until_last_accessible_node(it, end); for (; it != end; ++it) @@ -185,14 +185,14 @@ public: template BaseType& insert( - const It& begin, const It& end, MetadataType metadata, ProvideMetadataFunction provide_missing_metadata) requires(!IsNullPointer::value) + const It& begin, const It& end, MetadataType metadata, ProvideMetadataFunction provide_missing_metadata) requires(!IsNullPointer) { auto it = begin; return insert(it, end, move(metadata), move(provide_missing_metadata)); } template - BaseType& insert(const It& begin, const It& end) requires(IsNullPointer::value) + BaseType& insert(const It& begin, const It& end) requires(IsNullPointer) { auto it = begin; return insert(it, end); @@ -231,7 +231,7 @@ public: using DetailTrie = Detail::Trie, ValueType, MetadataT, ValueTraits>; using MetadataType = typename DetailTrie::MetadataType; - Trie(ValueType value, MetadataType metadata) requires(!IsVoid::value && !IsNullPointer::value) + Trie(ValueType value, MetadataType metadata) requires(!IsVoid && !IsNullPointer) : DetailTrie(move(value), move(metadata)) { } diff --git a/AK/TypeCasts.h b/AK/TypeCasts.h index 0e8f4e50ae..f70631a6d0 100644 --- a/AK/TypeCasts.h +++ b/AK/TypeCasts.h @@ -50,7 +50,7 @@ ALWAYS_INLINE bool is(InputType* input) template ALWAYS_INLINE CopyConst* downcast(InputType* input) { - static_assert(IsBaseOf::value); + static_assert(IsBaseOf); VERIFY(!input || is(*input)); return static_cast*>(input); } @@ -58,7 +58,7 @@ ALWAYS_INLINE CopyConst* downcast(InputType* input) template ALWAYS_INLINE CopyConst& downcast(InputType& input) { - static_assert(IsBaseOf::value); + static_assert(IsBaseOf); VERIFY(is(input)); return static_cast&>(input); } diff --git a/AK/Types.h b/AK/Types.h index c4b09c9f75..a80154cdef 100644 --- a/AK/Types.h +++ b/AK/Types.h @@ -42,7 +42,7 @@ using i8 = __INT8_TYPE__; #ifdef __serenity__ using size_t = __SIZE_TYPE__; -using ssize_t = MakeSigned::Type; +using ssize_t = MakeSigned; using ptrdiff_t = __PTRDIFF_TYPE__; @@ -72,7 +72,7 @@ using __ptrdiff_t = __PTRDIFF_TYPE__; #endif -using FlatPtr = Conditional::Type; +using FlatPtr = Conditional; constexpr u64 KiB = 1024; constexpr u64 MiB = KiB * KiB; diff --git a/AK/Userspace.h b/AK/Userspace.h index c769468ec4..49e9aa7410 100644 --- a/AK/Userspace.h +++ b/AK/Userspace.h @@ -36,10 +36,10 @@ namespace AK { // Once it supports C++20 concepts, we can remove this. #if defined(__cpp_concepts) && !defined(__COVERITY__) template -concept PointerTypeName = IsPointer::value; +concept PointerTypeName = IsPointer; template #else -template::value, int>::Type = 0> +template, int>::Type = 0> #endif class Userspace { diff --git a/AK/WeakPtr.h b/AK/WeakPtr.h index 59bffa273a..f4e41281db 100644 --- a/AK/WeakPtr.h +++ b/AK/WeakPtr.h @@ -38,26 +38,26 @@ class WeakPtr { public: WeakPtr() = default; - template::value>::Type* = nullptr> + template>::Type* = nullptr> WeakPtr(const WeakPtr& other) : m_link(other.m_link) { } - template::value>::Type* = nullptr> + template>::Type* = nullptr> WeakPtr(WeakPtr&& other) : m_link(other.take_link()) { } - template::value>::Type* = nullptr> + template>::Type* = nullptr> WeakPtr& operator=(WeakPtr&& other) { m_link = other.take_link(); return *this; } - template::value>::Type* = nullptr> + template>::Type* = nullptr> WeakPtr& operator=(const WeakPtr& other) { if ((const void*)this != (const void*)&other) @@ -71,20 +71,20 @@ public: return *this; } - template::value>::Type* = nullptr> + template>::Type* = nullptr> WeakPtr(const U& object) : m_link(object.template make_weak_ptr().take_link()) { } - template::value>::Type* = nullptr> + template>::Type* = nullptr> WeakPtr(const U* object) { if (object) m_link = object->template make_weak_ptr().take_link(); } - template::value>::Type* = nullptr> + template>::Type* = nullptr> WeakPtr(const RefPtr& object) { object.do_while_locked([&](U* obj) { @@ -93,7 +93,7 @@ public: }); } - template::value>::Type* = nullptr> + template>::Type* = nullptr> WeakPtr(const NonnullRefPtr& object) { object.do_while_locked([&](U* obj) { @@ -102,14 +102,14 @@ public: }); } - template::value>::Type* = nullptr> + template>::Type* = nullptr> WeakPtr& operator=(const U& object) { m_link = object.template make_weak_ptr().take_link(); return *this; } - template::value>::Type* = nullptr> + template>::Type* = nullptr> WeakPtr& operator=(const U* object) { if (object) @@ -119,7 +119,7 @@ public: return *this; } - template::value>::Type* = nullptr> + template>::Type* = nullptr> WeakPtr& operator=(const RefPtr& object) { object.do_while_locked([&](U* obj) { @@ -131,7 +131,7 @@ public: return *this; } - template::value>::Type* = nullptr> + template>::Type* = nullptr> WeakPtr& operator=(const NonnullRefPtr& object) { object.do_while_locked([&](U* obj) { @@ -199,7 +199,7 @@ template template inline WeakPtr Weakable::make_weak_ptr() const { - if constexpr (IsBaseOf::value) { + if constexpr (IsBaseOf) { // Checking m_being_destroyed isn't sufficient when dealing with // a RefCounted type.The reference count will drop to 0 before the // destructor is invoked and revoke_weak_ptrs is called. So, try @@ -223,7 +223,7 @@ inline WeakPtr Weakable::make_weak_ptr() const WeakPtr weak_ptr(m_link); - if constexpr (IsBaseOf::value) { + if constexpr (IsBaseOf) { // Now drop the reference we temporarily added if (static_cast(this)->unref()) { // We just dropped the last reference, which should have called diff --git a/AK/Weakable.h b/AK/Weakable.h index 605acfb2ee..2781fdd028 100644 --- a/AK/Weakable.h +++ b/AK/Weakable.h @@ -49,7 +49,7 @@ class WeakLink : public RefCounted { friend class WeakPtr; public: - template, typename EnableIf::value>::Type* = nullptr> + template, typename EnableIf>::Type* = nullptr> RefPtr strong_ref() const { RefPtr ref; diff --git a/Kernel/StdLib.h b/Kernel/StdLib.h index c00447b8b1..d11ab36ea4 100644 --- a/Kernel/StdLib.h +++ b/Kernel/StdLib.h @@ -77,28 +77,28 @@ const void* memmem(const void* haystack, size_t, const void* needle, size_t); template [[nodiscard]] inline bool copy_from_user(T* dest, const T* src) { - static_assert(is_trivially_copyable()); + static_assert(IsTriviallyCopyable); return copy_from_user(dest, src, sizeof(T)); } template [[nodiscard]] inline bool copy_to_user(T* dest, const T* src) { - static_assert(is_trivially_copyable()); + static_assert(IsTriviallyCopyable); return copy_to_user(dest, src, sizeof(T)); } template [[nodiscard]] inline bool copy_from_user(T* dest, Userspace src) { - static_assert(is_trivially_copyable()); + static_assert(IsTriviallyCopyable); return copy_from_user(dest, src.unsafe_userspace_ptr(), sizeof(T)); } template [[nodiscard]] inline bool copy_from_user(T* dest, Userspace src) { - static_assert(is_trivially_copyable()); + static_assert(IsTriviallyCopyable); return copy_from_user(dest, src.unsafe_userspace_ptr(), sizeof(T)); } @@ -125,28 +125,28 @@ DEPRECATE_COPY_FROM_USER_TYPE(timeval, copy_time_from_user) template [[nodiscard]] inline bool copy_to_user(Userspace dest, const T* src) { - static_assert(is_trivially_copyable()); + static_assert(IsTriviallyCopyable); return copy_to_user(dest.unsafe_userspace_ptr(), src, sizeof(T)); } template [[nodiscard]] inline bool copy_to_user(Userspace dest, const void* src, size_t size) { - static_assert(is_trivially_copyable()); + static_assert(IsTriviallyCopyable); return copy_to_user(dest.unsafe_userspace_ptr(), src, size); } template [[nodiscard]] inline bool copy_from_user(void* dest, Userspace src, size_t size) { - static_assert(is_trivially_copyable()); + static_assert(IsTriviallyCopyable); return copy_from_user(dest, src.unsafe_userspace_ptr(), size); } template [[nodiscard]] inline bool copy_n_from_user(T* dest, const T* src, size_t count) { - static_assert(is_trivially_copyable()); + static_assert(IsTriviallyCopyable); Checked size = sizeof(T); size *= count; if (size.has_overflow()) @@ -157,7 +157,7 @@ template template [[nodiscard]] inline bool copy_n_to_user(T* dest, const T* src, size_t count) { - static_assert(is_trivially_copyable()); + static_assert(IsTriviallyCopyable); Checked size = sizeof(T); size *= count; if (size.has_overflow()) @@ -168,7 +168,7 @@ template template [[nodiscard]] inline bool copy_n_from_user(T* dest, Userspace src, size_t count) { - static_assert(is_trivially_copyable()); + static_assert(IsTriviallyCopyable); Checked size = sizeof(T); size *= count; if (size.has_overflow()) @@ -179,7 +179,7 @@ template template [[nodiscard]] inline bool copy_n_to_user(Userspace dest, const T* src, size_t count) { - static_assert(is_trivially_copyable()); + static_assert(IsTriviallyCopyable); Checked size = sizeof(T); size *= count; if (size.has_overflow()) diff --git a/Userland/Libraries/LibC/scanf.cpp b/Userland/Libraries/LibC/scanf.cpp index 9676388e43..f7d676ad9b 100644 --- a/Userland/Libraries/LibC/scanf.cpp +++ b/Userland/Libraries/LibC/scanf.cpp @@ -277,19 +277,19 @@ struct ReadElement { case Short: return ReadElementConcrete {}(input_lexer, ap); case Long: - if constexpr (IsSame::value) + if constexpr (IsSame) return ReadElementConcrete {}(input_lexer, ap); - if constexpr (IsSame::value) + if constexpr (IsSame) return ReadElementConcrete {}(input_lexer, ap); - if constexpr (IsSame::value) + if constexpr (IsSame) return ReadElementConcrete {}(input_lexer, ap); return false; case LongLong: - if constexpr (IsSame::value) + if constexpr (IsSame) return ReadElementConcrete {}(input_lexer, ap); - if constexpr (IsSame::value) + if constexpr (IsSame) return ReadElementConcrete {}(input_lexer, ap); - if constexpr (IsSame::value) + if constexpr (IsSame) return ReadElementConcrete {}(input_lexer, ap); return false; case IntMax: diff --git a/Userland/Libraries/LibCore/AnonymousBuffer.h b/Userland/Libraries/LibCore/AnonymousBuffer.h index d65f892175..fe5a91a0f9 100644 --- a/Userland/Libraries/LibCore/AnonymousBuffer.h +++ b/Userland/Libraries/LibCore/AnonymousBuffer.h @@ -68,7 +68,7 @@ public: template T* data() { - static_assert(IsVoid::value || is_trivial()); + static_assert(IsVoid || IsTrivial); if (!m_impl) return nullptr; return (T*)m_impl->data(); @@ -77,7 +77,7 @@ public: template const T* data() const { - static_assert(IsVoid::value || is_trivial()); + static_assert(IsVoid || IsTrivial); if (!m_impl) return nullptr; return (const T*)m_impl->data(); diff --git a/Userland/Libraries/LibCore/Object.h b/Userland/Libraries/LibCore/Object.h index 105ca91260..4b0ced96be 100644 --- a/Userland/Libraries/LibCore/Object.h +++ b/Userland/Libraries/LibCore/Object.h @@ -90,13 +90,13 @@ public: } template - void for_each_child_of_type(Callback callback) requires IsBaseOf::value; + void for_each_child_of_type(Callback callback) requires IsBaseOf; template - T* find_child_of_type_named(const String&) requires IsBaseOf::value; + T* find_child_of_type_named(const String&) requires IsBaseOf; template - T* find_descendant_of_type_named(const String&) requires IsBaseOf::value; + T* find_descendant_of_type_named(const String&) requires IsBaseOf; bool is_ancestor_of(const Object&) const; @@ -187,7 +187,7 @@ struct AK::Formatter : AK::Formatter { namespace Core { template -inline void Object::for_each_child_of_type(Callback callback) requires IsBaseOf::value +inline void Object::for_each_child_of_type(Callback callback) requires IsBaseOf { for_each_child([&](auto& child) { if (auto* child_as_t = dynamic_cast(&child); child_as_t) @@ -197,7 +197,7 @@ inline void Object::for_each_child_of_type(Callback callback) requires IsBaseOf< } template -T* Object::find_child_of_type_named(const String& name) requires IsBaseOf::value +T* Object::find_child_of_type_named(const String& name) requires IsBaseOf { T* found_child = nullptr; for_each_child_of_type([&](auto& child) { @@ -212,7 +212,7 @@ T* Object::find_child_of_type_named(const String& name) requires IsBaseOf -T* Object::find_descendant_of_type_named(const String& name) requires IsBaseOf::value +T* Object::find_descendant_of_type_named(const String& name) requires IsBaseOf { auto* this_as_t = dynamic_cast(this); if (this_as_t && this->name() == name) diff --git a/Userland/Libraries/LibGUI/ItemListModel.h b/Userland/Libraries/LibGUI/ItemListModel.h index 8226a51342..30947404d3 100644 --- a/Userland/Libraries/LibGUI/ItemListModel.h +++ b/Userland/Libraries/LibGUI/ItemListModel.h @@ -37,13 +37,13 @@ class ItemListModel : public Model { public: static constexpr auto IsTwoDimensional = requires(Container data) { - requires !IsVoid::value; + requires !IsVoid; data.at(0).at(0); data.at(0).size(); }; // Substitute 'void' for a dummy u8. - using ColumnNamesT = typename Conditional::value, u8, ColumnNameListType>::Type; + using ColumnNamesT = Conditional, u8, ColumnNameListType>; static NonnullRefPtr create(const Container& data, const ColumnNamesT& column_names, const Optional& row_count = {}) requires(IsTwoDimensional) { diff --git a/Userland/Libraries/LibGfx/Filters/SpatialGaussianBlurFilter.h b/Userland/Libraries/LibGfx/Filters/SpatialGaussianBlurFilter.h index 8bf8d414ca..54ad5744c4 100644 --- a/Userland/Libraries/LibGfx/Filters/SpatialGaussianBlurFilter.h +++ b/Userland/Libraries/LibGfx/Filters/SpatialGaussianBlurFilter.h @@ -31,7 +31,7 @@ namespace Gfx { -template::Type> +template::Type> class SpatialGaussianBlurFilter : public GenericConvolutionFilter { public: SpatialGaussianBlurFilter() { } diff --git a/Userland/Libraries/LibJS/Heap/Heap.h b/Userland/Libraries/LibJS/Heap/Heap.h index c36bc34539..fefa4aa5c3 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.h +++ b/Userland/Libraries/LibJS/Heap/Heap.h @@ -62,7 +62,7 @@ public: auto* memory = allocate_cell(sizeof(T)); new (memory) T(forward(args)...); auto* cell = static_cast(memory); - constexpr bool is_object = IsBaseOf::value; + constexpr bool is_object = IsBaseOf; if constexpr (is_object) static_cast(cell)->disable_transitions(); cell->initialize(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h index 0b580be39d..2110dd30b2 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.h +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h @@ -101,7 +101,7 @@ public: return Value((i32)data()[property_index]); } else if constexpr (sizeof(T) == 4 || sizeof(T) == 8) { auto value = data()[property_index]; - if constexpr (IsFloatingPoint::value) { + if constexpr (IsFloatingPoint) { return Value((double)value); } else if constexpr (NumericLimits::is_signed()) { if (value > NumericLimits::max() || value < NumericLimits::min()) diff --git a/Userland/Libraries/LibThread/Thread.h b/Userland/Libraries/LibThread/Thread.h index 7fff078827..ea19753082 100644 --- a/Userland/Libraries/LibThread/Thread.h +++ b/Userland/Libraries/LibThread/Thread.h @@ -68,7 +68,7 @@ Result Thread::join() } m_tid = 0; - if constexpr (IsVoid::value) + if constexpr (IsVoid) return {}; else return { static_cast(thread_return) }; diff --git a/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h b/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h index dc75dd123c..463e3bc495 100644 --- a/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h +++ b/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h @@ -34,12 +34,10 @@ namespace Web::Bindings { template -struct IsExceptionOr : AK::FalseType { -}; +constexpr bool IsExceptionOr = false; template -struct IsExceptionOr> : AK::TrueType { -}; +constexpr bool IsExceptionOr> = true; template ALWAYS_INLINE bool throw_dom_exception(JS::VM& vm, JS::GlobalObject& global_object, DOM::ExceptionOr& result) @@ -51,17 +49,17 @@ ALWAYS_INLINE bool throw_dom_exception(JS::VM& vm, JS::GlobalObject& global_obje return false; } -template()()), typename Ret = typename Conditional::value && !IsVoid::value, T, JS::Value>::Type> +template()()), typename Ret = Conditional && !IsVoid, T, JS::Value>> Ret throw_dom_exception_if_needed(auto&& vm, auto&& global_object, F&& fn) { - if constexpr (IsExceptionOr::value) { + if constexpr (IsExceptionOr) { auto&& result = fn(); if (throw_dom_exception(vm, global_object, result)) return JS::Value(); if constexpr (requires(T v) { v.value(); }) return result.value(); return JS::Value(); - } else if constexpr (IsVoid::value) { + } else if constexpr (IsVoid) { fn(); return JS::js_undefined(); } else { @@ -72,7 +70,7 @@ Ret throw_dom_exception_if_needed(auto&& vm, auto&& global_object, F&& fn) template bool should_return_empty(T&& value) { - if constexpr (IsSame::value) + if constexpr (IsSame) return value.is_empty(); return false; } diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h index c51d4ad080..8d62ff7c0f 100644 --- a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h +++ b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h @@ -39,7 +39,7 @@ class Performance final , public Bindings::Wrappable { public: using WrapperType = Bindings::PerformanceWrapper; - using AllowOwnPtr = AK::TrueType; + using AllowOwnPtr = TrueType; explicit Performance(DOM::Window&); ~Performance(); diff --git a/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h index 1460ccee50..776e40e98e 100644 --- a/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h +++ b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.h @@ -34,7 +34,7 @@ namespace Web::NavigationTiming { class PerformanceTiming final : public Bindings::Wrappable { public: using WrapperType = Bindings::PerformanceTimingWrapper; - using AllowOwnPtr = AK::TrueType; + using AllowOwnPtr = TrueType; explicit PerformanceTiming(DOM::Window&); ~PerformanceTiming(); diff --git a/Userland/Libraries/LibWeb/TreeNode.h b/Userland/Libraries/LibWeb/TreeNode.h index fa4853486b..77b4139db4 100644 --- a/Userland/Libraries/LibWeb/TreeNode.h +++ b/Userland/Libraries/LibWeb/TreeNode.h @@ -49,7 +49,7 @@ public: VERIFY(!m_in_removed_last_ref); VERIFY(m_ref_count); if (!--m_ref_count) { - if constexpr (IsBaseOf::value) { + if constexpr (IsBaseOf) { m_in_removed_last_ref = true; static_cast(this)->removed_last_ref(); } else { diff --git a/Userland/Libraries/LibX86/Instruction.h b/Userland/Libraries/LibX86/Instruction.h index 0473841724..1c29ce65dd 100644 --- a/Userland/Libraries/LibX86/Instruction.h +++ b/Userland/Libraries/LibX86/Instruction.h @@ -47,7 +47,7 @@ template struct TypeTrivia { static const size_t bits = sizeof(T) * 8; static const T sign_bit = 1 << (bits - 1); - static const T mask = typename MakeUnsigned::Type(-1); + static const T mask = MakeUnsigned(-1); }; template