From 43ce4215d23509f171abb8a02f22dfbc49a75039 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sat, 13 Jul 2024 04:24:37 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20use=20std=20ranges=20in=20chwd?= =?UTF-8?q?=5Fprofiles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chwd_profiles.cpp | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/chwd_profiles.cpp b/src/chwd_profiles.cpp index 4f92edc..dc8bbe9 100644 --- a/src/chwd_profiles.cpp +++ b/src/chwd_profiles.cpp @@ -5,7 +5,8 @@ #include "gucc/io_utils.hpp" #include "gucc/string_utils.hpp" -#include // for any_of, sort, for_each +#include // for contains, sort, for_each +#include // for ranges::* #include #include @@ -13,25 +14,6 @@ #define TOML_EXCEPTIONS 0 // disable exceptions #include -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wold-style-cast" -#elif defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wuseless-cast" -#pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - -#include -#include -#include - -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - namespace detail::chwd { auto get_all_profile_names(std::string_view profile_type) noexcept -> std::optional> { @@ -68,9 +50,10 @@ auto get_available_profile_names(std::string_view profile_type) noexcept -> std: const auto& available_profile_names = gucc::utils::make_multiline(gucc::utils::exec("chwd --list -d | grep Name | awk '{print $4}'")); std::vector filtered_profile_names{}; - const auto& functor = [available_profile_names](auto&& profile_name) { return ranges::any_of(available_profile_names, [profile_name](auto&& available_profile) { return available_profile == profile_name; }); }; + const auto& functor = [available_profile_names](auto&& profile_name) { return std::ranges::contains(available_profile_names, profile_name); }; - ranges::for_each(all_profile_names.value() | ranges::views::filter(functor), [&](auto&& rng) { filtered_profile_names.push_back(std::forward(rng)); }); + const auto& for_each_functor = [&](auto&& rng) { filtered_profile_names.push_back(std::forward(rng)); }; + std::ranges::for_each(all_profile_names.value() | std::ranges::views::filter(functor), for_each_functor); return filtered_profile_names; }