@@ -73,4 +73,32 @@ using VelocityPose = AbstractPose<std::ratio<1>>;
73
73
// AccelerationPose (Length / Time^2, Angle / Time^2)
74
74
using AccelerationPose = AbstractPose<std::ratio<2 >>;
75
75
76
- } // namespace units
76
+ } // namespace units
77
+
78
+ template <> struct std ::formatter<units::Pose, char > : std::formatter<double , char > {
79
+ // Parse specifiers (using the base class's parse function)
80
+ template <typename ParseContext> constexpr auto parse (ParseContext& ctx) {
81
+ // Call parse on the current object (base class subobject)
82
+ return std::formatter<double , char >::parse (ctx);
83
+ }
84
+
85
+ // Format the units::Pose object
86
+ template <typename FormatContext> auto format (const units::Pose& vector, FormatContext& ctx) const {
87
+ auto it = ctx.out ();
88
+ it = format_to (it, " (" );
89
+
90
+ // Create temporary formatter objects for Length and Angle
91
+ std::formatter<Length, char > fmtLength {};
92
+ std::formatter<Angle, char > fmtAngle {};
93
+
94
+ // Use the temporary objects to format each component.
95
+ it = fmtLength.format (vector.x , ctx);
96
+ it = format_to (it, " , " );
97
+ it = fmtLength.format (vector.y , ctx);
98
+ it = format_to (it, " , " );
99
+ it = fmtAngle.format (vector.orientation , ctx);
100
+ it = format_to (it, " )" );
101
+
102
+ return it;
103
+ }
104
+ };
0 commit comments