From c48438a70fb6b92a59ba1a053ba33efbca564e27 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sat, 13 Jul 2024 03:15:57 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20gucc:=20use=20std=20ranges=20fro?= =?UTF-8?q?m=20C++23=20in=20crypttab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gucc/src/crypttab.cpp | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/gucc/src/crypttab.cpp b/gucc/src/crypttab.cpp index 610fd02..a531c08 100644 --- a/gucc/src/crypttab.cpp +++ b/gucc/src/crypttab.cpp @@ -3,33 +3,13 @@ #include "gucc/partition.hpp" #include // for any_of, sort, unique_copy - -#include +#include // for ranges::* #include #include #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 - using namespace std::string_literals; using namespace std::string_view_literals; @@ -78,18 +58,18 @@ auto generate_crypttab_content(const std::vector& partitions, std::st // sort by mountpoint & device auto partitions_sorted{partitions}; - ranges::sort(partitions_sorted, {}, &Partition::mountpoint); - ranges::sort(partitions_sorted, {}, &Partition::device); + std::ranges::sort(partitions_sorted, {}, &Partition::mountpoint); + std::ranges::sort(partitions_sorted, {}, &Partition::device); // filter duplicates std::vector partitions_filtered{}; - ranges::unique_copy( + std::ranges::unique_copy( partitions_sorted, std::back_inserter(partitions_filtered), {}, &Partition::device); - const bool is_root_encrypted = ranges::any_of(partitions, [](auto&& part) { return part.mountpoint == "/"sv && part.luks_mapper_name; }); - const bool is_boot_encrypted = ranges::any_of(partitions, [](auto&& part) { return part.mountpoint == "/bool"sv && part.luks_mapper_name; }); + const bool is_root_encrypted = std::ranges::any_of(partitions, [](auto&& part) { return part.mountpoint == "/"sv && part.luks_mapper_name; }); + const bool is_boot_encrypted = std::ranges::any_of(partitions, [](auto&& part) { return part.mountpoint == "/bool"sv && part.luks_mapper_name; }); for (auto&& partition : partitions_filtered) { auto crypttab_entry = gen_crypttab_entry(partition, crypttab_opts, is_root_encrypted, is_boot_encrypted);