Use std::ranges::distance instead implementation with std::ranges::fold_left

This commit is contained in:
sha512sum 2024-10-12 16:33:40 +00:00
parent bb605dc9a8
commit 2f8e5ff76e
2 changed files with 4 additions and 15 deletions

View file

@ -30,12 +30,7 @@ constexpr auto ToKebabCaseName() -> std::string_view {
return ch != '\0';
});
};
constexpr auto size = std::ranges::fold_left(str(),
std::size_t{},
[](auto accum, auto) {
return accum + 1;
}) -
1;
constexpr auto size = std::ranges::distance(str()) - 1;
static constexpr auto arr = [&] {
std::array<char, size> response; // NOLINT
std::ranges::copy(str() | std::views::drop(1), response.begin());

View file

@ -105,22 +105,16 @@ inline auto GetLines(const boost::asio::streambuf& buf) {
}
auto CountLines(const boost::asio::streambuf& buf) -> std::size_t {
return std::ranges::fold_left(GetLines(buf), 0, [](auto accum, auto&&) {
return accum + 1;
});
return std::ranges::distance(GetLines(buf));
};
auto CountLines(std::string_view buf) -> std::size_t {
return std::ranges::fold_left(buf | std::views::split('\n'), 0, [](auto accum, auto&&) {
return accum + 1;
});
return std::ranges::distance(buf | std::views::split('\n'));
}
auto GetIndex(const boost::asio::streambuf& buf, const xmlError* error, std::size_t alreadyCountedLines) -> std::size_t {
return std::ranges::fold_left(
GetLines(buf) | std::views::take(error->line - alreadyCountedLines) | std::views::transform([](auto&& line) -> std::size_t {
return std::ranges::fold_left(line, std::size_t{1}, [](auto accum, auto&&) {
return accum + 1;
});
return std::ranges::distance(line) + 1;
}),
error->int2 - 1, // columns
std::plus<>{});