File tree Expand file tree Collapse file tree 4 files changed +32
-6
lines changed Expand file tree Collapse file tree 4 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ constexpr auto parse_impl(ParseContext &ctx)
77
77
}
78
78
79
79
// If there is a . then we need to capture the precision argument
80
- if (*it == ' .' )
80
+ if (it != ctx. end () && *it == ' .' )
81
81
{
82
82
++it;
83
83
ctx_precision = 0 ;
@@ -172,7 +172,6 @@ struct formatter
172
172
template <typename FormatContext>
173
173
auto format (const T& v, FormatContext& ctx) const
174
174
{
175
- auto out = ctx.out ();
176
175
std::array<char , 128 > buffer {};
177
176
auto buffer_front = buffer.data ();
178
177
bool has_sign {false };
@@ -229,7 +228,7 @@ struct formatter
229
228
s.insert (s.begin () + static_cast <std::size_t >(has_sign), static_cast <std::size_t >(padding_digits) - s.size (), ' 0' );
230
229
}
231
230
232
- return std::copy (s. begin (), s. end (), out );
231
+ return fmt::format_to (ctx. out (), " {} " , s );
233
232
}
234
233
};
235
234
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ constexpr auto parse_impl(ParseContext &ctx)
77
77
}
78
78
79
79
// If there is a . then we need to capture the precision argument
80
- if (*it == ' .' )
80
+ if (it != ctx. end () && *it == ' .' )
81
81
{
82
82
++it;
83
83
ctx_precision = 0 ;
@@ -176,7 +176,6 @@ struct formatter<T>
176
176
using namespace boost ::decimal;
177
177
using namespace boost ::decimal::detail;
178
178
179
- auto out = ctx.out ();
180
179
std::array<char , 128 > buffer {};
181
180
auto buffer_front = buffer.data ();
182
181
bool has_sign {false };
@@ -233,7 +232,7 @@ struct formatter<T>
233
232
s.insert (s.begin () + static_cast <std::size_t >(has_sign), static_cast <std::size_t >(padding_digits) - s.size (), ' 0' );
234
233
}
235
234
236
- return std::copy (s. begin (), s. end (), out );
235
+ return std::format_to (ctx. out (), " {} " , s );
237
236
}
238
237
};
239
238
Original file line number Diff line number Diff line change @@ -189,6 +189,13 @@ void test_hex()
189
189
BOOST_TEST_EQ (std::format (" {:A}" , -std::numeric_limits<T>::signaling_NaN ()), " -NAN(SNAN)" );
190
190
}
191
191
192
+ template <typename T>
193
+ void test_with_string ()
194
+ {
195
+ BOOST_TEST_EQ (std::format (" Height is: {:.0f} meters" , T {0 }), " Height is: 0 meters" );
196
+ BOOST_TEST_EQ (std::format (" Height is: {} meters" , T {2 }), " Height is: 2 meters" );
197
+ }
198
+
192
199
int main ()
193
200
{
194
201
test_general<decimal32_t >();
@@ -219,6 +226,13 @@ int main()
219
226
test_hex<decimal128_t >();
220
227
test_hex<decimal_fast128_t >();
221
228
229
+ test_with_string<decimal32_t >();
230
+ test_with_string<decimal_fast32_t >();
231
+ test_with_string<decimal64_t >();
232
+ test_with_string<decimal_fast64_t >();
233
+ test_with_string<decimal128_t >();
234
+ test_with_string<decimal_fast128_t >();
235
+
222
236
return boost::report_errors ();
223
237
}
224
238
Original file line number Diff line number Diff line change @@ -213,6 +213,13 @@ void test_hex()
213
213
BOOST_TEST_EQ (fmt::format (" {:A}" , -std::numeric_limits<T>::signaling_NaN ()), " -NAN(SNAN)" );
214
214
}
215
215
216
+ template <typename T>
217
+ void test_with_string ()
218
+ {
219
+ BOOST_TEST_EQ (std::format (" Height is: {:.0f} meters" , T {0 }), " Height is: 0 meters" );
220
+ BOOST_TEST_EQ (std::format (" Height is: {} meters" , T {2 }), " Height is: 2 meters" );
221
+ }
222
+
216
223
#ifdef _MSC_VER
217
224
#pragma warning(pop)
218
225
#endif
@@ -247,6 +254,13 @@ int main()
247
254
test_hex<decimal128_t >();
248
255
test_hex<decimal_fast128_t >();
249
256
257
+ test_with_string<decimal32_t >();
258
+ test_with_string<decimal_fast32_t >();
259
+ test_with_string<decimal64_t >();
260
+ test_with_string<decimal_fast64_t >();
261
+ test_with_string<decimal128_t >();
262
+ test_with_string<decimal_fast128_t >();
263
+
250
264
return boost::report_errors ();
251
265
}
252
266
You can’t perform that action at this time.
0 commit comments