From 2f8e5ff76e5bd94022ba11b2630dc28ada9408a2 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Sat, 12 Oct 2024 16:33:40 +0000 Subject: [PATCH] Use std::ranges::distance instead implementation with std::ranges::fold_left --- library/include/larra/stream_error.hpp | 7 +------ library/src/xml_stream.cpp | 12 +++--------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/library/include/larra/stream_error.hpp b/library/include/larra/stream_error.hpp index 82822db..e6d080f 100644 --- a/library/include/larra/stream_error.hpp +++ b/library/include/larra/stream_error.hpp @@ -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 response; // NOLINT std::ranges::copy(str() | std::views::drop(1), response.begin()); diff --git a/library/src/xml_stream.cpp b/library/src/xml_stream.cpp index 69afa67..897916e 100644 --- a/library/src/xml_stream.cpp +++ b/library/src/xml_stream.cpp @@ -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<>{});