From 57952505e522be868a5a8270d8670163b55ebade Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Tue, 5 May 2020 22:52:14 +0100 Subject: Update fmt to 6.2.0 (#4718) * Update fmt to 6.2.0 --- src/Vector3.h | 61 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 16 deletions(-) (limited to 'src/Vector3.h') diff --git a/src/Vector3.h b/src/Vector3.h index b3d54514b..4445c6336 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -384,22 +384,6 @@ public: z = -z; } - // tolua_end - - /** Allows formatting a Vector using the same format specifiers as for T - e.g. `fmt::format("{0:0.2f}", Vector3f{0.0231f, 1.2146f, 1.0f}) == "{0.02, 1.21, 1.00}"` */ - template - friend void format_arg(fmt::BasicFormatter & a_Formatter, const char *& a_FormatStr, Vector3 a_Vec) - { - std::array Data{{a_Vec.x, a_Vec.y, a_Vec.z}}; - - a_Formatter.writer() << '{'; - fmt::format_arg(a_Formatter, a_FormatStr, fmt::join(Data.cbegin(), Data.cend(), ", ")); - a_Formatter.writer() << '}'; - } - - // tolua_begin - /** The max difference between two coords for which the coords are assumed equal. */ static const double EPS; @@ -411,6 +395,51 @@ public: +namespace fmt +{ + +template +class formatter>: + public fmt::formatter +{ + using Super = fmt::formatter; + + template + void Write(FormatContext & a_Ctx, const char (& a_Str)[Len]) + { + auto Itr = std::copy_n(&a_Str[0], Len - 1, a_Ctx.out()); + a_Ctx.advance_to(Itr); + } + + template + void Write(FormatContext & a_Ctx, const What & a_Arg) + { + auto Itr = Super::format(a_Arg, a_Ctx); + a_Ctx.advance_to(Itr); + } + +public: + + template + auto format(const Vector3 & a_Vec, FormatContext & a_Ctx) + -> typename FormatContext::iterator + { + Write(a_Ctx, "{"); + Write(a_Ctx, a_Vec.x); + Write(a_Ctx, ", "); + Write(a_Ctx, a_Vec.y); + Write(a_Ctx, ", "); + Write(a_Ctx, a_Vec.z); + Write(a_Ctx, "}"); + return a_Ctx.out(); + } +}; + +} + + + + template <> inline Vector3 Vector3::Floor(void) const { -- cgit v1.2.3