Solved: 45 - Span

This commit is contained in:
2026-08-22 11:55:54 +03:00
parent 758b9fdaa8
commit 519e90e66f
+9 -7
View File
@@ -1,21 +1,23 @@
#include "span.hpp"
#include <algorithm>
#include <ranges>
namespace cpp20 {
auto span_sum(std::span<const int> data) -> int {
(void)data;
return 0;
return std::ranges::fold_left(data, 0, std::plus<>{});
}
auto first_and_last(std::span<const int> data) -> std::pair<int, int> {
(void)data;
return {0, 0};
return {*data.begin(), *(--data.end())};
}
auto make_subspan(std::span<const int> data, std::size_t offset, std::size_t count)
auto make_subspan(std::span<const int> data, const std::size_t offset, std::size_t count)
-> std::vector<int> {
(void)data; (void)offset; (void)count;
return {};
return std::views::drop(data, offset)
| std::views::take(count)
| std::ranges::to<std::vector<int>>();
}
} // namespace cpp20