Skip to content

Commit

Permalink
⚗️ (stl): Test std::ranges support for arm-gcc + clang
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Oct 26, 2022
1 parent 60cbe65 commit 0317f41
Show file tree
Hide file tree
Showing 4 changed files with 57 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
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

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

#include "drivers/BufferedSerial.h"
Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions tests/functional/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
std_features_std_ranges

INCLUDE_DIRECTORIES

SOURCES
suite_std_ranges.cpp

LINK_LIBRARIES
)
24 changes: 24 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,24 @@
// 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 = [] {
auto data = std::to_array({1, 2, 3, 4, 5});
auto i = 0;

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

0 comments on commit 0317f41

Please sign in to comment.