BLI: support initializing empty FunctionRef with nullptr

This may sometimes be desired because it is more explicitely
shows that the `FunctionRef` will be empty.
This commit is contained in:
Jacques Lucke 2021-09-22 19:55:44 +02:00
parent 02bde2c1d5
commit f893dea586
2 changed files with 10 additions and 0 deletions

View File

@ -110,6 +110,10 @@ template<typename Ret, typename... Params> class FunctionRef<Ret(Params...)> {
public:
FunctionRef() = default;
FunctionRef(std::nullptr_t)
{
}
/**
* A `FunctionRef` itself is a callable as well. However, we don't want that this
* constructor is called when `Callable` is a `FunctionRef`. If we would allow this, it

View File

@ -124,4 +124,10 @@ TEST(function_ref, CallSafeVoid)
EXPECT_EQ(value, 1);
}
TEST(function_ref, InitializeWithNull)
{
FunctionRef<int(int, int)> f{nullptr};
EXPECT_FALSE(f);
}
} // namespace blender::tests