From 45f637cc09c94b0eb5cf1ebc739b5d3eb77aef33 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 15 Nov 2023 00:37:27 -0500 Subject: [PATCH] cpp-common: add `bt2s::string_view`, alias of `bpstd::string_view` In order to avoid having all sorts of external namespaces, make `bt2s::string_view` an alias of `nonstd::string_view`, and make sure everything in the project uses `bt2s::string_view`. Also add aliases for other STL types of ``, like the `bt2s::basic_string_view` class template. This will make it possible to easily change the implementation without changing the code using it indirectly (only `cpp-common/bt2s/string-view.hpp` will change). Move `cpp-common/string_view.hpp` to `cpp-common/vendor/string_view-standalone/string_view.hpp` to make it clear it's an external project. Signed-off-by: Philippe Proulx Change-Id: I5172f642f5490b4a7eb21ed7cca55039452dc9b8 Reviewed-on: https://review.lttng.org/c/babeltrace/+/11392 Reviewed-by: Simon Marchi CI-Build: Simon Marchi Tested-by: jenkins --- src/Makefile.am | 5 ++-- src/cpp-common/bt2s/string-view.hpp | 24 +++++++++++++++++++ .../string_view-standalone}/string_view.hpp | 0 tools/format-cpp.sh | 1 - 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 src/cpp-common/bt2s/string-view.hpp rename src/cpp-common/{ => vendor/string_view-standalone}/string_view.hpp (100%) diff --git a/src/Makefile.am b/src/Makefile.am index 23acb9e1..cf315687 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -55,9 +55,10 @@ noinst_HEADERS = \ cpp-common/bt2c/vector.hpp \ cpp-common/bt2s/make-unique.hpp \ cpp-common/bt2s/optional.hpp \ + cpp-common/bt2s/string-view.hpp \ cpp-common/nlohmann/json.hpp \ - cpp-common/string_view.hpp \ - cpp-common/vendor/optional-lite/optional.hpp + cpp-common/vendor/optional-lite/optional.hpp \ + cpp-common/vendor/string_view-standalone/string_view.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/bt2s/string-view.hpp b/src/cpp-common/bt2s/string-view.hpp new file mode 100644 index 00000000..8cdafd84 --- /dev/null +++ b/src/cpp-common/bt2s/string-view.hpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Philippe Proulx + * + * SPDX-License-Identifier: MIT + */ + +#ifndef BABELTRACE_CPP_COMMON_BT2S_STRING_VIEW_HPP +#define BABELTRACE_CPP_COMMON_BT2S_STRING_VIEW_HPP + +#include "cpp-common/vendor/string_view-standalone/string_view.hpp" + +namespace bt2s { + +template > +using basic_string_view = bpstd::basic_string_view; + +using string_view = bpstd::string_view; +using wstring_view = bpstd::wstring_view; +using u16string_view = bpstd::u16string_view; +using u32string_view = bpstd::u32string_view; + +} /* namespace bt2s */ + +#endif /* BABELTRACE_CPP_COMMON_BT2S_STRING_VIEW_HPP */ diff --git a/src/cpp-common/string_view.hpp b/src/cpp-common/vendor/string_view-standalone/string_view.hpp similarity index 100% rename from src/cpp-common/string_view.hpp rename to src/cpp-common/vendor/string_view-standalone/string_view.hpp diff --git a/tools/format-cpp.sh b/tools/format-cpp.sh index 04444ddc..754b04d2 100755 --- a/tools/format-cpp.sh +++ b/tools/format-cpp.sh @@ -45,7 +45,6 @@ format_cpp() { # files in specific subdirectories. find "$(realpath "$root_dir")" \( -name '*.cpp' -o -name '*.hpp' \) \ ! -path '*/src/cpp-common/vendor/*' \ - ! -path '*/src/cpp-common/string_view.hpp' \ ! -path '*/src/cpp-common/nlohmann/json.hpp' \ ! -path '*/src/plugins/ctf/common/metadata/parser.*' \ ! -path '*/src/plugins/ctf/common/metadata/lexer.*' \ -- 2.34.1