From 0317f412556e206d2157886e43e1bd4fe6bf8a6e Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Wed, 26 Oct 2022 19:32:34 +0200 Subject: [PATCH] :alembic: (stl): Test std::ranges support for arm-gcc + clang --- spikes/stl_cxxsupport/main.cpp | 16 +++++++++++++ tests/functional/CMakeLists.txt | 2 ++ .../tests/stl_features/CMakeLists.txt | 15 ++++++++++++ .../tests/stl_features/suite_std_ranges.cpp | 24 +++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 tests/functional/tests/stl_features/CMakeLists.txt create mode 100644 tests/functional/tests/stl_features/suite_std_ranges.cpp diff --git a/spikes/stl_cxxsupport/main.cpp b/spikes/stl_cxxsupport/main.cpp index eff0ebd85a..5ed491640f 100644 --- a/spikes/stl_cxxsupport/main.cpp +++ b/spikes/stl_cxxsupport/main.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include #include #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(3, 10)) { + printf("x: %i\n", x); + } + + for (auto y: range(12, 15)) { + printf("y: %i\n", y); + } + return 1; } diff --git a/tests/functional/CMakeLists.txt b/tests/functional/CMakeLists.txt index 1fc5291047..1b78e90163 100644 --- a/tests/functional/CMakeLists.txt +++ b/tests/functional/CMakeLists.txt @@ -41,3 +41,5 @@ add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/boost_ut) add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/io_expander) add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/qdac) + +add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/stl_features) diff --git a/tests/functional/tests/stl_features/CMakeLists.txt b/tests/functional/tests/stl_features/CMakeLists.txt new file mode 100644 index 0000000000..9f790bb7f6 --- /dev/null +++ b/tests/functional/tests/stl_features/CMakeLists.txt @@ -0,0 +1,15 @@ +# Leka - LekaOS +# Copyright 2022 APF France handicap +# SPDX-License-Identifier: Apache-2.0 + +register_functional_test( + TARGET + std_features_std_ranges + + INCLUDE_DIRECTORIES + + SOURCES + suite_std_ranges.cpp + + LINK_LIBRARIES +) diff --git a/tests/functional/tests/stl_features/suite_std_ranges.cpp b/tests/functional/tests/stl_features/suite_std_ranges.cpp new file mode 100644 index 0000000000..bee6fb32ab --- /dev/null +++ b/tests/functional/tests/stl_features/suite_std_ranges.cpp @@ -0,0 +1,24 @@ +// Leka - LekaOS +// Copyright 2022 APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +#include + +#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 = [] { + auto data = std::to_array({1, 2, 3, 4, 5}); + auto i = 0; + + for (auto v: range(1, 5)) { + expect(data[i] == v); + ++i; + } +};