aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-14 14:46:30 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-14 14:46:30 +0100
commit65906bc4de308c5841154a3d25368ade2eb38947 (patch)
tree7d1ead30c4804f723f1e29219b5c5b879c285b0e /src/crepe/api
parent22abed597868511c595c1226e9137beca7837576 (diff)
add std::formatter for Vector2
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/Vector2.h7
-rw-r--r--src/crepe/api/Vector2.hpp6
2 files changed, 13 insertions, 0 deletions
diff --git a/src/crepe/api/Vector2.h b/src/crepe/api/Vector2.h
index bf9d124..f4ba2b2 100644
--- a/src/crepe/api/Vector2.h
+++ b/src/crepe/api/Vector2.h
@@ -1,5 +1,7 @@
#pragma once
+#include <format>
+
namespace crepe {
//! 2D vector
@@ -94,4 +96,9 @@ struct Vector2 {
} // namespace crepe
+template <typename T>
+struct std::formatter<crepe::Vector2<T>> : std::formatter<std::string> {
+ format_context::iterator format(crepe::Vector2<T> vec, format_context & ctx) const;
+};
+
#include "Vector2.hpp"
diff --git a/src/crepe/api/Vector2.hpp b/src/crepe/api/Vector2.hpp
index ff53cb0..75d875a 100644
--- a/src/crepe/api/Vector2.hpp
+++ b/src/crepe/api/Vector2.hpp
@@ -164,3 +164,9 @@ Vector2<T> Vector2<T>::perpendicular() const {
}
} // namespace crepe
+
+template <typename T>
+std::format_context::iterator std::formatter<crepe::Vector2<T>>::format(crepe::Vector2<T> vec, format_context & ctx) const {
+ return formatter<string>::format(std::format("{{{}, {}}}", vec.x, vec.y), ctx);
+}
+