From 0fbd8465611e7dcd3b9572efe1e13e082c9d3f35 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 4 Sep 2017 11:41:15 -0700 Subject: [PATCH] Replace fmt::internal::make_unsigned with std::make_unsigned --- fmt/format.h | 20 ++------------------ fmt/ostream.cc | 2 +- fmt/printf.h | 12 ++++++++++-- test/ostream-test.cc | 2 +- test/printf-test.cc | 6 +++--- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/fmt/format.h b/fmt/format.h index 0be4cd70..6616d27a 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -488,27 +488,11 @@ struct formatter; namespace internal { -// make_unsigned::type gives an unsigned type corresponding to integer -// type T. -template -struct make_unsigned { typedef T type; }; - -#define FMT_SPECIALIZE_MAKE_UNSIGNED(T, U) \ - template <> \ - struct make_unsigned { typedef U type; } - -FMT_SPECIALIZE_MAKE_UNSIGNED(char, unsigned char); -FMT_SPECIALIZE_MAKE_UNSIGNED(signed char, unsigned char); -FMT_SPECIALIZE_MAKE_UNSIGNED(short, unsigned short); -FMT_SPECIALIZE_MAKE_UNSIGNED(int, unsigned); -FMT_SPECIALIZE_MAKE_UNSIGNED(long, unsigned long); -FMT_SPECIALIZE_MAKE_UNSIGNED(long long, unsigned long long); - // Casts nonnegative integer to unsigned. template -inline typename make_unsigned::type to_unsigned(Int value) { +inline typename std::make_unsigned::type to_unsigned(Int value) { FMT_ASSERT(value >= 0, "negative value"); - return static_cast::type>(value); + return static_cast::type>(value); } // The number of characters to store in the basic_memory_buffer object itself diff --git a/fmt/ostream.cc b/fmt/ostream.cc index 8fb717bd..d7bbb912 100644 --- a/fmt/ostream.cc +++ b/fmt/ostream.cc @@ -14,7 +14,7 @@ namespace fmt { namespace internal { FMT_FUNC void write(std::ostream &os, buffer &buf) { const char *data = buf.data(); - typedef internal::make_unsigned::type UnsignedStreamSize; + typedef std::make_unsigned::type UnsignedStreamSize; UnsignedStreamSize size = buf.size(); UnsignedStreamSize max_size = internal::to_unsigned((std::numeric_limits::max)()); diff --git a/fmt/printf.h b/fmt/printf.h index 1c58df2b..7e6b06cd 100644 --- a/fmt/printf.h +++ b/fmt/printf.h @@ -70,6 +70,14 @@ class IsZeroInt { operator()(T) { return false; } }; +template +struct make_unsigned_or_bool : std::make_unsigned {}; + +template <> +struct make_unsigned_or_bool { + using type = bool; +}; + template class ArgConverter { private: @@ -99,7 +107,7 @@ class ArgConverter { arg_ = internal::make_arg( static_cast(static_cast(value))); } else { - typedef typename internal::make_unsigned::type Unsigned; + typedef typename make_unsigned_or_bool::type Unsigned; arg_ = internal::make_arg( static_cast(static_cast(value))); } @@ -111,7 +119,7 @@ class ArgConverter { arg_ = internal::make_arg(static_cast(value)); } else { arg_ = internal::make_arg( - static_cast::type>(value)); + static_cast::type>(value)); } } } diff --git a/test/ostream-test.cc b/test/ostream-test.cc index 1b3119c3..b5deb6ad 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -155,7 +155,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) { const char *data = 0; std::size_t size = max_size; do { - typedef fmt::internal::make_unsigned::type UStreamSize; + typedef std::make_unsigned::type UStreamSize; UStreamSize n = std::min( size, fmt::internal::to_unsigned(max_streamsize)); EXPECT_CALL(streambuf, xsputn(data, static_cast(n))) diff --git a/test/printf-test.cc b/test/printf-test.cc index aeeac1f3..c2d9e3d1 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -306,13 +306,13 @@ void TestLength(const char *length_spec, U value) { signed_value = static_cast(value); unsigned_value = static_cast(value); } - using fmt::internal::make_unsigned; if (sizeof(U) <= sizeof(int) && sizeof(int) < sizeof(T)) { signed_value = static_cast(value); - unsigned_value = static_cast::type>(value); + unsigned_value = + static_cast::type>(value); } else { signed_value = static_cast::type>(value); - unsigned_value = static_cast::type>(value); + unsigned_value = static_cast::type>(value); } std::ostringstream os; os << signed_value;