mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-12-16 04:09:39 +00:00
Common/Functional: Add InvokerOf template which can convert function pointers to functor types.
This commit is contained in:
parent
1b63776f2d
commit
605cc579a4
@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
@ -51,4 +52,17 @@ private:
|
||||
std::unique_ptr<FuncBase> m_ptr;
|
||||
};
|
||||
|
||||
// A functor type with an invocable non-type template parameter.
|
||||
// e.g. Providing a function pointer will create a functor type that invokes said function.
|
||||
// It allows using function pointers in contexts that expect a type, e.g. as a "deleter".
|
||||
template <auto Invocable>
|
||||
struct InvokerOf
|
||||
{
|
||||
template <typename... Args>
|
||||
constexpr auto operator()(Args... args) const
|
||||
{
|
||||
return std::invoke(Invocable, std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Common
|
||||
|
||||
Loading…
Reference in New Issue
Block a user