feat: std::format support for compliant compilers added

This commit is contained in:
Mateusz Pusz
2021-09-20 15:01:58 +02:00
parent 9b842ac879
commit b1bd4cab2d
40 changed files with 1447 additions and 975 deletions
+3 -2
View File
@@ -21,6 +21,7 @@
// SOFTWARE.
#include "glide_computer.h"
#include <iostream>
#include <numeric>
#include <string_view>
@@ -136,8 +137,8 @@ namespace glide_computer {
void estimate(timestamp start_ts, const glider& g, const weather& w, const task& t, const safety& s, const aircraft_tow& at)
{
fmt::print("| {:<12} | {:^28} | {:^26} | {:^21} |\n", "Flight phase", "Duration", "Distance", "Height");
fmt::print("|{0:-^14}|{0:-^30}|{0:-^28}|{0:-^23}|\n", "");
std::cout << STD_FMT::format("| {:<12} | {:^28} | {:^26} | {:^21} |\n", "Flight phase", "Duration", "Distance", "Height");
std::cout << STD_FMT::format("|{0:-^14}|{0:-^30}|{0:-^28}|{0:-^23}|\n", "");
// ready to takeoff
flight_point pos = takeoff(start_ts, t);
+5 -10
View File
@@ -22,15 +22,10 @@
#pragma once
#include <units/bits/external/hacks.h>
#include <units/bits/fmt_hacks.h>
#include <units/isq/si/length.h>
#include <units/quantity_kind.h>
UNITS_DIAGNOSTIC_PUSH
UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE
#include <fmt/format.h>
UNITS_DIAGNOSTIC_POP
#include <limits>
#include <ostream>
@@ -106,21 +101,21 @@ class std::numeric_limits<geographic::longitude> : public numeric_limits<geograp
};
template<>
struct fmt::formatter<geographic::latitude> : formatter<geographic::latitude::value_type> {
struct STD_FMT::formatter<geographic::latitude> : formatter<geographic::latitude::value_type> {
template<typename FormatContext>
auto format(geographic::latitude lat, FormatContext& ctx)
{
fmt::format_to(ctx.out(), fmt::runtime(lat.value() > 0 ? "N" : "S"));
STD_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);
}
};
template<>
struct fmt::formatter<geographic::longitude> : formatter<geographic::longitude::value_type> {
struct STD_FMT::formatter<geographic::longitude> : formatter<geographic::longitude::value_type> {
template<typename FormatContext>
auto format(geographic::longitude lon, FormatContext& ctx)
{
fmt::format_to(ctx.out(), fmt::runtime(lon.value() > 0 ? "E" : "W"));
STD_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);
}
};
@@ -57,7 +57,7 @@
// - flight path exactly on a shortest possible line to destination
template<units::QuantityKind QK>
struct fmt::formatter<QK> : formatter<typename QK::quantity_type> {
struct STD_FMT::formatter<QK> : formatter<typename QK::quantity_type> {
template<typename FormatContext>
auto format(const QK& v, FormatContext& ctx)
{
@@ -105,12 +105,12 @@ std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>&
} // namespace glide_computer
template<>
struct fmt::formatter<glide_computer::altitude> : formatter<units::isq::si::length<units::isq::si::metre>> {
struct STD_FMT::formatter<glide_computer::altitude> : formatter<units::isq::si::length<units::isq::si::metre>> {
template<typename FormatContext>
auto format(glide_computer::altitude a, FormatContext& ctx)
{
formatter<units::isq::si::length<units::isq::si::metre>>::format(a.relative().common(), ctx);
return fmt::format_to(ctx.out(), " AMSL");
return STD_FMT::format_to(ctx.out(), " AMSL");
}
};