From a111fb7da2c4aae9fa8f91891071231fe214d9c2 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 21 Mar 2024 10:37:54 -0400 Subject: [PATCH] cpp-common/bt2c: enable span-lite's `make_span()` function 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/12117 Reviewed-by: Philippe Proulx Tested-by: jenkins --- src/Makefile.am | 1 + src/cpp-common/bt2c/span.hpp | 22 ++++++++++++++++++++++ src/cpp-common/bt2s/span.hpp | 4 +++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/cpp-common/bt2c/span.hpp diff --git a/src/Makefile.am b/src/Makefile.am index b66b1d6b..7df63580 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 00000000..05ab3d79 --- /dev/null +++ b/src/cpp-common/bt2c/span.hpp @@ -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 +inline constexpr bt2s::span makeSpan(T * const ptr, const size_t count) noexcept +{ + return nonstd::make_span(ptr, count); +} + +} /* namespace bt2c */ + +#endif /* BABELTRACE_CPP_COMMON_BT2C_SPAN_HPP */ diff --git a/src/cpp-common/bt2s/span.hpp b/src/cpp-common/bt2s/span.hpp index 4313c9ab..94dd8011 100644 --- a/src/cpp-common/bt2s/span.hpp +++ b/src/cpp-common/bt2s/span.hpp @@ -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 { -- 2.34.1