modernization: tweaks for c++20

Update various places for what we can do with C++20:

- ends_with / starts_with
- std::to_array
- using instead of typedef
- designated initializers
- "[[maybe_unused]]" instead of G_GNUC_UNUSED

Also remove some unnecessary 'static'
This commit is contained in:
Dirk-Jan C. Binnema
2026-07-21 14:12:33 +03:00
committed by Seth Ladygo
parent 502c9cd67b
commit 86464cd083
40 changed files with 155 additions and 166 deletions

View File

@ -71,7 +71,7 @@ create_maildir(const std::string& path, mode_t mode)
if (path.empty())
return Err(Error{Error::Code::File, "path must not be empty"});
std::array<std::string,3> subdirs = {"new", "cur", "tmp"};
const auto subdirs = std::to_array<std::string>({"new", "cur", "tmp"});
for (auto&& subdir: subdirs) {
const auto fullpath{join_paths(path, subdir)};
@ -274,7 +274,7 @@ msg_move_verify(const std::string& src, const std::string& dst)
// valgrind warning in tests
/* use GIO to move files; this is slower than rename() so only use
* this when needed: when moving across filesystems */
G_GNUC_UNUSED static Mu::Result<void>
[[maybe_unused]] static Mu::Result<void>
msg_move_g_file(const std::string& src, const std::string& dst)
{
GFile *srcfile{g_file_new_for_path(src.c_str())};
@ -296,7 +296,7 @@ msg_move_g_file(const std::string& src, const std::string& dst)
/* use mv to move files; this is slower than rename() so only use this when
* needed: when moving across filesystems */
G_GNUC_UNUSED static Mu::Result<void>
[[maybe_unused]] static Mu::Result<void>
msg_move_mv_file(const std::string& src, const std::string& dst)
{
static const auto mv_path{program_in_path("mv")};
@ -407,7 +407,7 @@ check_determine_target_params (const std::string& old_path,
"target maildir must be empty or start with / ({})",
target_maildir});
if (old_path.find(root_maildir_path) != 0)
if (!old_path.starts_with(root_maildir_path))
return Err(Error{Error::Code::File,
"old-path must be below root-maildir ({}) ({})",
old_path, root_maildir_path});