forked from mpusz/mp-units
refactor: got rid of FMT_RUNTIME()
as it is not the part of C++20
This commit is contained in:
@@ -105,7 +105,7 @@ struct STD_FMT::formatter<geographic::latitude> : formatter<geographic::latitude
|
|||||||
template<typename FormatContext>
|
template<typename FormatContext>
|
||||||
auto format(geographic::latitude lat, FormatContext& ctx)
|
auto format(geographic::latitude lat, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
STD_FMT::format_to(ctx.out(), FMT_RUNTIME(lat.value() > 0 ? "N" : "S"));
|
STD_FMT::vformat_to(ctx.out(), lat.value() > 0 ? "N" : "S", {});
|
||||||
return formatter<geographic::latitude::value_type>::format(lat.value() > 0 ? lat.value() : -lat.value(), ctx);
|
return formatter<geographic::latitude::value_type>::format(lat.value() > 0 ? lat.value() : -lat.value(), ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -115,7 +115,7 @@ struct STD_FMT::formatter<geographic::longitude> : formatter<geographic::longitu
|
|||||||
template<typename FormatContext>
|
template<typename FormatContext>
|
||||||
auto format(geographic::longitude lon, FormatContext& ctx)
|
auto format(geographic::longitude lon, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
STD_FMT::format_to(ctx.out(), FMT_RUNTIME(lon.value() > 0 ? "E" : "W"));
|
STD_FMT::vformat_to(ctx.out(), lon.value() > 0 ? "E" : "W", {});
|
||||||
return formatter<geographic::longitude::value_type>::format(lon.value() > 0 ? lon.value() : -lon.value(), ctx);
|
return formatter<geographic::longitude::value_type>::format(lon.value() > 0 ? lon.value() : -lon.value(), ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -184,7 +184,7 @@ struct STD_FMT::formatter<kalman::state<Qs...>> {
|
|||||||
units::detail::quantity_global_format_specs<char> global_specs = { specs.fill, specs.align, specs.width };
|
units::detail::quantity_global_format_specs<char> global_specs = { specs.fill, specs.align, specs.width };
|
||||||
units::detail::format_global_buffer(std::back_inserter(global_format_buffer), global_specs);
|
units::detail::format_global_buffer(std::back_inserter(global_format_buffer), global_specs);
|
||||||
|
|
||||||
return STD_FMT::format_to(ctx.out(), FMT_RUNTIME(global_format_buffer), value_buffer);
|
return STD_FMT::vformat_to(ctx.out(), global_format_buffer, STD_FMT::make_format_args(value_buffer));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
units::detail::dynamic_format_specs<char> specs;
|
units::detail::dynamic_format_specs<char> specs;
|
||||||
@@ -221,7 +221,7 @@ struct STD_FMT::formatter<kalman::estimation<Q>> {
|
|||||||
units::detail::quantity_global_format_specs<char> global_specs = { specs.fill, specs.align, specs.width };
|
units::detail::quantity_global_format_specs<char> global_specs = { specs.fill, specs.align, specs.width };
|
||||||
units::detail::format_global_buffer(std::back_inserter(global_format_buffer), global_specs);
|
units::detail::format_global_buffer(std::back_inserter(global_format_buffer), global_specs);
|
||||||
|
|
||||||
return STD_FMT::format_to(ctx.out(), FMT_RUNTIME(global_format_buffer), value_buffer);
|
return STD_FMT::vformat_to(ctx.out(), global_format_buffer, STD_FMT::make_format_args(value_buffer));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
units::detail::dynamic_format_specs<char> specs;
|
units::detail::dynamic_format_specs<char> specs;
|
||||||
|
@@ -42,7 +42,6 @@ UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
|||||||
UNITS_DIAGNOSTIC_POP
|
UNITS_DIAGNOSTIC_POP
|
||||||
|
|
||||||
#define STD_FMT fmt
|
#define STD_FMT fmt
|
||||||
#define FMT_RUNTIME(arg) fmt::runtime(arg)
|
|
||||||
#define FMT_LOCALE(loc) (loc).template get<std::locale>()
|
#define FMT_LOCALE(loc) (loc).template get<std::locale>()
|
||||||
#define FMT_TO_ARG_ID(arg) static_cast<int>(arg)
|
#define FMT_TO_ARG_ID(arg) static_cast<int>(arg)
|
||||||
#define FMT_FROM_ARG_ID(arg) static_cast<size_t>(arg)
|
#define FMT_FROM_ARG_ID(arg) static_cast<size_t>(arg)
|
||||||
@@ -56,7 +55,6 @@ UNITS_DIAGNOSTIC_POP
|
|||||||
#include <format>
|
#include <format>
|
||||||
|
|
||||||
#define STD_FMT std
|
#define STD_FMT std
|
||||||
#define FMT_RUNTIME(arg) arg
|
|
||||||
#define FMT_LOCALE(loc) loc
|
#define FMT_LOCALE(loc) loc
|
||||||
#define FMT_TO_ARG_ID(arg) arg
|
#define FMT_TO_ARG_ID(arg) arg
|
||||||
#define FMT_FROM_ARG_ID(arg) arg
|
#define FMT_FROM_ARG_ID(arg) arg
|
||||||
|
@@ -233,9 +233,9 @@ template<typename CharT, typename Rep, typename OutputIt, typename Locale>
|
|||||||
|
|
||||||
STD_FMT::format_to(to_buffer, "}}");
|
STD_FMT::format_to(to_buffer, "}}");
|
||||||
if (rep_specs.localized) {
|
if (rep_specs.localized) {
|
||||||
return STD_FMT::format_to(out, FMT_LOCALE(loc), FMT_RUNTIME(buffer), val);
|
return STD_FMT::vformat_to(out, FMT_LOCALE(loc), buffer, STD_FMT::make_format_args(val));
|
||||||
}
|
}
|
||||||
return STD_FMT::format_to(out, FMT_RUNTIME(buffer), val);
|
return STD_FMT::vformat_to(out, buffer, STD_FMT::make_format_args(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a global format string
|
// Creates a global format string
|
||||||
@@ -457,7 +457,7 @@ public:
|
|||||||
|
|
||||||
// Format the `quantity buffer` using specs from `global_format_buffer`
|
// Format the `quantity buffer` using specs from `global_format_buffer`
|
||||||
// In the example, equivalent to STD_FMT::format("{:*^10}", "1.2_m")
|
// In the example, equivalent to STD_FMT::format("{:*^10}", "1.2_m")
|
||||||
return STD_FMT::format_to(ctx.out(), FMT_RUNTIME(global_format_buffer), quantity_buffer);
|
return STD_FMT::vformat_to(ctx.out(), global_format_buffer, STD_FMT::make_format_args(quantity_buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1034,12 +1034,12 @@ TEST_CASE("precision specification for integral representation should throw", "[
|
|||||||
{
|
{
|
||||||
SECTION("full format {:%Q %q} on a quantity")
|
SECTION("full format {:%Q %q} on a quantity")
|
||||||
{
|
{
|
||||||
REQUIRE_THROWS_MATCHES(STD_FMT::format(FMT_RUNTIME("{:%.1Q %q}"), 1_q_m), STD_FMT::format_error, Message("precision not allowed for integral quantity representation"));
|
REQUIRE_THROWS_MATCHES(STD_FMT::format("{:%.1Q %q}", 1_q_m), STD_FMT::format_error, Message("precision not allowed for integral quantity representation"));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("value only format {:%Q} on a quantity")
|
SECTION("value only format {:%Q} on a quantity")
|
||||||
{
|
{
|
||||||
REQUIRE_THROWS_MATCHES(STD_FMT::format(FMT_RUNTIME("{:%.1Q}"), 1_q_m), STD_FMT::format_error, Message("precision not allowed for integral quantity representation"));
|
REQUIRE_THROWS_MATCHES(STD_FMT::format("{:%.1Q}", 1_q_m), STD_FMT::format_error, Message("precision not allowed for integral quantity representation"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user