[Bf-blender-cvs] [6384a61a991] functions: Add arrow and star operator to BLI::Optional

Jacques Lucke noreply at git.blender.org
Mon Sep 16 16:01:01 CEST 2019


Commit: 6384a61a991aa7aeaa5e2bc46995c0b78732397b
Author: Jacques Lucke
Date:   Mon Sep 16 11:04:05 2019 +0200
Branches: functions
https://developer.blender.org/rB6384a61a991aa7aeaa5e2bc46995c0b78732397b

Add arrow and star operator to BLI::Optional

===================================================================

M	source/blender/blenlib/BLI_optional.h
M	tests/gtests/blenlib/BLI_optional_test.cc

===================================================================

diff --git a/source/blender/blenlib/BLI_optional.h b/source/blender/blenlib/BLI_optional.h
index dd08db39c29..47ea9d2803f 100644
--- a/source/blender/blenlib/BLI_optional.h
+++ b/source/blender/blenlib/BLI_optional.h
@@ -161,6 +161,16 @@ template<typename T> class Optional {
     return value;
   }
 
+  T *operator->()
+  {
+    return this->value_ptr();
+  }
+
+  T &operator*()
+  {
+    return *this->value_ptr();
+  }
+
  private:
   T *value_ptr() const
   {
diff --git a/tests/gtests/blenlib/BLI_optional_test.cc b/tests/gtests/blenlib/BLI_optional_test.cc
index 499fd5d0604..2e672967680 100644
--- a/tests/gtests/blenlib/BLI_optional_test.cc
+++ b/tests/gtests/blenlib/BLI_optional_test.cc
@@ -57,3 +57,18 @@ TEST(optional, Extract)
   EXPECT_EQ(a.extract(), 32);
   EXPECT_FALSE(a.has_value());
 }
+
+TEST(optional, ArrowOperator)
+{
+  Optional<std::string> value = std::string("Hello");
+  EXPECT_TRUE(value.has_value());
+  EXPECT_EQ(value->size(), 5);
+}
+
+TEST(optional, StarOperator)
+{
+  Optional<std::string> value = std::string("Hello");
+  EXPECT_TRUE(value.has_value());
+  std::string &s = *value;
+  EXPECT_EQ(s.size(), 5);
+}



More information about the Bf-blender-cvs mailing list