From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 29 May 2024 16:29:55 -0700 Subject: [PATCH 1/8] Use fmtlib --- include/sleipnir/optimization/problem.hpp | 1 + include/sleipnir/util/assert.hpp | 5 ++-- include/sleipnir/util/print.hpp | 31 +++++++++++++---------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/sleipnir/optimization/problem.hpp b/include/sleipnir/optimization/problem.hpp index 3185466605b6604068e2807e461d07d8c856c505..95a33952a5a368c7c81491dbe849a8096357dc38 100644 --- a/include/sleipnir/optimization/problem.hpp +++ b/include/sleipnir/optimization/problem.hpp @@ -15,6 +15,7 @@ #include #include +#include #include #include "sleipnir/autodiff/expression_type.hpp" diff --git a/include/sleipnir/util/assert.hpp b/include/sleipnir/util/assert.hpp index 0846928c3da7a6047a3c271dd2d377a3b755eeab..5d432608def05b6dee6b7cbdb9a0b91a6ab5e1c2 100644 --- a/include/sleipnir/util/assert.hpp +++ b/include/sleipnir/util/assert.hpp @@ -4,10 +4,11 @@ #ifdef SLEIPNIR_PYTHON -#include #include #include +#include + /** * Throw an exception in Python. */ @@ -15,7 +16,7 @@ do { \ if (!(condition)) { \ auto location = std::source_location::current(); \ - throw std::invalid_argument(std::format( \ + throw std::invalid_argument(fmt::format( \ "{}:{}: {}: Assertion `{}' failed.", location.file_name(), \ location.line(), location.function_name(), #condition)); \ } \ diff --git a/include/sleipnir/util/print.hpp b/include/sleipnir/util/print.hpp index 797df849f63d960cf10eaf847415595961868ab0..a89b7d4f9864965443405a8e79cddd8dbfc54ad3 100644 --- a/include/sleipnir/util/print.hpp +++ b/include/sleipnir/util/print.hpp @@ -4,10 +4,15 @@ #ifndef SLEIPNIR_DISABLE_DIAGNOSTICS #include -#include #include #include +#if __has_include() +#include +#else +#include +#endif + #endif namespace slp { @@ -15,45 +20,45 @@ namespace slp { #ifndef SLEIPNIR_DISABLE_DIAGNOSTICS /** - * Wrapper around std::print() that squelches write failure exceptions. + * Wrapper around fmt::print() that squelches write failure exceptions. */ template -void print(std::format_string fmt, T&&... args) { +void print(fmt::format_string fmt, T&&... args) { try { - std::print(fmt, std::forward(args)...); + fmt::print(fmt, std::forward(args)...); } catch (const std::system_error&) { } } /** - * Wrapper around std::print() that squelches write failure exceptions. + * Wrapper around fmt::print() that squelches write failure exceptions. */ template -void print(std::FILE* f, std::format_string fmt, T&&... args) { +void print(std::FILE* f, fmt::format_string fmt, T&&... args) { try { - std::print(f, fmt, std::forward(args)...); + fmt::print(f, fmt, std::forward(args)...); } catch (const std::system_error&) { } } /** - * Wrapper around std::println() that squelches write failure exceptions. + * Wrapper around fmt::println() that squelches write failure exceptions. */ template -void println(std::format_string fmt, T&&... args) { +void println(fmt::format_string fmt, T&&... args) { try { - std::println(fmt, std::forward(args)...); + fmt::println(fmt, std::forward(args)...); } catch (const std::system_error&) { } } /** - * Wrapper around std::println() that squelches write failure exceptions. + * Wrapper around fmt::println() that squelches write failure exceptions. */ template -void println(std::FILE* f, std::format_string fmt, T&&... args) { +void println(std::FILE* f, fmt::format_string fmt, T&&... args) { try { - std::println(f, fmt, std::forward(args)...); + fmt::println(f, fmt, std::forward(args)...); } catch (const std::system_error&) { } }