1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:17:36 +00: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:
Lenny Maiorani 2022-03-17 11:29:46 -06:00 committed by Brian Gianforcaro
parent 8f7219c6fa
commit 2844f7c333
9 changed files with 63 additions and 73 deletions

View file

@ -17,11 +17,11 @@ namespace AK {
// FIXME: Implement Buffered<T> for DuplexStream.
template<typename StreamType, size_t Size = 4096, typename = void>
template<typename StreamType, size_t Size = 4096>
class Buffered;
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);
public:
@ -119,7 +119,7 @@ private:
};
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);
public:
@ -192,7 +192,6 @@ private:
u8 m_buffer[Size];
size_t m_buffered { 0 };
};
}
using AK::Buffered;

View file

@ -692,8 +692,8 @@ ErrorOr<void> Formatter<FormatString>::vformat(FormatBuilder& builder, StringVie
return {};
}
template<typename T>
ErrorOr<void> Formatter<T, typename EnableIf<IsIntegral<T>>::Type>::format(FormatBuilder& builder, T value)
template<Integral T>
ErrorOr<void> Formatter<T>::format(FormatBuilder& builder, T value)
{
if (m_mode == Mode::Character) {
// FIXME: We just support ASCII for now, in the future maybe unicode?

View file

@ -307,8 +307,8 @@ struct StandardFormatter {
void parse(TypeErasedFormatParams&, FormatParser&);
};
template<typename T>
struct Formatter<T, typename EnableIf<IsIntegral<T>>::Type> : StandardFormatter {
template<Integral T>
struct Formatter<T> : StandardFormatter {
Formatter() = default;
explicit Formatter(StandardFormatter formatter)
: StandardFormatter(move(formatter))

View file

@ -10,15 +10,6 @@
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>
struct IntegralConstant {
static constexpr T value = v;
@ -591,7 +582,6 @@ using AK::Detail::Conditional;
using AK::Detail::CopyConst;
using AK::Detail::declval;
using AK::Detail::DependentFalse;
using AK::Detail::EnableIf;
using AK::Detail::FalseType;
using AK::Detail::IdentityType;
using AK::Detail::IndexSequence;

View file

@ -22,27 +22,27 @@ class [[nodiscard]] WeakPtr {
public:
WeakPtr() = default;
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr(const WeakPtr<U>& other)
template<typename U>
WeakPtr(const WeakPtr<U>& other) requires(IsBaseOf<T, U>)
: m_link(other.m_link)
{
}
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr(WeakPtr<U>&& other)
template<typename U>
WeakPtr(WeakPtr<U>&& other) requires(IsBaseOf<T, U>)
: m_link(other.take_link())
{
}
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr& operator=(WeakPtr<U>&& other)
template<typename U>
WeakPtr& operator=(WeakPtr<U>&& other) requires(IsBaseOf<T, U>)
{
m_link = other.take_link();
return *this;
}
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr& operator=(const WeakPtr<U>& other)
template<typename U>
WeakPtr& operator=(const WeakPtr<U>& other) requires(IsBaseOf<T, U>)
{
if ((const void*)this != (const void*)&other)
m_link = other.m_link;
@ -55,41 +55,41 @@ public:
return *this;
}
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr(const U& object)
template<typename U>
WeakPtr(const U& object) requires(IsBaseOf<T, U>)
: m_link(object.template make_weak_ptr<U>().take_link())
{
}
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr(const U* object)
template<typename U>
WeakPtr(const U* object) requires(IsBaseOf<T, U>)
{
if (object)
m_link = object->template make_weak_ptr<U>().take_link();
}
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr(RefPtr<U> const& object)
template<typename U>
WeakPtr(RefPtr<U> const& object) requires(IsBaseOf<T, U>)
{
if (object)
m_link = object->template make_weak_ptr<U>().take_link();
}
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr(NonnullRefPtr<U> const& object)
template<typename U>
WeakPtr(NonnullRefPtr<U> const& object) requires(IsBaseOf<T, U>)
{
m_link = object->template make_weak_ptr<U>().take_link();
}
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr& operator=(const U& object)
template<typename U>
WeakPtr& operator=(const U& object) requires(IsBaseOf<T, U>)
{
m_link = object.template make_weak_ptr<U>().take_link();
return *this;
}
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr& operator=(const U* object)
template<typename U>
WeakPtr& operator=(const U* object) requires(IsBaseOf<T, U>)
{
if (object)
m_link = object->template make_weak_ptr<U>().take_link();
@ -98,8 +98,8 @@ public:
return *this;
}
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr& operator=(const RefPtr<U>& object)
template<typename U>
WeakPtr& operator=(const RefPtr<U>& object) requires(IsBaseOf<T, U>)
{
if (object)
m_link = object->template make_weak_ptr<U>().take_link();
@ -108,8 +108,8 @@ public:
return *this;
}
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr& operator=(const NonnullRefPtr<U>& object)
template<typename U>
WeakPtr& operator=(const NonnullRefPtr<U>& object) requires(IsBaseOf<T, U>)
{
m_link = object->template make_weak_ptr<U>().take_link();
return *this;

View file

@ -32,8 +32,9 @@ class WeakLink : public RefCounted<WeakLink> {
friend class WeakPtr;
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
requires(IsBaseOf<RefCountedBase, T>)
{
RefPtr<T, PtrTraits> ref;