diff options
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Common/Functional.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Source/Core/Common/Functional.h b/Source/Core/Common/Functional.h index 49d81d5a24..cdb44ebb0c 100644 --- a/Source/Core/Common/Functional.h +++ b/Source/Core/Common/Functional.h @@ -3,7 +3,9 @@ #pragma once +#include <concepts> #include <memory> +#include <type_traits> // TODO C++23: Replace with std::move_only_function. @@ -21,13 +23,14 @@ public: MoveOnlyFunction() = default; - template <typename F> + template <std::invocable<Args...> F> + requires(!std::same_as<std::decay_t<F>, MoveOnlyFunction>) MoveOnlyFunction(F&& f) : m_ptr{std::make_unique<Func<F>>(std::forward<F>(f))} { } result_type operator()(Args... args) const { return m_ptr->Invoke(std::forward<Args>(args)...); } - explicit operator bool() const { return m_ptr != nullptr; }; + explicit operator bool() const { return m_ptr != nullptr; } void swap(MoveOnlyFunction& other) { m_ptr.swap(other.m_ptr); } private: @@ -40,9 +43,9 @@ private: template <typename F> struct Func : FuncBase { - Func(F&& f) : func{std::forward<F>(f)} {} + explicit Func(F&& f) : func{std::forward<F>(f)} {} result_type Invoke(Args... args) override { return func(std::forward<Args>(args)...); } - F func; + std::decay_t<F> func; }; std::unique_ptr<FuncBase> m_ptr; |
