mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
129 lines
4.3 KiB
Diff
129 lines
4.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Tyler Veness <calcmogul@gmail.com>
|
|
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 <Eigen/Core>
|
|
#include <Eigen/SparseCore>
|
|
+#include <fmt/chrono.h>
|
|
#include <gch/small_vector.hpp>
|
|
|
|
#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 <format>
|
|
#include <source_location>
|
|
#include <stdexcept>
|
|
|
|
+#include <fmt/format.h>
|
|
+
|
|
/**
|
|
* 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 <cstdio>
|
|
-#include <print>
|
|
#include <system_error>
|
|
#include <utility>
|
|
|
|
+#if __has_include(<fmt/base.h>)
|
|
+#include <fmt/base.h>
|
|
+#else
|
|
+#include <fmt/core.h>
|
|
+#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 <typename... T>
|
|
-void print(std::format_string<T...> fmt, T&&... args) {
|
|
+void print(fmt::format_string<T...> fmt, T&&... args) {
|
|
try {
|
|
- std::print(fmt, std::forward<T>(args)...);
|
|
+ fmt::print(fmt, std::forward<T>(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 <typename... T>
|
|
-void print(std::FILE* f, std::format_string<T...> fmt, T&&... args) {
|
|
+void print(std::FILE* f, fmt::format_string<T...> fmt, T&&... args) {
|
|
try {
|
|
- std::print(f, fmt, std::forward<T>(args)...);
|
|
+ fmt::print(f, fmt, std::forward<T>(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 <typename... T>
|
|
-void println(std::format_string<T...> fmt, T&&... args) {
|
|
+void println(fmt::format_string<T...> fmt, T&&... args) {
|
|
try {
|
|
- std::println(fmt, std::forward<T>(args)...);
|
|
+ fmt::println(fmt, std::forward<T>(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 <typename... T>
|
|
-void println(std::FILE* f, std::format_string<T...> fmt, T&&... args) {
|
|
+void println(std::FILE* f, fmt::format_string<T...> fmt, T&&... args) {
|
|
try {
|
|
- std::println(f, fmt, std::forward<T>(args)...);
|
|
+ fmt::println(f, fmt, std::forward<T>(args)...);
|
|
} catch (const std::system_error&) {
|
|
}
|
|
}
|