mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 20:34:26 +02:00
Merge branch 'master' of https://github.com/mpusz/units
This commit is contained in:
1
.github/workflows/ci-conan.yml
vendored
1
.github/workflows/ci-conan.yml
vendored
@@ -136,6 +136,7 @@ jobs:
|
||||
if [[ "${{ matrix.config.compiler.type }}" == "GCC" || "${{ matrix.config.compiler.type }}" == "CLANG" ]]; then
|
||||
conan profile update settings.compiler.libcxx=${{ matrix.config.lib }} default
|
||||
fi
|
||||
conan profile update conf.tools.cmake.cmaketoolchain:generator=Ninja default
|
||||
conan profile show default
|
||||
# - name: Add support for clang-13 to Conan's settings.yml
|
||||
# # TODO Remove when Conan will support clang-13
|
||||
|
@@ -110,7 +110,7 @@ struct fmt::formatter<geographic::latitude> : formatter<geographic::latitude::va
|
||||
template<typename FormatContext>
|
||||
auto format(geographic::latitude lat, FormatContext& ctx)
|
||||
{
|
||||
format_to(ctx.out(), fmt::runtime(lat.value() > 0 ? "N" : "S"));
|
||||
fmt::format_to(ctx.out(), fmt::runtime(lat.value() > 0 ? "N" : "S"));
|
||||
return formatter<geographic::latitude::value_type>::format(lat.value() > 0 ? lat.value() : -lat.value(), ctx);
|
||||
}
|
||||
};
|
||||
@@ -120,7 +120,7 @@ struct fmt::formatter<geographic::longitude> : formatter<geographic::longitude::
|
||||
template<typename FormatContext>
|
||||
auto format(geographic::longitude lon, FormatContext& ctx)
|
||||
{
|
||||
format_to(ctx.out(), fmt::runtime(lon.value() > 0 ? "E" : "W"));
|
||||
fmt::format_to(ctx.out(), fmt::runtime(lon.value() > 0 ? "E" : "W"));
|
||||
return formatter<geographic::longitude::value_type>::format(lon.value() > 0 ? lon.value() : -lon.value(), ctx);
|
||||
}
|
||||
};
|
||||
|
@@ -110,7 +110,7 @@ struct fmt::formatter<glide_computer::altitude> : formatter<units::isq::si::leng
|
||||
auto format(glide_computer::altitude a, FormatContext& ctx)
|
||||
{
|
||||
formatter<units::isq::si::length<units::isq::si::metre>>::format(a.relative().common(), ctx);
|
||||
return format_to(ctx.out(), " AMSL");
|
||||
return fmt::format_to(ctx.out(), " AMSL");
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -165,26 +165,26 @@ struct fmt::formatter<kalman::state<Qs...>> {
|
||||
auto to_value_buffer = std::back_inserter(value_buffer);
|
||||
if (specs.precision != -1) {
|
||||
if constexpr(sizeof...(Qs) == 1)
|
||||
format_to(to_value_buffer, "{1:%.{0}Q %q}", specs.precision, kalman::get<0>(s));
|
||||
fmt::format_to(to_value_buffer, "{1:%.{0}Q %q}", specs.precision, kalman::get<0>(s));
|
||||
else if constexpr(sizeof...(Qs) == 2)
|
||||
format_to(to_value_buffer, "{{ {1:%.{0}Q %q}, {2:%.{0}Q %q} }}", specs.precision, kalman::get<0>(s), kalman::get<1>(s));
|
||||
fmt::format_to(to_value_buffer, "{{ {1:%.{0}Q %q}, {2:%.{0}Q %q} }}", specs.precision, kalman::get<0>(s), kalman::get<1>(s));
|
||||
else
|
||||
format_to(to_value_buffer, "{{ {1:%.{0}Q %q}, {2:%.{0}Q %q}, {3:%.{0}Q %q} }}", specs.precision, kalman::get<0>(s), kalman::get<1>(s), kalman::get<2>(s));
|
||||
fmt::format_to(to_value_buffer, "{{ {1:%.{0}Q %q}, {2:%.{0}Q %q}, {3:%.{0}Q %q} }}", specs.precision, kalman::get<0>(s), kalman::get<1>(s), kalman::get<2>(s));
|
||||
}
|
||||
else {
|
||||
if constexpr(sizeof...(Qs) == 1)
|
||||
format_to(to_value_buffer, "{}", kalman::get<0>(s));
|
||||
fmt::format_to(to_value_buffer, "{}", kalman::get<0>(s));
|
||||
else if constexpr(sizeof...(Qs) == 2)
|
||||
format_to(to_value_buffer, "{{ {}, {} }}", kalman::get<0>(s), kalman::get<1>(s));
|
||||
fmt::format_to(to_value_buffer, "{{ {}, {} }}", kalman::get<0>(s), kalman::get<1>(s));
|
||||
else
|
||||
format_to(to_value_buffer, "{{ {}, {}, {} }}", kalman::get<0>(s), kalman::get<1>(s), kalman::get<2>(s));
|
||||
fmt::format_to(to_value_buffer, "{{ {}, {}, {} }}", kalman::get<0>(s), kalman::get<1>(s), kalman::get<2>(s));
|
||||
}
|
||||
|
||||
basic_memory_buffer<char> global_format_buffer;
|
||||
units::detail::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);
|
||||
|
||||
return format_to(ctx.out(), fmt::runtime(std::string_view(global_format_buffer.data(), global_format_buffer.size())),
|
||||
return fmt::format_to(ctx.out(), fmt::runtime(std::string_view(global_format_buffer.data(), global_format_buffer.size())),
|
||||
std::string_view(value_buffer.data(), value_buffer.size()));
|
||||
}
|
||||
private:
|
||||
@@ -212,17 +212,17 @@ struct fmt::formatter<kalman::estimation<Q>> {
|
||||
memory_buffer value_buffer;
|
||||
auto to_value_buffer = std::back_inserter(value_buffer);
|
||||
if (specs.precision != -1) {
|
||||
format_to(to_value_buffer, "{0:%.{2}Q} ± {1:%.{2}Q} {0:%q}", q, sqrt(e.uncertainty), specs.precision);
|
||||
fmt::format_to(to_value_buffer, "{0:%.{2}Q} ± {1:%.{2}Q} {0:%q}", q, sqrt(e.uncertainty), specs.precision);
|
||||
}
|
||||
else {
|
||||
format_to(to_value_buffer, "{0:%Q} ± {1:%Q} {0:%q}", q, sqrt(e.uncertainty));
|
||||
fmt::format_to(to_value_buffer, "{0:%Q} ± {1:%Q} {0:%q}", q, sqrt(e.uncertainty));
|
||||
}
|
||||
|
||||
basic_memory_buffer<char> global_format_buffer;
|
||||
units::detail::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);
|
||||
|
||||
return format_to(ctx.out(), fmt::runtime(std::string_view(global_format_buffer.data(), global_format_buffer.size())),
|
||||
return fmt::format_to(ctx.out(), fmt::runtime(std::string_view(global_format_buffer.data(), global_format_buffer.size())),
|
||||
std::string_view(value_buffer.data(), value_buffer.size()));
|
||||
}
|
||||
private:
|
||||
|
@@ -24,6 +24,8 @@
|
||||
|
||||
#include <units/customization_points.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
|
||||
// IWYU pragma: begin_exports
|
||||
@@ -222,37 +224,37 @@ namespace units {
|
||||
case fmt::sign::none:
|
||||
break;
|
||||
case fmt::sign::plus:
|
||||
format_to(to_buffer, "+");
|
||||
fmt::format_to(to_buffer, "+");
|
||||
break;
|
||||
case fmt::sign::minus:
|
||||
format_to(to_buffer, "-");
|
||||
fmt::format_to(to_buffer, "-");
|
||||
break;
|
||||
case fmt::sign::space:
|
||||
format_to(to_buffer, " ");
|
||||
fmt::format_to(to_buffer, " ");
|
||||
break;
|
||||
}
|
||||
|
||||
if (rep_specs.alt) {
|
||||
format_to(to_buffer, "#");
|
||||
fmt::format_to(to_buffer, "#");
|
||||
}
|
||||
auto type = rep_specs.type;
|
||||
if (auto precision = rep_specs.precision; precision >= 0) {
|
||||
format_to(to_buffer, ".{}{}", precision, type == '\0' ? 'f' : type);
|
||||
fmt::format_to(to_buffer, ".{}{}", precision, type == '\0' ? 'f' : type);
|
||||
} else if constexpr (treat_as_floating_point<Rep>) {
|
||||
format_to(to_buffer, "{}", type == '\0' ? 'g' : type);
|
||||
fmt::format_to(to_buffer, "{}", type == '\0' ? 'g' : type);
|
||||
} else {
|
||||
if (type != '\0') {
|
||||
format_to(to_buffer, "{}", type);
|
||||
fmt::format_to(to_buffer, "{}", type);
|
||||
}
|
||||
}
|
||||
if (rep_specs.use_locale) {
|
||||
format_to(to_buffer, "L");
|
||||
fmt::format_to(to_buffer, "L");
|
||||
}
|
||||
fmt::format_to(to_buffer, "}}");
|
||||
if (rep_specs.use_locale and static_cast<bool>(loc)) {
|
||||
return format_to(out, loc.template get<std::locale>(), fmt::runtime(std::string_view(buffer.data(), buffer.size())), val);
|
||||
return fmt::format_to(out, loc.template get<std::locale>(), fmt::runtime(std::string_view(buffer.data(), buffer.size())), val);
|
||||
}
|
||||
return format_to(out, fmt::runtime(std::string_view(buffer.data(), buffer.size())), val);
|
||||
return fmt::format_to(out, fmt::runtime(std::string_view(buffer.data(), buffer.size())), val);
|
||||
}
|
||||
|
||||
// Creates a global format string
|
||||
@@ -260,27 +262,27 @@ namespace units {
|
||||
template<typename CharT, typename OutputIt>
|
||||
inline OutputIt format_global_buffer(OutputIt out, const global_format_specs<CharT>& specs)
|
||||
{
|
||||
format_to(out, "{{:");
|
||||
fmt::format_to(out, "{{:");
|
||||
if (specs.fill.size() != 1 || specs.fill[0] != ' ') {
|
||||
format_to(out, "{}", specs.fill.data());
|
||||
fmt::format_to(out, "{}", specs.fill.data());
|
||||
}
|
||||
switch (specs.align) {
|
||||
case fmt::align_t::left:
|
||||
format_to(out, "<");
|
||||
fmt::format_to(out, "<");
|
||||
break;
|
||||
case fmt::align_t::right:
|
||||
format_to(out, ">");
|
||||
fmt::format_to(out, ">");
|
||||
break;
|
||||
case fmt::align_t::center:
|
||||
format_to(out, "^");
|
||||
fmt::format_to(out, "^");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (specs.width >= 1) {
|
||||
format_to(out, "{}", specs.width);
|
||||
fmt::format_to(out, "{}", specs.width);
|
||||
}
|
||||
return format_to(out, "}}");
|
||||
return fmt::format_to(out, "}}");
|
||||
}
|
||||
|
||||
template<typename OutputIt, typename Dimension, typename Unit, typename Rep, typename LocaleRef, typename CharT>
|
||||
@@ -317,10 +319,10 @@ namespace units {
|
||||
{
|
||||
auto txt = unit_text<Dimension, Unit>();
|
||||
if(unit_specs.modifier == 'A') {
|
||||
format_to(out, "{}", txt.ascii().c_str());
|
||||
fmt::format_to(out, "{}", txt.ascii().c_str());
|
||||
}
|
||||
else {
|
||||
format_to(out, "{}", txt.standard().c_str());
|
||||
fmt::format_to(out, "{}", txt.standard().c_str());
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -493,7 +495,7 @@ public:
|
||||
constexpr auto symbol = units::detail::unit_text<Dimension, Unit>();
|
||||
if(symbol.standard().size()) {
|
||||
*to_quantity_buffer++ = CharT(' ');
|
||||
format_to(to_quantity_buffer, "{}", symbol.standard().c_str());
|
||||
fmt::format_to(to_quantity_buffer, "{}", symbol.standard().c_str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -509,6 +511,6 @@ public:
|
||||
|
||||
// Format the `quantity buffer` using specs from `global_format_buffer`
|
||||
// In the example, equivalent to fmt::format("{:*^10}", "1.2_m")
|
||||
return format_to(ctx.out(), fmt::runtime(std::basic_string_view<CharT>(global_format_buffer.data(), global_format_buffer.size())), std::string_view(quantity_buffer.data(), quantity_buffer.size()));
|
||||
return fmt::format_to(ctx.out(), fmt::runtime(std::basic_string_view<CharT>(global_format_buffer.data(), global_format_buffer.size())), std::string_view(quantity_buffer.data(), quantity_buffer.size()));
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user