From f893dea5863934e5c09cff673ff6cccd4106e069 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 22 Sep 2021 19:55:44 +0200 Subject: BLI: support initializing empty FunctionRef with nullptr This may sometimes be desired because it is more explicitely shows that the `FunctionRef` will be empty. --- source/blender/blenlib/BLI_function_ref.hh | 4 ++++ source/blender/blenlib/tests/BLI_function_ref_test.cc | 6 ++++++ 2 files changed, 10 insertions(+) (limited to 'source/blender/blenlib') 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 class FunctionRef { 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 f{nullptr}; + EXPECT_FALSE(f); +} + } // namespace blender::tests -- cgit v1.2.3