From 545dc4148a4a48e2e6f43b89799800118bc5fed2 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 14 Sep 2024 10:24:47 -0700 Subject: [PATCH] Add value ctor taking name_arg --- include/fmt/base.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index af91a11a..e4cdd5ec 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -1146,10 +1146,10 @@ template struct arg_mapper { FMT_MAP_API auto map(long double x) -> long double { return x; } template - FMT_MAP_API auto map(bitint) + static auto map(bitint) -> conditional_t; template - FMT_MAP_API auto map(ubitint) + static auto map(ubitint) -> conditional_t; FMT_MAP_API auto map(Char* x) -> const Char* { return x; } @@ -1228,9 +1228,7 @@ template struct arg_mapper { } template ::value)> - FMT_MAP_API auto map(const T& named_arg) -> decltype(map(named_arg.value)) { - return map(named_arg.value); - } + static auto map(const T& named_arg) -> decltype(map(named_arg.value)); FMT_MAP_API auto map(...) -> unformattable { return {}; } }; @@ -2187,12 +2185,18 @@ template class value { } FMT_INLINE value(const void* x FMT_BUILTIN) : pointer(x) {} + template ::value)> + value(const T& named_arg) : value(named_arg.value) {} + + template > + using mappable = + bool_constant::value && !is_named_arg::value>; + // We can't use mapped_t because of a bug in MSVC 2017. template < typename T, typename M = decltype(arg_mapper::map(std::declval())), - FMT_ENABLE_IF(!std::is_same::value && - !std::is_integral>::value)> + FMT_ENABLE_IF(!std::is_same::value && mappable::value)> FMT_CONSTEXPR20 FMT_INLINE value(T&& x) { *this = arg_mapper::map(x); } @@ -2200,8 +2204,7 @@ template class value { template < typename T, typename M = decltype(arg_mapper::map(std::declval())), - FMT_ENABLE_IF(std::is_same::value && - !std::is_integral>::value)> + FMT_ENABLE_IF(std::is_same::value&& mappable::value)> FMT_CONSTEXPR20 FMT_INLINE value(T&& x) { // Formatting of arbitrary pointers is disallowed. If you want to format a // pointer cast it to `void*` or `const void*`. In particular, this forbids