mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-06 05:34:27 +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
|
if [[ "${{ matrix.config.compiler.type }}" == "GCC" || "${{ matrix.config.compiler.type }}" == "CLANG" ]]; then
|
||||||
conan profile update settings.compiler.libcxx=${{ matrix.config.lib }} default
|
conan profile update settings.compiler.libcxx=${{ matrix.config.lib }} default
|
||||||
fi
|
fi
|
||||||
|
conan profile update conf.tools.cmake.cmaketoolchain:generator=Ninja default
|
||||||
conan profile show default
|
conan profile show default
|
||||||
# - name: Add support for clang-13 to Conan's settings.yml
|
# - name: Add support for clang-13 to Conan's settings.yml
|
||||||
# # TODO Remove when Conan will support clang-13
|
# # TODO Remove when Conan will support clang-13
|
||||||
|
@@ -110,7 +110,7 @@ struct fmt::formatter<geographic::latitude> : formatter<geographic::latitude::va
|
|||||||
template<typename FormatContext>
|
template<typename FormatContext>
|
||||||
auto format(geographic::latitude lat, FormatContext& ctx)
|
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);
|
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>
|
template<typename FormatContext>
|
||||||
auto format(geographic::longitude lon, FormatContext& ctx)
|
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);
|
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)
|
auto format(glide_computer::altitude a, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
formatter<units::isq::si::length<units::isq::si::metre>>::format(a.relative().common(), 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);
|
auto to_value_buffer = std::back_inserter(value_buffer);
|
||||||
if (specs.precision != -1) {
|
if (specs.precision != -1) {
|
||||||
if constexpr(sizeof...(Qs) == 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)
|
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
|
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 {
|
else {
|
||||||
if constexpr(sizeof...(Qs) == 1)
|
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)
|
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
|
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;
|
basic_memory_buffer<char> global_format_buffer;
|
||||||
units::detail::global_format_specs<char> global_specs = { specs.fill, specs.align, specs.width };
|
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);
|
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()));
|
std::string_view(value_buffer.data(), value_buffer.size()));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
@@ -212,17 +212,17 @@ struct fmt::formatter<kalman::estimation<Q>> {
|
|||||||
memory_buffer value_buffer;
|
memory_buffer value_buffer;
|
||||||
auto to_value_buffer = std::back_inserter(value_buffer);
|
auto to_value_buffer = std::back_inserter(value_buffer);
|
||||||
if (specs.precision != -1) {
|
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 {
|
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;
|
basic_memory_buffer<char> global_format_buffer;
|
||||||
units::detail::global_format_specs<char> global_specs = { specs.fill, specs.align, specs.width };
|
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);
|
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()));
|
std::string_view(value_buffer.data(), value_buffer.size()));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
@@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
#include <units/customization_points.h>
|
#include <units/customization_points.h>
|
||||||
#include <units/quantity.h>
|
#include <units/quantity.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
// IWYU pragma: begin_exports
|
// IWYU pragma: begin_exports
|
||||||
@@ -222,37 +224,37 @@ namespace units {
|
|||||||
case fmt::sign::none:
|
case fmt::sign::none:
|
||||||
break;
|
break;
|
||||||
case fmt::sign::plus:
|
case fmt::sign::plus:
|
||||||
format_to(to_buffer, "+");
|
fmt::format_to(to_buffer, "+");
|
||||||
break;
|
break;
|
||||||
case fmt::sign::minus:
|
case fmt::sign::minus:
|
||||||
format_to(to_buffer, "-");
|
fmt::format_to(to_buffer, "-");
|
||||||
break;
|
break;
|
||||||
case fmt::sign::space:
|
case fmt::sign::space:
|
||||||
format_to(to_buffer, " ");
|
fmt::format_to(to_buffer, " ");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rep_specs.alt) {
|
if (rep_specs.alt) {
|
||||||
format_to(to_buffer, "#");
|
fmt::format_to(to_buffer, "#");
|
||||||
}
|
}
|
||||||
auto type = rep_specs.type;
|
auto type = rep_specs.type;
|
||||||
if (auto precision = rep_specs.precision; precision >= 0) {
|
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>) {
|
} 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 {
|
} else {
|
||||||
if (type != '\0') {
|
if (type != '\0') {
|
||||||
format_to(to_buffer, "{}", type);
|
fmt::format_to(to_buffer, "{}", type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rep_specs.use_locale) {
|
if (rep_specs.use_locale) {
|
||||||
format_to(to_buffer, "L");
|
fmt::format_to(to_buffer, "L");
|
||||||
}
|
}
|
||||||
fmt::format_to(to_buffer, "}}");
|
fmt::format_to(to_buffer, "}}");
|
||||||
if (rep_specs.use_locale and static_cast<bool>(loc)) {
|
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
|
// Creates a global format string
|
||||||
@@ -260,27 +262,27 @@ namespace units {
|
|||||||
template<typename CharT, typename OutputIt>
|
template<typename CharT, typename OutputIt>
|
||||||
inline OutputIt format_global_buffer(OutputIt out, const global_format_specs<CharT>& specs)
|
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] != ' ') {
|
if (specs.fill.size() != 1 || specs.fill[0] != ' ') {
|
||||||
format_to(out, "{}", specs.fill.data());
|
fmt::format_to(out, "{}", specs.fill.data());
|
||||||
}
|
}
|
||||||
switch (specs.align) {
|
switch (specs.align) {
|
||||||
case fmt::align_t::left:
|
case fmt::align_t::left:
|
||||||
format_to(out, "<");
|
fmt::format_to(out, "<");
|
||||||
break;
|
break;
|
||||||
case fmt::align_t::right:
|
case fmt::align_t::right:
|
||||||
format_to(out, ">");
|
fmt::format_to(out, ">");
|
||||||
break;
|
break;
|
||||||
case fmt::align_t::center:
|
case fmt::align_t::center:
|
||||||
format_to(out, "^");
|
fmt::format_to(out, "^");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (specs.width >= 1) {
|
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>
|
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>();
|
auto txt = unit_text<Dimension, Unit>();
|
||||||
if(unit_specs.modifier == 'A') {
|
if(unit_specs.modifier == 'A') {
|
||||||
format_to(out, "{}", txt.ascii().c_str());
|
fmt::format_to(out, "{}", txt.ascii().c_str());
|
||||||
}
|
}
|
||||||
else {
|
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>();
|
constexpr auto symbol = units::detail::unit_text<Dimension, Unit>();
|
||||||
if(symbol.standard().size()) {
|
if(symbol.standard().size()) {
|
||||||
*to_quantity_buffer++ = CharT(' ');
|
*to_quantity_buffer++ = CharT(' ');
|
||||||
format_to(to_quantity_buffer, "{}", symbol.standard().c_str());
|
fmt::format_to(to_quantity_buffer, "{}", symbol.standard().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -509,6 +511,6 @@ 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 fmt::format("{:*^10}", "1.2_m")
|
// 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