cpp-common/bt2c: enable span-lite's `make_span()` function
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 21 Mar 2024 14:37:54 +0000 (10:37 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Mar 2024 18:56:36 +0000 (14:56 -0400)
Enable span-lite's `make_span()` function, which exists to compensate
for the lack of class template argument deduction in C++ pre 17.  This
allows creating spans without being too verbose.  This is not a standard
function, but the day we switch to C++ 17 and want to use `std::span`,
we can just replace all uses of `make_span()` with calls to
`std::span`'s constructor.

Make one version of `nonstd::make_span` (expected to be used in an
upcoming patch) available as `bt2c::makeSpan()`.

Change-Id: Ie28c1884d2c03c38a4b839096afae887fa54cc04
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12117
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/Makefile.am
src/cpp-common/bt2c/span.hpp [new file with mode: 0644]
src/cpp-common/bt2s/span.hpp

index b66b1d6b1585aa3a105693535a3a8e0abad75099..7df63580b931cdda8d661378e2f4ed40a1f4ee6a 100644 (file)
@@ -164,6 +164,7 @@ cpp_common_libcpp_common_la_SOURCES = \
        cpp-common/bt2c/prio-heap.hpp \
        cpp-common/bt2c/read-fixed-len-int.hpp \
        cpp-common/bt2c/safe-ops.hpp \
+       cpp-common/bt2c/span.hpp \
        cpp-common/bt2c/std-int.hpp \
        cpp-common/bt2c/type-traits.hpp \
        cpp-common/bt2c/uuid.hpp \
diff --git a/src/cpp-common/bt2c/span.hpp b/src/cpp-common/bt2c/span.hpp
new file mode 100644 (file)
index 0000000..05ab3d7
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2024 EfficiOS Inc.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_SPAN_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_SPAN_HPP
+
+#include "cpp-common/bt2s/span.hpp"
+
+namespace bt2c {
+
+template <class T>
+inline constexpr bt2s::span<T> makeSpan(T * const ptr, const size_t count) noexcept
+{
+    return nonstd::make_span(ptr, count);
+}
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_SPAN_HPP */
index 4313c9ab9ff291ef78fd5a47268df28677ffdb7f..94dd8011b9358894ae83235215f798afe98f1740 100644 (file)
@@ -7,7 +7,9 @@
 #ifndef BABELTRACE_CPP_COMMON_BT2S_SPAN_HPP
 #define BABELTRACE_CPP_COMMON_BT2S_SPAN_HPP
 
-#include "cpp-common/vendor/span-lite/span.hpp"
+#define span_FEATURE_MAKE_SPAN 1
+
+#include "cpp-common/vendor/span-lite/span.hpp" /* IWYU pragma: export */
 
 namespace bt2s {
 
This page took 0.027588 seconds and 4 git commands to generate.