From: Simon Marchi Date: Mon, 11 Dec 2023 21:07:18 +0000 (-0500) Subject: cpp-common: add `bt2s::optional`, alias of `nonstd::optional` X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=c022776a5704be758b90a56563d491861d29fa49 cpp-common: add `bt2s::optional`, alias of `nonstd::optional` In order to avoid having all sorts of external namespaces, make `bt2s::optional` an alias of `nonstd::optional`, and make sure everything in the project uses `bt2s::optional`. Also add aliases for other STL types and functions of ``. This will make it possible to easily change the implementation without changing the code using it indirectly (only `cpp-common/bt2s/optional.hpp` will change). Move `cpp-common/optional.hpp` to `cpp-common/vendor/optional-lite/optional.hpp` to make it clear it's an external project. Making everything under `cpp-common/vendor` an exception in `tools/format-cpp.sh`. Signed-off-by: Philippe Proulx Change-Id: I2a1ea52c484c85fbf8d68631d40369efd969818a Reviewed-on: https://review.lttng.org/c/babeltrace/+/11391 Tested-by: jenkins Reviewed-by: Simon Marchi CI-Build: Simon Marchi --- diff --git a/src/Makefile.am b/src/Makefile.am index 9f4796e4..23acb9e1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -54,9 +54,10 @@ noinst_HEADERS = \ cpp-common/bt2c/uuid.hpp \ cpp-common/bt2c/vector.hpp \ cpp-common/bt2s/make-unique.hpp \ + cpp-common/bt2s/optional.hpp \ cpp-common/nlohmann/json.hpp \ - cpp-common/optional.hpp \ - cpp-common/string_view.hpp + cpp-common/string_view.hpp \ + cpp-common/vendor/optional-lite/optional.hpp ## This target generates an include file that contains the git version ## string of the current branch, it must be continuously updated when diff --git a/src/cpp-common/bt2/clock-class.hpp b/src/cpp-common/bt2/clock-class.hpp index 64e093f4..6d99ed1f 100644 --- a/src/cpp-common/bt2/clock-class.hpp +++ b/src/cpp-common/bt2/clock-class.hpp @@ -14,7 +14,7 @@ #include #include "cpp-common/bt2c/uuid-view.hpp" -#include "cpp-common/optional.hpp" +#include "cpp-common/bt2s/optional.hpp" #include "borrowed-object.hpp" #include "exc.hpp" @@ -219,7 +219,7 @@ public: bt_clock_class_set_uuid(this->libObjPtr(), uuid); } - nonstd::optional uuid() const noexcept + bt2s::optional uuid() const noexcept { const auto uuid = bt_clock_class_get_uuid(this->libObjPtr()); @@ -227,7 +227,7 @@ public: return bt2c::UuidView {uuid}; } - return nonstd::nullopt; + return bt2s::nullopt; } template diff --git a/src/cpp-common/bt2/field-class.hpp b/src/cpp-common/bt2/field-class.hpp index f299690e..94cdb8e6 100644 --- a/src/cpp-common/bt2/field-class.hpp +++ b/src/cpp-common/bt2/field-class.hpp @@ -13,7 +13,7 @@ #include #include "common/assert.h" -#include "cpp-common/optional.hpp" +#include "cpp-common/bt2s/optional.hpp" #include "borrowed-object-iterator.hpp" #include "borrowed-object.hpp" @@ -850,7 +850,7 @@ public: this->libObjPtr(), index)}; } - nonstd::optional operator[](const char * const label) const noexcept + bt2s::optional operator[](const char * const label) const noexcept { const auto libObjPtr = internal::CommonEnumerationFieldClassSpec::mappingByLabel( this->libObjPtr(), label); @@ -859,10 +859,10 @@ public: return Mapping {libObjPtr}; } - return nonstd::nullopt; + return bt2s::nullopt; } - nonstd::optional operator[](const std::string& label) const noexcept + bt2s::optional operator[](const std::string& label) const noexcept { return (*this)[label.data()]; } @@ -1188,7 +1188,7 @@ public: this->libObjPtr(), index)}; } - nonstd::optional operator[](const char * const name) const noexcept + bt2s::optional operator[](const char * const name) const noexcept { const auto libObjPtr = internal::CommonStructureFieldClassSpec::memberByName(this->libObjPtr(), name); @@ -1197,10 +1197,10 @@ public: return Member {libObjPtr}; } - return nonstd::nullopt; + return bt2s::nullopt; } - nonstd::optional operator[](const std::string& name) const noexcept + bt2s::optional operator[](const std::string& name) const noexcept { return (*this)[name.data()]; } @@ -2186,7 +2186,7 @@ public: this->libObjPtr(), index)}; } - nonstd::optional