mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 23:13:26 +00:00
Adds std::format support for math types
Adds `std::formatter` specializations for `Mat`, `Vector2`, `Vector3`, and `Vector4` types, enabling the use of `std::format` for these types. This simplifies formatting and printing of these mathematical objects, improving code readability and consistency. Also adds a hash function specialization for Vector3.
This commit is contained in:
@@ -201,3 +201,18 @@ namespace omath
|
||||
#endif
|
||||
};
|
||||
} // namespace omath
|
||||
|
||||
template<class Type>
|
||||
struct std::formatter<omath::Vector4<Type>> // NOLINT(*-dcl58-cpp)
|
||||
{
|
||||
[[nodiscard]]
|
||||
static constexpr auto parse(std::format_parse_context& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
[[nodiscard]]
|
||||
static auto format(const omath::Vector4<Type>& vec, std::format_context& ctx)
|
||||
{
|
||||
return std::format_to(ctx.out(), "[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user