@@ -423,12 +423,14 @@ bool formats::operator!=(const formats& other) const
423
423
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
424
424
425
425
template <typename T>
426
- static void register_integer_adapter (formats& fmt)
426
+ static void register_integer_adapter (formats& fmt,
427
+ duplicate_type_action on_duplicate = duplicate_type_action::exception
428
+ )
427
429
{
428
430
static auto instance = make_adapter ([] (const value& from) { return T (from.as_integer ()); },
429
431
[] (const T& from) { return value (static_cast <std::int64_t >(from)); }
430
432
);
431
- fmt.register_adapter (&instance);
433
+ fmt.register_adapter (&instance, on_duplicate );
432
434
}
433
435
434
436
static formats create_default_formats ()
@@ -468,15 +470,13 @@ static formats create_default_formats()
468
470
register_integer_adapter<std::uint32_t >(fmt);
469
471
register_integer_adapter<std::int64_t >(fmt);
470
472
register_integer_adapter<std::uint64_t >(fmt);
471
- #if defined(__APPLE__)
472
- register_integer_adapter<std::size_t >(fmt);
473
- register_integer_adapter<long >(fmt);
474
- #elif defined(_MSC_VER)
475
- // In MSVC's 64-bit compiler, `std::int64_t` is a distinct type from `long`. Since these are really common types,
476
- // we will add them explicitly.
477
- register_integer_adapter<long >(fmt);
478
- register_integer_adapter<unsigned long >(fmt);
479
- #endif
473
+
474
+ // These common types are usually covered by the explicitly-sized integers, but try to add them for platforms like
475
+ // OSX and Windows.
476
+ register_integer_adapter<std::size_t >(fmt, duplicate_type_action::ignore);
477
+ register_integer_adapter<std::ptrdiff_t >(fmt, duplicate_type_action::ignore);
478
+ register_integer_adapter<long >(fmt, duplicate_type_action::ignore);
479
+ register_integer_adapter<unsigned long >(fmt, duplicate_type_action::ignore);
480
480
481
481
static auto double_extractor = make_adapter ([] (const value& from) { return from.as_decimal (); },
482
482
[] (const double & from) { return value (from); }
@@ -534,10 +534,11 @@ formats formats::reset_global()
534
534
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
535
535
536
536
template <typename T>
537
- static void register_integer_coerce_extractor (formats& fmt)
537
+ static void register_integer_coerce_extractor (formats& fmt,
538
+ duplicate_type_action on_duplicate = duplicate_type_action::exception )
538
539
{
539
540
static auto instance = make_extractor ([] (const value& from) { return T (coerce_integer (from)); });
540
- fmt.register_extractor (&instance);
541
+ fmt.register_extractor (&instance, on_duplicate );
541
542
}
542
543
543
544
static formats create_coerce_formats ()
@@ -559,6 +560,13 @@ static formats create_coerce_formats()
559
560
register_integer_coerce_extractor<std::int64_t >(fmt);
560
561
register_integer_coerce_extractor<std::uint64_t >(fmt);
561
562
563
+ // These common types are usually covered by the explicitly-sized integers, but try to add them for platforms like
564
+ // OSX and Windows.
565
+ register_integer_coerce_extractor<std::size_t >(fmt, duplicate_type_action::ignore);
566
+ register_integer_coerce_extractor<std::ptrdiff_t >(fmt, duplicate_type_action::ignore);
567
+ register_integer_coerce_extractor<long >(fmt, duplicate_type_action::ignore);
568
+ register_integer_coerce_extractor<unsigned long >(fmt, duplicate_type_action::ignore);
569
+
562
570
static auto double_extractor = make_extractor ([] (const value& from) { return coerce_decimal (from); });
563
571
fmt.register_extractor (&double_extractor);
564
572
static auto float_extractor = make_extractor ([] (const value& from) { return float (coerce_decimal (from)); });
0 commit comments