From a0ae532f4ebf0a5d31f8378fd0584d420e9eca7e Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 16 Jan 2024 13:58:25 -0500 Subject: [PATCH] cpp-common/bt2c: make CStringView convertible from std::string This will make it possible to have functions that accept CStringViews: void foo(CStringView); and pass in std::strings seamlessly: foo(myStdStr); Change-Id: I76dc55438c2cd87f77ddec421dff7f119e53eff5 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/11688 Reviewed-by: Philippe Proulx --- src/cpp-common/bt2c/c-string-view.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cpp-common/bt2c/c-string-view.hpp b/src/cpp-common/bt2c/c-string-view.hpp index c1c8bf38..fb1b3a65 100644 --- a/src/cpp-common/bt2c/c-string-view.hpp +++ b/src/cpp-common/bt2c/c-string-view.hpp @@ -42,6 +42,15 @@ public: { } + /* + * Builds a view of the string `str`. + * + * Intentionally not explicit. + */ + CStringView(const std::string& str) noexcept : _mStr {str.c_str()} + { + } + /* * Makes this view view the C string `str` (may be `nullptr`). * -- 2.34.1