Common: Make a void-returning MoveOnlyFunction able to accept a non-void-returning function object and just drop the return value. std::function behaves this way.

This commit is contained in:
Jordan Woyak 2025-11-23 18:47:49 -06:00
parent 44c7440702
commit cf3d5509b1

View File

@ -45,7 +45,13 @@ private:
struct Func : FuncBase
{
explicit Func(F&& f) : func{std::forward<F>(f)} {}
result_type Invoke(Args... args) override { return func(std::forward<Args>(args)...); }
result_type Invoke(Args... args) override
{
if constexpr (std::is_void_v<result_type>)
func(std::forward<Args>(args)...);
else
return func(std::forward<Args>(args)...);
}
std::decay_t<F> func;
};