diff options
author | Jacques Lucke <jacques@blender.org> | 2021-09-22 20:55:44 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-09-22 20:55:44 +0300 |
commit | f893dea5863934e5c09cff673ff6cccd4106e069 (patch) | |
tree | bed24e3bf6124713c528052c1898087d13d4f2d8 /source/blender/blenlib | |
parent | 02bde2c1d5bbf1ea44209a618eb1947ea1d6cd25 (diff) |
BLI: support initializing empty FunctionRef with nullptr
This may sometimes be desired because it is more explicitely
shows that the `FunctionRef` will be empty.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_function_ref.hh | 4 | ||||
-rw-r--r-- | source/blender/blenlib/tests/BLI_function_ref_test.cc | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_function_ref.hh b/source/blender/blenlib/BLI_function_ref.hh index 70a064adc5d..71be7d7f029 100644 --- a/source/blender/blenlib/BLI_function_ref.hh +++ b/source/blender/blenlib/BLI_function_ref.hh @@ -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 diff --git a/source/blender/blenlib/tests/BLI_function_ref_test.cc b/source/blender/blenlib/tests/BLI_function_ref_test.cc index 74f5014142c..20c9ee5885e 100644 --- a/source/blender/blenlib/tests/BLI_function_ref_test.cc +++ b/source/blender/blenlib/tests/BLI_function_ref_test.cc @@ -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 |