Skip to content

Commit 84cbc14

Browse files
committed
🎨 Improve span for flow construction
Problem: - The span constructor used for constructing a flow impl triggers the warning `-Wunsafe-buffer-usage-in-container`. Solution: - We know the exact size, so the span's extent can be typed. This also means that a runtime check is unnecessary.
1 parent ac1d8ec commit 84cbc14

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

include/flow/graph_builder.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ struct graph_builder {
186186
if (not g.empty()) {
187187
return {};
188188
}
189-
return std::optional<Output>{
190-
std::in_place,
191-
std::span{std::cbegin(ordered_list), std::size(ordered_list)}};
189+
using span_t =
190+
std::span<typename Graph::key_type const, Graph::capacity()>;
191+
return std::optional<Output>{std::in_place, span_t{ordered_list}};
192192
}
193193

194194
constexpr static void check_for_missing_nodes(auto nodes,

include/flow/impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ template <stdx::ct_string Name, std::size_t NumSteps> class impl {
6060
*
6161
* @see flow::builder
6262
*/
63-
constexpr explicit(true) impl(std::span<node_t const> newMilestones) {
64-
CIB_ASSERT(NumSteps >= std::size(newMilestones));
63+
constexpr explicit(true)
64+
impl(std::span<node_t const, NumSteps> newMilestones) {
6565
if constexpr (loggingEnabled) {
6666
for (auto const &milestone : newMilestones) {
6767
functionPtrs.push_back(milestone.log_name);

include/seq/impl.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include <log/log.hpp>
43
#include <seq/step.hpp>
54

65
#include <stdx/ct_string.hpp>
@@ -24,8 +23,7 @@ template <stdx::ct_string, std::size_t NumSteps> struct impl {
2423

2524
using node_t = rt_step;
2625

27-
constexpr explicit(true) impl(std::span<node_t const> steps) {
28-
CIB_ASSERT(NumSteps >= std::size(steps));
26+
constexpr explicit(true) impl(std::span<node_t const, NumSteps> steps) {
2927
for (auto const &step : steps) {
3028
_forward_steps.push_back(step.forward_ptr);
3129
_backward_steps.push_back(step.backward_ptr);

0 commit comments

Comments
 (0)