Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚗️ (stl): Test std::ranges support for arm-gcc + clang
Browse files Browse the repository at this point in the history
ladislas committed Oct 31, 2022

Verified

This commit was signed with the committer’s verified signature.
ladislas Ladislas de Toldi
1 parent 25050e2 commit 88c6d13
Showing 4 changed files with 68 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spikes/stl_cxxsupport/main.cpp
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

#include <array>
#include <ranges>
#include <span>

#include "drivers/BufferedSerial.h"
@@ -94,5 +95,20 @@ auto main() -> int
auto back = span0.back();
log_info("span0.back() = %i", back);

log_info("Test std::range features");

constexpr auto range = [](const auto a, const auto b) {
auto x = std::ranges::views::iota(a) | std::ranges::views::take(b - a + 1);
return std::ranges::views::all(x);
};

for (auto x: range(1, 10)) {
log_info("x: %i", x);
}

for (auto y: range(20, 25)) {
log_info("y: %i", y);
}

return 1;
}
2 changes: 2 additions & 0 deletions tests/functional/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -42,3 +42,5 @@ add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/boost_ut)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/io_expander)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/file_manager)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/qdac)

add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/stl_features)
15 changes: 15 additions & 0 deletions tests/functional/tests/stl_features/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Leka - LekaOS
# Copyright 2022 APF France handicap
# SPDX-License-Identifier: Apache-2.0

register_functional_test(
TARGET
functional_ut_std_features

INCLUDE_DIRECTORIES

SOURCES
suite_std_ranges.cpp

LINK_LIBRARIES
)
35 changes: 35 additions & 0 deletions tests/functional/tests/stl_features/suite_std_ranges.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include <ranges>

#include "tests/config.h"

using namespace boost::ut;

constexpr auto range = [](auto a, auto b) {
auto x = std::ranges::views::iota(a) | std::ranges::views::take(b - a + 1);
return std::ranges::views::all(x);
};

suite suite_std_ranges = [] {
"generate range of 5 values from 1 to 5"_test = [] {
auto data = std::to_array({1, 2, 3, 4, 5});
auto i = 0;
for (auto v: range(1, 5)) {
expect(data[i] == v);
++i;
}
};

"store range in variable and compare"_test = [&] {
auto data = range(10, 20);
auto i = 0;

for (auto v: range(10, 20)) {
expect(data[i] == v);
++i;
}
};
};

0 comments on commit 88c6d13

Please sign in to comment.