mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 09:34:57 +09:00
AK: Simplify constructors and conversions from nullptr_t
Problem: - Many constructors are defined as `{}` rather than using the ` = default` compiler-provided constructor. - Some types provide an implicit conversion operator from `nullptr_t` instead of requiring the caller to default construct. This violates the C++ Core Guidelines suggestion to declare single-argument constructors explicit (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit). Solution: - Change default constructors to use the compiler-provided default constructor. - Remove implicit conversion operators from `nullptr_t` and change usage to enforce type consistency without conversion.
This commit is contained in:
parent
9dc44bf8c4
commit
e6f907a155
Notes:
sideshowbarker
2024-07-18 23:54:24 +09:00
Author: https://github.com/ldm5180
Commit: e6f907a155
Pull-request: https://github.com/SerenityOS/serenity/pull/4908
Reviewed-by: https://github.com/asynts
Reviewed-by: https://github.com/emanuele6
105 changed files with 300 additions and 244 deletions
|
@ -25,9 +25,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Assertions.h"
|
||||
#include "OwnPtr.h"
|
||||
#include "StdLibExtras.h"
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Traits.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
@ -38,7 +39,6 @@ template<typename Out, typename... In>
|
|||
class Function<Out(In...)> {
|
||||
public:
|
||||
Function() = default;
|
||||
Function(std::nullptr_t) { }
|
||||
|
||||
template<typename CallableType, class = typename EnableIf<!(IsPointer<CallableType>::value && IsFunction<typename RemovePointer<CallableType>::Type>::value) && IsRvalueReference<CallableType&&>::value>::Type>
|
||||
Function(CallableType&& callable)
|
||||
|
@ -83,7 +83,7 @@ public:
|
|||
private:
|
||||
class CallableWrapperBase {
|
||||
public:
|
||||
virtual ~CallableWrapperBase() { }
|
||||
virtual ~CallableWrapperBase() = default;
|
||||
virtual Out call(In...) const = 0;
|
||||
};
|
||||
|
||||
|
@ -98,7 +98,18 @@ private:
|
|||
CallableWrapper(const CallableWrapper&) = delete;
|
||||
CallableWrapper& operator=(const CallableWrapper&) = delete;
|
||||
|
||||
Out call(In... in) const final override { return m_callable(forward<In>(in)...); }
|
||||
Out call(In... in) const final override
|
||||
{
|
||||
if constexpr (requires { m_callable(forward<In>(in)...); }) {
|
||||
return m_callable(forward<In>(in)...);
|
||||
} else if constexpr (requires { m_callable(); }) {
|
||||
return m_callable();
|
||||
} else if constexpr (IsSame<void, Out>::value) {
|
||||
return;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
CallableType m_callable;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue