@@ -228,19 +228,29 @@ class kstream {
228
228
*/
229
229
static int mod (int a, int b);
230
230
231
+ // NB: the following 6 overloads of `to_string` are exactly the ones that
232
+ // [`std::to_string`](https://en.cppreference.com/w/cpp/string/basic_string/to_string) has.
233
+ // Testing has shown that they are all necessary: if you remove any of them, you will get
234
+ // something like `error: call to 'to_string' is ambiguous` when trying to call `to_string`
235
+ // with the integer type for which you removed the overload.
236
+
231
237
/* *
232
238
* Converts given integer `val` to a decimal string representation.
233
239
* Should be used in place of `std::to_string(int)` (which is available only
234
240
* since C++11) in older C++ implementations.
235
241
*/
236
- static std::string to_string (int val);
242
+ static std::string to_string (int val) {
243
+ return to_string_signed (val);
244
+ }
237
245
238
246
/* *
239
247
* Converts given integer `val` to a decimal string representation.
240
248
* Should be used in place of `std::to_string(long)` (which is available only
241
249
* since C++11) in older C++ implementations.
242
250
*/
243
- static std::string to_string (long val);
251
+ static std::string to_string (long val) {
252
+ return to_string_signed (val);
253
+ }
244
254
245
255
// The `long long` type is only available since C++11, so we use it only in C++11 mode.
246
256
#ifdef KAITAI_STREAM_H_CPP11_SUPPORT
@@ -249,22 +259,28 @@ class kstream {
249
259
* Should be used in place of `std::to_string(long long)` (which is available only
250
260
* since C++11) in older C++ implementations.
251
261
*/
252
- static std::string to_string (long long val);
262
+ static std::string to_string (long long val) {
263
+ return to_string_signed (val);
264
+ }
253
265
#endif
254
266
255
267
/* *
256
268
* Converts given integer `val` to a decimal string representation.
257
269
* Should be used in place of `std::to_string(unsigned)` (which is available only
258
270
* since C++11) in older C++ implementations.
259
271
*/
260
- static std::string to_string (unsigned val);
272
+ static std::string to_string (unsigned val) {
273
+ return to_string_unsigned (val);
274
+ }
261
275
262
276
/* *
263
277
* Converts given integer `val` to a decimal string representation.
264
278
* Should be used in place of `std::to_string(unsigned long)` (which is available only
265
279
* since C++11) in older C++ implementations.
266
280
*/
267
- static std::string to_string (unsigned long val);
281
+ static std::string to_string (unsigned long val) {
282
+ return to_string_unsigned (val);
283
+ }
268
284
269
285
// The `unsigned long long` type is only available since C++11, so we use it only in C++11 mode.
270
286
#ifdef KAITAI_STREAM_H_CPP11_SUPPORT
@@ -273,7 +289,9 @@ class kstream {
273
289
* Should be used in place of `std::to_string(unsigned long long)` (which is available only
274
290
* since C++11) in older C++ implementations.
275
291
*/
276
- static std::string to_string (unsigned long long val);
292
+ static std::string to_string (unsigned long long val) {
293
+ return to_string_unsigned (val);
294
+ }
277
295
#endif
278
296
279
297
/* *
0 commit comments