forked from fmtlib/fmt
Replace fmt::internal::make_unsigned with std::make_unsigned
This commit is contained in:
20
fmt/format.h
20
fmt/format.h
@ -488,27 +488,11 @@ struct formatter;
|
|||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
// make_unsigned<T>::type gives an unsigned type corresponding to integer
|
|
||||||
// type T.
|
|
||||||
template <typename T>
|
|
||||||
struct make_unsigned { typedef T type; };
|
|
||||||
|
|
||||||
#define FMT_SPECIALIZE_MAKE_UNSIGNED(T, U) \
|
|
||||||
template <> \
|
|
||||||
struct make_unsigned<T> { 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.
|
// Casts nonnegative integer to unsigned.
|
||||||
template <typename Int>
|
template <typename Int>
|
||||||
inline typename make_unsigned<Int>::type to_unsigned(Int value) {
|
inline typename std::make_unsigned<Int>::type to_unsigned(Int value) {
|
||||||
FMT_ASSERT(value >= 0, "negative value");
|
FMT_ASSERT(value >= 0, "negative value");
|
||||||
return static_cast<typename make_unsigned<Int>::type>(value);
|
return static_cast<typename std::make_unsigned<Int>::type>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The number of characters to store in the basic_memory_buffer object itself
|
// The number of characters to store in the basic_memory_buffer object itself
|
||||||
|
@ -14,7 +14,7 @@ namespace fmt {
|
|||||||
namespace internal {
|
namespace internal {
|
||||||
FMT_FUNC void write(std::ostream &os, buffer &buf) {
|
FMT_FUNC void write(std::ostream &os, buffer &buf) {
|
||||||
const char *data = buf.data();
|
const char *data = buf.data();
|
||||||
typedef internal::make_unsigned<std::streamsize>::type UnsignedStreamSize;
|
typedef std::make_unsigned<std::streamsize>::type UnsignedStreamSize;
|
||||||
UnsignedStreamSize size = buf.size();
|
UnsignedStreamSize size = buf.size();
|
||||||
UnsignedStreamSize max_size =
|
UnsignedStreamSize max_size =
|
||||||
internal::to_unsigned((std::numeric_limits<std::streamsize>::max)());
|
internal::to_unsigned((std::numeric_limits<std::streamsize>::max)());
|
||||||
|
12
fmt/printf.h
12
fmt/printf.h
@ -70,6 +70,14 @@ class IsZeroInt {
|
|||||||
operator()(T) { return false; }
|
operator()(T) { return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct make_unsigned_or_bool : std::make_unsigned<T> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct make_unsigned_or_bool<bool> {
|
||||||
|
using type = bool;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T, typename Context>
|
template <typename T, typename Context>
|
||||||
class ArgConverter {
|
class ArgConverter {
|
||||||
private:
|
private:
|
||||||
@ -99,7 +107,7 @@ class ArgConverter {
|
|||||||
arg_ = internal::make_arg<Context>(
|
arg_ = internal::make_arg<Context>(
|
||||||
static_cast<int>(static_cast<TargetType>(value)));
|
static_cast<int>(static_cast<TargetType>(value)));
|
||||||
} else {
|
} else {
|
||||||
typedef typename internal::make_unsigned<TargetType>::type Unsigned;
|
typedef typename make_unsigned_or_bool<TargetType>::type Unsigned;
|
||||||
arg_ = internal::make_arg<Context>(
|
arg_ = internal::make_arg<Context>(
|
||||||
static_cast<unsigned>(static_cast<Unsigned>(value)));
|
static_cast<unsigned>(static_cast<Unsigned>(value)));
|
||||||
}
|
}
|
||||||
@ -111,7 +119,7 @@ class ArgConverter {
|
|||||||
arg_ = internal::make_arg<Context>(static_cast<long long>(value));
|
arg_ = internal::make_arg<Context>(static_cast<long long>(value));
|
||||||
} else {
|
} else {
|
||||||
arg_ = internal::make_arg<Context>(
|
arg_ = internal::make_arg<Context>(
|
||||||
static_cast<typename internal::make_unsigned<U>::type>(value));
|
static_cast<typename make_unsigned_or_bool<U>::type>(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
|
|||||||
const char *data = 0;
|
const char *data = 0;
|
||||||
std::size_t size = max_size;
|
std::size_t size = max_size;
|
||||||
do {
|
do {
|
||||||
typedef fmt::internal::make_unsigned<std::streamsize>::type UStreamSize;
|
typedef std::make_unsigned<std::streamsize>::type UStreamSize;
|
||||||
UStreamSize n = std::min<UStreamSize>(
|
UStreamSize n = std::min<UStreamSize>(
|
||||||
size, fmt::internal::to_unsigned(max_streamsize));
|
size, fmt::internal::to_unsigned(max_streamsize));
|
||||||
EXPECT_CALL(streambuf, xsputn(data, static_cast<std::streamsize>(n)))
|
EXPECT_CALL(streambuf, xsputn(data, static_cast<std::streamsize>(n)))
|
||||||
|
@ -306,13 +306,13 @@ void TestLength(const char *length_spec, U value) {
|
|||||||
signed_value = static_cast<unsigned>(value);
|
signed_value = static_cast<unsigned>(value);
|
||||||
unsigned_value = static_cast<unsigned>(value);
|
unsigned_value = static_cast<unsigned>(value);
|
||||||
}
|
}
|
||||||
using fmt::internal::make_unsigned;
|
|
||||||
if (sizeof(U) <= sizeof(int) && sizeof(int) < sizeof(T)) {
|
if (sizeof(U) <= sizeof(int) && sizeof(int) < sizeof(T)) {
|
||||||
signed_value = static_cast<long long>(value);
|
signed_value = static_cast<long long>(value);
|
||||||
unsigned_value = static_cast<typename make_unsigned<unsigned>::type>(value);
|
unsigned_value =
|
||||||
|
static_cast<typename std::make_unsigned<unsigned>::type>(value);
|
||||||
} else {
|
} else {
|
||||||
signed_value = static_cast<typename make_signed<T>::type>(value);
|
signed_value = static_cast<typename make_signed<T>::type>(value);
|
||||||
unsigned_value = static_cast<typename make_unsigned<T>::type>(value);
|
unsigned_value = static_cast<typename std::make_unsigned<T>::type>(value);
|
||||||
}
|
}
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << signed_value;
|
os << signed_value;
|
||||||
|
Reference in New Issue
Block a user