fix: compilation errors with cpp_std=c++20

There were two main issues with fmtlib and C++20 mode:

 - `fmt::format` defaults to compile-time argument checking and requires
   using `fmt::runtime(format_string)` to bypass that.
 - `std::format` implementation introduces conflicting declarations and
   we have to specify the namespace for all `format`/`format_to` calls.
This commit is contained in:
Aleksei Bavshin
2023-01-16 13:24:55 -08:00
parent 67efe1af89
commit ea17a66dfc
35 changed files with 143 additions and 137 deletions

View File

@ -4,6 +4,7 @@
#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <string_view>
#include <unordered_map>
#include "AModule.hpp"
@ -21,7 +22,9 @@ class Workspaces : public AModule, public sigc::trackable {
auto update() -> void;
private:
static inline const std::string workspace_switch_cmd_ = "workspace {} \"{}\"";
static constexpr std::string_view workspace_switch_cmd_ = "workspace {} \"{}\"";
static constexpr std::string_view persistent_workspace_switch_cmd_ =
R"(workspace {} "{}"; move workspace to output "{}"; workspace {} "{}")";
static int convertWorkspaceNameToNum(std::string name);

View File

@ -66,9 +66,9 @@ struct formatter<pow_format> {
std::string string;
switch (spec) {
case '>':
return format_to(ctx.out(), "{:>{}}", fmt::format("{}", s), max_width);
return fmt::format_to(ctx.out(), "{:>{}}", fmt::format("{}", s), max_width);
case '<':
return format_to(ctx.out(), "{:<{}}", fmt::format("{}", s), max_width);
return fmt::format_to(ctx.out(), "{:<{}}", fmt::format("{}", s), max_width);
case '=':
format = "{coefficient:<{number_width}.1f}{padding}{prefix}{unit}";
break;
@ -77,8 +77,8 @@ struct formatter<pow_format> {
format = "{coefficient:.1f}{prefix}{unit}";
break;
}
return format_to(
ctx.out(), format, fmt::arg("coefficient", fraction),
return fmt::format_to(
ctx.out(), fmt::runtime(format), fmt::arg("coefficient", fraction),
fmt::arg("number_width", number_width),
fmt::arg("prefix", std::string() + units[pow] + ((s.binary_ && pow) ? "i" : "")),
fmt::arg("unit", s.unit_),