cpp-common/bt2c: make CStringView convertible from std::string
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 16 Jan 2024 18:58:25 +0000 (13:58 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 29 Jan 2024 16:38:19 +0000 (11:38 -0500)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11688
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/cpp-common/bt2c/c-string-view.hpp

index c1c8bf389c8bd50233bc56ae54bd602a5aceda5c..fb1b3a658aeb87fab893da56d52c380780f7d25f 100644 (file)
@@ -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`).
      *
This page took 0.024389 seconds and 4 git commands to generate.