cpp-common/bt2: use `bt2::OptionalBorrowedObject` where possible
[babeltrace.git] / src / cpp-common / bt2 / value.hpp
index 13d30a98c450bbadf1f8f60d0ec43670e27294c0..4dc4019a8677ffab3d36f35043217331eddbcc05 100644 (file)
 
 #include "common/assert.h"
 #include "common/common.h"
-#include "cpp-common/bt2s/optional.hpp"
 
 #include "borrowed-object-iterator.hpp"
 #include "borrowed-object.hpp"
 #include "exc.hpp"
 #include "internal/utils.hpp"
+#include "optional-borrowed-object.hpp"
 #include "raw-value-proxy.hpp"
 #include "shared-object.hpp"
 
@@ -241,7 +241,7 @@ public:
     }
 
     template <typename KeyT>
-    bt2s::optional<CommonValue<LibObjT>> operator[](KeyT&& key) const noexcept
+    OptionalBorrowedObject<CommonValue<LibObjT>> operator[](KeyT&& key) const noexcept
     {
         return this->asMap()[std::forward<KeyT>(key)];
     }
@@ -1285,19 +1285,12 @@ public:
         return this->length() == 0;
     }
 
-    bt2s::optional<CommonValue<LibObjT>> operator[](const char * const key) const noexcept
+    OptionalBorrowedObject<CommonValue<LibObjT>> operator[](const char * const key) const noexcept
     {
-        const auto libObjPtr =
-            internal::CommonMapValueSpec<LibObjT>::entryByKey(this->libObjPtr(), key);
-
-        if (!libObjPtr) {
-            return bt2s::nullopt;
-        }
-
-        return CommonValue<LibObjT> {libObjPtr};
+        return internal::CommonMapValueSpec<LibObjT>::entryByKey(this->libObjPtr(), key);
     }
 
-    bt2s::optional<CommonValue<LibObjT>> operator[](const std::string& key) const noexcept
+    OptionalBorrowedObject<CommonValue<LibObjT>> operator[](const std::string& key) const noexcept
     {
         return (*this)[key.data()];
     }
This page took 0.025005 seconds and 4 git commands to generate.