summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorLenny Maiorani <lenny@serenityos.org>2022-03-17 11:29:46 -0600
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-03-17 22:15:42 -0700
commit2844f7c3332f84f147763413406c6f70d99ea14f (patch)
tree7828ecd3936b3305dbe3719479d2a937a2847ea3 /AK
parent8f7219c6fafb4941d4cd1f094fb43e32e101299f (diff)
downloadserenity-2844f7c3332f84f147763413406c6f70d99ea14f.zip
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.
Diffstat (limited to 'AK')
-rw-r--r--AK/Buffered.h7
-rw-r--r--AK/Format.cpp4
-rw-r--r--AK/Format.h4
-rw-r--r--AK/StdLibExtraDetails.h10
-rw-r--r--AK/WeakPtr.h48
-rw-r--r--AK/Weakable.h3
6 files changed, 33 insertions, 43 deletions
diff --git a/AK/Buffered.h b/AK/Buffered.h
index ab4c7e2752..5eec15d544 100644
--- a/AK/Buffered.h
+++ b/AK/Buffered.h
@@ -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;
diff --git a/AK/Format.cpp b/AK/Format.cpp
index 63e9ff8689..ecd0948d31 100644
--- a/AK/Format.cpp
+++ b/AK/Format.cpp
@@ -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?
diff --git a/AK/Format.h b/AK/Format.h
index 2034980594..83971c1474 100644
--- a/AK/Format.h
+++ b/AK/Format.h
@@ -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))
diff --git a/AK/StdLibExtraDetails.h b/AK/StdLibExtraDetails.h
index 1b91e33751..3357363ea2 100644
--- a/AK/StdLibExtraDetails.h
+++ b/AK/StdLibExtraDetails.h
@@ -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;
diff --git a/AK/WeakPtr.h b/AK/WeakPtr.h
index cfd3da2d49..a7e3346abe 100644
--- a/AK/WeakPtr.h
+++ b/AK/WeakPtr.h
@@ -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;
diff --git a/AK/Weakable.h b/AK/Weakable.h
index 0aad3cb436..122fb6ddfa 100644
--- a/AK/Weakable.h
+++ b/AK/Weakable.h
@@ -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;