Skip to content

Commit

Permalink
Fix custom Vec2 formatting with libc++
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Oct 3, 2024
1 parent c51cea1 commit 86878a2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/jngl/Vec2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ std::ostream& operator<<(std::ostream&, const Vec2&);
} // namespace jngl

#if __has_include(<format>) && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 170000)
template <> struct std::formatter<jngl::Vec2> : std::formatter<std::string> {
auto format(jngl::Vec2 v, format_context& ctx) const {
return formatter<string>::format(std::format("[x={}, y={}]", v.x, v.y), ctx);
template <> struct std::formatter<jngl::Vec2> {
constexpr auto parse(std::format_parse_context& ctx) {
return ctx.begin();
}
auto format(const jngl::Vec2& v, auto& ctx) const {
return std::format_to(ctx.out(), "[x={}, y={}]", v.x, v.y);
}
};
#endif
Expand Down

0 comments on commit 86878a2

Please sign in to comment.