Skip to content

Commit

Permalink
👷 use std ranges in chwd_profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
vnepogodin committed Jul 13, 2024
1 parent c9170b6 commit 43ce421
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/chwd_profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,15 @@
#include "gucc/io_utils.hpp"
#include "gucc/string_utils.hpp"

#include <algorithm> // for any_of, sort, for_each
#include <algorithm> // for contains, sort, for_each
#include <ranges> // for ranges::*

#include <fmt/compile.h>
#include <fmt/format.h>

#define TOML_EXCEPTIONS 0 // disable exceptions
#include <toml++/toml.h>

#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 <range/v3/algorithm/any_of.hpp>
#include <range/v3/algorithm/for_each.hpp>
#include <range/v3/view/filter.hpp>

#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<std::vector<std::string>> {
Expand Down Expand Up @@ -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<std::string> 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); };

Check failure on line 53 in src/chwd_profiles.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

src/chwd_profiles.cpp:53:83 [clang-diagnostic-error]

no matching function for call to 'contains'

Check failure on line 53 in src/chwd_profiles.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

src/chwd_profiles.cpp:53:83 [clang-diagnostic-error]

no member named 'contains' in namespace 'std::ranges'; did you mean 'gucc::utils::contains'?

ranges::for_each(all_profile_names.value() | ranges::views::filter(functor), [&](auto&& rng) { filtered_profile_names.push_back(std::forward<decltype(rng)>(rng)); });
const auto& for_each_functor = [&](auto&& rng) { filtered_profile_names.push_back(std::forward<decltype(rng)>(rng)); };
std::ranges::for_each(all_profile_names.value() | std::ranges::views::filter(functor), for_each_functor);

Check failure on line 56 in src/chwd_profiles.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

src/chwd_profiles.cpp:56:53 [clang-diagnostic-error]

invalid operands to binary expression ('std::vector<std::basic_string<char>>' and '_Partial<_Filter, decay_t<const (lambda at /home/runner/work/New-Cli-Installer/New-Cli-Installer/src/chwd_profiles.cpp:53:27) &>>' (aka '_Partial<std::ranges::views::_Filter, (lambda at /home/runner/work/New-Cli-Installer/New-Cli-Installer/src/chwd_profiles.cpp:53:27)>'))
return filtered_profile_names;
}

Expand Down

0 comments on commit 43ce421

Please sign in to comment.