From 0ce18dc3c7c6200eaea645de0dbfe06fc327a52b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 15 Nov 2021 16:28:26 +0100 Subject: [PATCH] feat: `std::format` usage enabled for VS2022 --- conanfile.py | 9 ++++++--- example/glide_computer/glide_computer.cpp | 2 +- src/core/include/units/bits/external/hacks.h | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/conanfile.py b/conanfile.py index d383f49b..ae848677 100644 --- a/conanfile.py +++ b/conanfile.py @@ -63,9 +63,12 @@ class UnitsConan(ConanFile): @property def _use_libfmt(self): - # compiler = self.settings.compiler - # return compiler != "Visual Studio" and compiler != "msvc" # TODO Enable when VS std::format_to(ctx.out, ...) is fixed - return True + compiler = self.settings.compiler + version = Version(self.settings.compiler.version) + std_support = \ + (compiler == "Visual Studio" and version >= "17" and compiler.cppstd == 23) or \ + (compiler == "msvc" and (version == "19.3" or version >= "19.30") and compiler.cppstd == 23) + return not std_support def set_version(self): content = tools.load(os.path.join(self.recipe_folder, "src/CMakeLists.txt")) diff --git a/example/glide_computer/glide_computer.cpp b/example/glide_computer/glide_computer.cpp index 4595609b..79d325c1 100644 --- a/example/glide_computer/glide_computer.cpp +++ b/example/glide_computer/glide_computer.cpp @@ -72,7 +72,7 @@ using namespace glide_computer; void print(std::string_view phase_name, timestamp start_ts, const glide_computer::flight_point& point, const glide_computer::flight_point& new_point) { - fmt::print( + std::cout << STD_FMT::format( "| {:<12} | {:>9%.1Q %q} (Total: {:>9%.1Q %q}) | {:>8%.1Q %q} (Total: {:>8%.1Q %q}) | {:>7%.0Q %q} ({:>6%.0Q %q}) |\n", phase_name, quantity_cast(new_point.ts - point.ts), quantity_cast(new_point.ts - start_ts), new_point.dist - point.dist, new_point.dist, new_point.alt - point.alt, new_point.alt); diff --git a/src/core/include/units/bits/external/hacks.h b/src/core/include/units/bits/external/hacks.h index 126d1b2b..821590f7 100644 --- a/src/core/include/units/bits/external/hacks.h +++ b/src/core/include/units/bits/external/hacks.h @@ -22,6 +22,8 @@ #pragma once +#include + #if __clang__ #define UNITS_COMP_CLANG __clang_major__ #elif __GNUC__