[Bf-blender-cvs] [f893dea5863] master: BLI: support initializing empty FunctionRef with nullptr
Jacques Lucke
noreply at git.blender.org
Wed Sep 22 19:55:53 CEST 2021
Commit: f893dea5863934e5c09cff673ff6cccd4106e069
Author: Jacques Lucke
Date: Wed Sep 22 19:55:44 2021 +0200
Branches: master
https://developer.blender.org/rBf893dea5863934e5c09cff673ff6cccd4106e069
BLI: support initializing empty FunctionRef with nullptr
This may sometimes be desired because it is more explicitely
shows that the `FunctionRef` will be empty.
===================================================================
M source/blender/blenlib/BLI_function_ref.hh
M source/blender/blenlib/tests/BLI_function_ref_test.cc
===================================================================
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
More information about the Bf-blender-cvs
mailing list