mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
Everywhere: Switch from EnableIf to requires
C++20 provides the `requires` clause which simplifies the ability to limit overload resolution. Prefer it over `EnableIf` With all uses of `EnableIf` being removed, also remove the implementation so future devs are not tempted.
This commit is contained in:
parent
8f7219c6fa
commit
2844f7c333
Notes:
sideshowbarker
2024-07-17 17:13:48 +09:00
Author: https://github.com/ldm5180 Commit: https://github.com/SerenityOS/serenity/commit/2844f7c333 Pull-request: https://github.com/SerenityOS/serenity/pull/13096 Reviewed-by: https://github.com/BertalanD Reviewed-by: https://github.com/alimpfard
@ -17,11 +17,11 @@ namespace AK {
|
|||||||
|
|
||||||
// FIXME: Implement Buffered<T> for DuplexStream.
|
// FIXME: Implement Buffered<T> for DuplexStream.
|
||||||
|
|
||||||
template<typename StreamType, size_t Size = 4096, typename = void>
|
template<typename StreamType, size_t Size = 4096>
|
||||||
class Buffered;
|
class Buffered;
|
||||||
|
|
||||||
template<typename StreamType, size_t Size>
|
template<typename StreamType, size_t Size>
|
||||||
class Buffered<StreamType, Size, typename EnableIf<IsBaseOf<InputStream, StreamType>>::Type> final : public InputStream {
|
requires(IsBaseOf<InputStream, StreamType>) class Buffered<StreamType, Size> final : public InputStream {
|
||||||
AK_MAKE_NONCOPYABLE(Buffered);
|
AK_MAKE_NONCOPYABLE(Buffered);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -119,7 +119,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename StreamType, size_t Size>
|
template<typename StreamType, size_t Size>
|
||||||
class Buffered<StreamType, Size, typename EnableIf<IsBaseOf<OutputStream, StreamType>>::Type> final : public OutputStream {
|
requires(IsBaseOf<OutputStream, StreamType>) class Buffered<StreamType, Size> : public OutputStream {
|
||||||
AK_MAKE_NONCOPYABLE(Buffered);
|
AK_MAKE_NONCOPYABLE(Buffered);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -192,7 +192,6 @@ private:
|
|||||||
u8 m_buffer[Size];
|
u8 m_buffer[Size];
|
||||||
size_t m_buffered { 0 };
|
size_t m_buffered { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using AK::Buffered;
|
using AK::Buffered;
|
||||||
|
@ -692,8 +692,8 @@ ErrorOr<void> Formatter<FormatString>::vformat(FormatBuilder& builder, StringVie
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<Integral T>
|
||||||
ErrorOr<void> Formatter<T, typename EnableIf<IsIntegral<T>>::Type>::format(FormatBuilder& builder, T value)
|
ErrorOr<void> Formatter<T>::format(FormatBuilder& builder, T value)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Character) {
|
if (m_mode == Mode::Character) {
|
||||||
// FIXME: We just support ASCII for now, in the future maybe unicode?
|
// FIXME: We just support ASCII for now, in the future maybe unicode?
|
||||||
|
@ -307,8 +307,8 @@ struct StandardFormatter {
|
|||||||
void parse(TypeErasedFormatParams&, FormatParser&);
|
void parse(TypeErasedFormatParams&, FormatParser&);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<Integral T>
|
||||||
struct Formatter<T, typename EnableIf<IsIntegral<T>>::Type> : StandardFormatter {
|
struct Formatter<T> : StandardFormatter {
|
||||||
Formatter() = default;
|
Formatter() = default;
|
||||||
explicit Formatter(StandardFormatter formatter)
|
explicit Formatter(StandardFormatter formatter)
|
||||||
: StandardFormatter(move(formatter))
|
: StandardFormatter(move(formatter))
|
||||||
|
@ -10,15 +10,6 @@
|
|||||||
|
|
||||||
namespace AK::Detail {
|
namespace AK::Detail {
|
||||||
|
|
||||||
template<bool B, class T = void>
|
|
||||||
struct EnableIf {
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct EnableIf<true, T> {
|
|
||||||
using Type = T;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T, T v>
|
template<class T, T v>
|
||||||
struct IntegralConstant {
|
struct IntegralConstant {
|
||||||
static constexpr T value = v;
|
static constexpr T value = v;
|
||||||
@ -591,7 +582,6 @@ using AK::Detail::Conditional;
|
|||||||
using AK::Detail::CopyConst;
|
using AK::Detail::CopyConst;
|
||||||
using AK::Detail::declval;
|
using AK::Detail::declval;
|
||||||
using AK::Detail::DependentFalse;
|
using AK::Detail::DependentFalse;
|
||||||
using AK::Detail::EnableIf;
|
|
||||||
using AK::Detail::FalseType;
|
using AK::Detail::FalseType;
|
||||||
using AK::Detail::IdentityType;
|
using AK::Detail::IdentityType;
|
||||||
using AK::Detail::IndexSequence;
|
using AK::Detail::IndexSequence;
|
||||||
|
48
AK/WeakPtr.h
48
AK/WeakPtr.h
@ -22,27 +22,27 @@ class [[nodiscard]] WeakPtr {
|
|||||||
public:
|
public:
|
||||||
WeakPtr() = default;
|
WeakPtr() = default;
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr(const WeakPtr<U>& other)
|
WeakPtr(const WeakPtr<U>& other) requires(IsBaseOf<T, U>)
|
||||||
: m_link(other.m_link)
|
: m_link(other.m_link)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr(WeakPtr<U>&& other)
|
WeakPtr(WeakPtr<U>&& other) requires(IsBaseOf<T, U>)
|
||||||
: m_link(other.take_link())
|
: m_link(other.take_link())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr& operator=(WeakPtr<U>&& other)
|
WeakPtr& operator=(WeakPtr<U>&& other) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
m_link = other.take_link();
|
m_link = other.take_link();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr& operator=(const WeakPtr<U>& other)
|
WeakPtr& operator=(const WeakPtr<U>& other) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
if ((const void*)this != (const void*)&other)
|
if ((const void*)this != (const void*)&other)
|
||||||
m_link = other.m_link;
|
m_link = other.m_link;
|
||||||
@ -55,41 +55,41 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr(const U& object)
|
WeakPtr(const U& object) requires(IsBaseOf<T, U>)
|
||||||
: m_link(object.template make_weak_ptr<U>().take_link())
|
: m_link(object.template make_weak_ptr<U>().take_link())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr(const U* object)
|
WeakPtr(const U* object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
if (object)
|
if (object)
|
||||||
m_link = object->template make_weak_ptr<U>().take_link();
|
m_link = object->template make_weak_ptr<U>().take_link();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr(RefPtr<U> const& object)
|
WeakPtr(RefPtr<U> const& object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
if (object)
|
if (object)
|
||||||
m_link = object->template make_weak_ptr<U>().take_link();
|
m_link = object->template make_weak_ptr<U>().take_link();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr(NonnullRefPtr<U> const& object)
|
WeakPtr(NonnullRefPtr<U> const& object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
m_link = object->template make_weak_ptr<U>().take_link();
|
m_link = object->template make_weak_ptr<U>().take_link();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr& operator=(const U& object)
|
WeakPtr& operator=(const U& object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
m_link = object.template make_weak_ptr<U>().take_link();
|
m_link = object.template make_weak_ptr<U>().take_link();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr& operator=(const U* object)
|
WeakPtr& operator=(const U* object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
if (object)
|
if (object)
|
||||||
m_link = object->template make_weak_ptr<U>().take_link();
|
m_link = object->template make_weak_ptr<U>().take_link();
|
||||||
@ -98,8 +98,8 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr& operator=(const RefPtr<U>& object)
|
WeakPtr& operator=(const RefPtr<U>& object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
if (object)
|
if (object)
|
||||||
m_link = object->template make_weak_ptr<U>().take_link();
|
m_link = object->template make_weak_ptr<U>().take_link();
|
||||||
@ -108,8 +108,8 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr& operator=(const NonnullRefPtr<U>& object)
|
WeakPtr& operator=(const NonnullRefPtr<U>& object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
m_link = object->template make_weak_ptr<U>().take_link();
|
m_link = object->template make_weak_ptr<U>().take_link();
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -32,8 +32,9 @@ class WeakLink : public RefCounted<WeakLink> {
|
|||||||
friend class WeakPtr;
|
friend class WeakPtr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template<typename T, typename PtrTraits = RefPtrTraits<T>, typename EnableIf<IsBaseOf<RefCountedBase, T>>::Type* = nullptr>
|
template<typename T, typename PtrTraits = RefPtrTraits<T>>
|
||||||
RefPtr<T, PtrTraits> strong_ref() const
|
RefPtr<T, PtrTraits> strong_ref() const
|
||||||
|
requires(IsBaseOf<RefCountedBase, T>)
|
||||||
{
|
{
|
||||||
RefPtr<T, PtrTraits> ref;
|
RefPtr<T, PtrTraits> ref;
|
||||||
|
|
||||||
|
@ -361,16 +361,17 @@ public:
|
|||||||
|
|
||||||
ALWAYS_INLINE bool is_null() const { return PtrTraits::is_null(m_bits.load(AK::MemoryOrder::memory_order_relaxed)); }
|
ALWAYS_INLINE bool is_null() const { return PtrTraits::is_null(m_bits.load(AK::MemoryOrder::memory_order_relaxed)); }
|
||||||
|
|
||||||
template<typename U = T, typename EnableIf<IsSame<U, T> && !IsNullPointer<typename PtrTraits::NullType>>::Type* = nullptr>
|
template<typename U = T>
|
||||||
typename PtrTraits::NullType null_value() const
|
typename PtrTraits::NullType null_value() const
|
||||||
|
requires(IsSame<U, T> && !IsNullPointer<typename PtrTraits::NullType>)
|
||||||
{
|
{
|
||||||
// make sure we are holding a null value
|
// make sure we are holding a null value
|
||||||
FlatPtr bits = m_bits.load(AK::MemoryOrder::memory_order_relaxed);
|
FlatPtr bits = m_bits.load(AK::MemoryOrder::memory_order_relaxed);
|
||||||
VERIFY(PtrTraits::is_null(bits));
|
VERIFY(PtrTraits::is_null(bits));
|
||||||
return PtrTraits::to_null_value(bits);
|
return PtrTraits::to_null_value(bits);
|
||||||
}
|
}
|
||||||
template<typename U = T, typename EnableIf<IsSame<U, T> && !IsNullPointer<typename PtrTraits::NullType>>::Type* = nullptr>
|
template<typename U = T>
|
||||||
void set_null_value(typename PtrTraits::NullType value)
|
void set_null_value(typename PtrTraits::NullType value) requires(IsSame<U, T> && !IsNullPointer<typename PtrTraits::NullType>)
|
||||||
{
|
{
|
||||||
// make sure that new null value would be interpreted as a null value
|
// make sure that new null value would be interpreted as a null value
|
||||||
FlatPtr bits = PtrTraits::from_null_value(value);
|
FlatPtr bits = PtrTraits::from_null_value(value);
|
||||||
|
@ -18,27 +18,27 @@ class [[nodiscard]] WeakPtr {
|
|||||||
public:
|
public:
|
||||||
WeakPtr() = default;
|
WeakPtr() = default;
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr(const WeakPtr<U>& other)
|
WeakPtr(const WeakPtr<U>& other) requires(IsBaseOf<T, U>)
|
||||||
: m_link(other.m_link)
|
: m_link(other.m_link)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr(WeakPtr<U>&& other)
|
WeakPtr(WeakPtr<U>&& other) requires(IsBaseOf<T, U>)
|
||||||
: m_link(other.take_link())
|
: m_link(other.take_link())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr& operator=(WeakPtr<U>&& other)
|
WeakPtr& operator=(WeakPtr<U>&& other) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
m_link = other.take_link();
|
m_link = other.take_link();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr& operator=(const WeakPtr<U>& other)
|
WeakPtr& operator=(const WeakPtr<U>& other) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
if ((const void*)this != (const void*)&other)
|
if ((const void*)this != (const void*)&other)
|
||||||
m_link = other.m_link;
|
m_link = other.m_link;
|
||||||
@ -51,21 +51,21 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr(const U& object)
|
WeakPtr(const U& object) requires(IsBaseOf<T, U>)
|
||||||
: m_link(object.template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link())
|
: m_link(object.template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr(const U* object)
|
WeakPtr(const U* object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
if (object)
|
if (object)
|
||||||
m_link = object->template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
m_link = object->template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr(const RefPtr<U>& object)
|
WeakPtr(const RefPtr<U>& object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
object.do_while_locked([&](U* obj) {
|
object.do_while_locked([&](U* obj) {
|
||||||
if (obj)
|
if (obj)
|
||||||
@ -73,8 +73,8 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr(const NonnullRefPtr<U>& object)
|
WeakPtr(const NonnullRefPtr<U>& object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
object.do_while_locked([&](U* obj) {
|
object.do_while_locked([&](U* obj) {
|
||||||
if (obj)
|
if (obj)
|
||||||
@ -82,15 +82,15 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr& operator=(const U& object)
|
WeakPtr& operator=(const U& object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
m_link = object.template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
m_link = object.template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr& operator=(const U* object)
|
WeakPtr& operator=(const U* object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
if (object)
|
if (object)
|
||||||
m_link = object->template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
m_link = object->template try_make_weak_ptr<U>().release_value_but_fixme_should_propagate_errors().take_link();
|
||||||
@ -99,8 +99,8 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr& operator=(const RefPtr<U>& object)
|
WeakPtr& operator=(const RefPtr<U>& object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
object.do_while_locked([&](U* obj) {
|
object.do_while_locked([&](U* obj) {
|
||||||
if (obj)
|
if (obj)
|
||||||
@ -111,8 +111,8 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
|
template<typename U>
|
||||||
WeakPtr& operator=(const NonnullRefPtr<U>& object)
|
WeakPtr& operator=(const NonnullRefPtr<U>& object) requires(IsBaseOf<T, U>)
|
||||||
{
|
{
|
||||||
object.do_while_locked([&](U* obj) {
|
object.do_while_locked([&](U* obj) {
|
||||||
if (obj)
|
if (obj)
|
||||||
|
@ -11,13 +11,12 @@
|
|||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
template<size_t N, typename = typename EnableIf<N % 2 == 1>::Type>
|
template<size_t N>
|
||||||
class SpatialGaussianBlurFilter : public GenericConvolutionFilter<N> {
|
requires(N % 2 == 1) class SpatialGaussianBlurFilter : public GenericConvolutionFilter<N> {
|
||||||
public:
|
public:
|
||||||
SpatialGaussianBlurFilter() = default;
|
SpatialGaussianBlurFilter() = default;
|
||||||
virtual ~SpatialGaussianBlurFilter() = default;
|
virtual ~SpatialGaussianBlurFilter() = default;
|
||||||
|
|
||||||
virtual const char* class_name() const override { return "SpatialGaussianBlurFilter"; }
|
virtual const char* class_name() const override { return "SpatialGaussianBlurFilter"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user