mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-26 12:10:06 +00:00
Remove legacy code
This commit is contained in:
parent
07f8ffc44f
commit
016acebb56
@ -281,10 +281,8 @@ template <typename T>
|
||||
const uint64_t internal::basic_data<T>::POWERS_OF_10_64[] = {
|
||||
0,
|
||||
FMT_POWERS_OF_10(1),
|
||||
FMT_POWERS_OF_10(ulong_long(1000000000)),
|
||||
// Multiply several constants instead of using a single long long constant
|
||||
// to avoid warnings about C++98 not supporting long long.
|
||||
ulong_long(1000000000) * ulong_long(1000000000) * 10
|
||||
FMT_POWERS_OF_10(1000000000ull),
|
||||
10000000000000000000ull
|
||||
};
|
||||
|
||||
FMT_FUNC void internal::report_unknown_type(char code, const char *type) {
|
||||
|
73
fmt/format.h
73
fmt/format.h
@ -41,6 +41,7 @@
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _SECURE_SCL
|
||||
# define FMT_SECURE_SCL _SECURE_SCL
|
||||
@ -52,20 +53,6 @@
|
||||
# include <iterator>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define FMT_MSC_VER _MSC_VER
|
||||
#else
|
||||
# define FMT_MSC_VER 0
|
||||
#endif
|
||||
|
||||
#if FMT_MSC_VER && FMT_MSC_VER <= 1500
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef __int64 intmax_t;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
|
||||
# ifdef FMT_EXPORT
|
||||
# define FMT_API __declspec(dllexport)
|
||||
@ -79,14 +66,9 @@ typedef __int64 intmax_t;
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
||||
# define FMT_GCC_EXTENSION __extension__
|
||||
# if FMT_GCC_VERSION >= 406
|
||||
# pragma GCC diagnostic push
|
||||
|
||||
// Disable the warning about "long long" which is sometimes reported even
|
||||
// when using __extension__.
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
|
||||
// Disable the warning about declaration shadowing because it affects too
|
||||
// many valid cases.
|
||||
# pragma GCC diagnostic ignored "-Wshadow"
|
||||
@ -99,8 +81,6 @@ typedef __int64 intmax_t;
|
||||
# if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__
|
||||
# define FMT_HAS_GXX_CXX11 1
|
||||
# endif
|
||||
#else
|
||||
# define FMT_GCC_EXTENSION
|
||||
#endif
|
||||
|
||||
#if defined(__INTEL_COMPILER)
|
||||
@ -119,6 +99,12 @@ typedef __int64 intmax_t;
|
||||
# define FMT_GNUC_LIBSTD_VERSION (__GNUC_LIBSTD__ * 100 + __GNUC_LIBSTD_MINOR__)
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define FMT_MSC_VER _MSC_VER
|
||||
#else
|
||||
# define FMT_MSC_VER 0
|
||||
#endif
|
||||
|
||||
#ifdef __has_feature
|
||||
# define FMT_HAS_FEATURE(x) __has_feature(x)
|
||||
#else
|
||||
@ -368,11 +354,6 @@ class numeric_limits<fmt::internal::dummy_int> :
|
||||
|
||||
namespace fmt {
|
||||
|
||||
// Fix the warning about long long on older versions of GCC
|
||||
// that don't support the diagnostic pragma.
|
||||
FMT_GCC_EXTENSION typedef long long long_long;
|
||||
FMT_GCC_EXTENSION typedef unsigned long long ulong_long;
|
||||
|
||||
#if FMT_USE_RVALUE_REFERENCES
|
||||
using std::move;
|
||||
#endif
|
||||
@ -523,7 +504,7 @@ 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, ulong_long);
|
||||
FMT_SPECIALIZE_MAKE_UNSIGNED(long long, unsigned long long);
|
||||
|
||||
// Casts nonnegative integer to unsigned.
|
||||
template <typename Int>
|
||||
@ -1168,7 +1149,7 @@ typedef char no[2];
|
||||
template <typename T>
|
||||
T &get();
|
||||
|
||||
yes &convert(fmt::ulong_long);
|
||||
yes &convert(unsigned long long);
|
||||
no &convert(...);
|
||||
|
||||
template<typename T, bool ENABLE_CONVERSION>
|
||||
@ -1267,8 +1248,8 @@ template <> constexpr Type gettype<unsigned long>() {
|
||||
return sizeof(unsigned long) == sizeof(unsigned) ?
|
||||
UINT : ULONG_LONG;
|
||||
}
|
||||
template <> constexpr Type gettype<long_long>() { return LONG_LONG; }
|
||||
template <> constexpr Type gettype<ulong_long>() { return ULONG_LONG; }
|
||||
template <> constexpr Type gettype<long long>() { return LONG_LONG; }
|
||||
template <> constexpr Type gettype<unsigned long long>() { return ULONG_LONG; }
|
||||
template <> constexpr Type gettype<float>() { return DOUBLE; }
|
||||
template <> constexpr Type gettype<double>() { return DOUBLE; }
|
||||
template <> constexpr Type gettype<long double>() { return LONG_DOUBLE; }
|
||||
@ -1305,8 +1286,8 @@ class value {
|
||||
union {
|
||||
int int_value;
|
||||
unsigned uint_value;
|
||||
long_long long_long_value;
|
||||
ulong_long ulong_long_value;
|
||||
long long long_long_value;
|
||||
unsigned long long ulong_long_value;
|
||||
double double_value;
|
||||
long double long_double_value;
|
||||
const void *pointer;
|
||||
@ -1401,8 +1382,8 @@ class value {
|
||||
this->ulong_long_value = value;
|
||||
}
|
||||
|
||||
FMT_MAKE_VALUE(long_long, long_long_value, LONG_LONG)
|
||||
FMT_MAKE_VALUE(ulong_long, ulong_long_value, ULONG_LONG)
|
||||
FMT_MAKE_VALUE(long long, long_long_value, LONG_LONG)
|
||||
FMT_MAKE_VALUE(unsigned long long, ulong_long_value, ULONG_LONG)
|
||||
FMT_MAKE_VALUE(float, double_value, DOUBLE)
|
||||
FMT_MAKE_VALUE(double, double_value, DOUBLE)
|
||||
FMT_MAKE_VALUE(long double, long_double_value, LONG_DOUBLE)
|
||||
@ -2437,7 +2418,7 @@ class basic_writer {
|
||||
void write(long value) {
|
||||
write_decimal(value);
|
||||
}
|
||||
void write(long_long value) {
|
||||
void write(long long value) {
|
||||
write_decimal(value);
|
||||
}
|
||||
|
||||
@ -3039,12 +3020,12 @@ class FormatInt {
|
||||
private:
|
||||
// Buffer should be large enough to hold all digits (digits10 + 1),
|
||||
// a sign and a null character.
|
||||
enum {BUFFER_SIZE = std::numeric_limits<ulong_long>::digits10 + 3};
|
||||
enum {BUFFER_SIZE = std::numeric_limits<unsigned long long>::digits10 + 3};
|
||||
mutable char buffer_[BUFFER_SIZE];
|
||||
char *str_;
|
||||
|
||||
// Formats value in reverse and returns the number of digits.
|
||||
char *format_decimal(ulong_long value) {
|
||||
char *format_decimal(unsigned long long value) {
|
||||
char *buffer_end = buffer_ + BUFFER_SIZE - 1;
|
||||
while (value >= 100) {
|
||||
// Integer division is slow so do it for a group of two digits instead
|
||||
@ -3065,8 +3046,8 @@ class FormatInt {
|
||||
return buffer_end;
|
||||
}
|
||||
|
||||
void FormatSigned(long_long value) {
|
||||
ulong_long abs_value = static_cast<ulong_long>(value);
|
||||
void FormatSigned(long long value) {
|
||||
unsigned long long abs_value = static_cast<unsigned long long>(value);
|
||||
bool negative = value < 0;
|
||||
if (negative)
|
||||
abs_value = 0 - abs_value;
|
||||
@ -3078,10 +3059,10 @@ class FormatInt {
|
||||
public:
|
||||
explicit FormatInt(int value) { FormatSigned(value); }
|
||||
explicit FormatInt(long value) { FormatSigned(value); }
|
||||
explicit FormatInt(long_long value) { FormatSigned(value); }
|
||||
explicit FormatInt(long long value) { FormatSigned(value); }
|
||||
explicit FormatInt(unsigned value) : str_(format_decimal(value)) {}
|
||||
explicit FormatInt(unsigned long value) : str_(format_decimal(value)) {}
|
||||
explicit FormatInt(ulong_long value) : str_(format_decimal(value)) {}
|
||||
explicit FormatInt(unsigned long long value) : str_(format_decimal(value)) {}
|
||||
|
||||
/** Returns the number of characters written to the output buffer. */
|
||||
std::size_t size() const {
|
||||
@ -3246,7 +3227,7 @@ struct is_integer {
|
||||
|
||||
struct width_handler {
|
||||
template <typename T>
|
||||
typename std::enable_if<is_integer<T>::value, ulong_long>::type
|
||||
typename std::enable_if<is_integer<T>::value, unsigned long long>::type
|
||||
operator()(T value) {
|
||||
if (is_negative(value))
|
||||
FMT_THROW(format_error("negative width"));
|
||||
@ -3254,7 +3235,7 @@ struct width_handler {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<!is_integer<T>::value, ulong_long>::type
|
||||
typename std::enable_if<!is_integer<T>::value, unsigned long long>::type
|
||||
operator()(T value) {
|
||||
FMT_THROW(format_error("width is not integer"));
|
||||
return 0;
|
||||
@ -3263,7 +3244,7 @@ struct width_handler {
|
||||
|
||||
struct precision_handler {
|
||||
template <typename T>
|
||||
typename std::enable_if<is_integer<T>::value, ulong_long>::type
|
||||
typename std::enable_if<is_integer<T>::value, unsigned long long>::type
|
||||
operator()(T value) {
|
||||
if (is_negative(value))
|
||||
FMT_THROW(format_error("negative precision"));
|
||||
@ -3271,7 +3252,7 @@ struct precision_handler {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<!is_integer<T>::value, ulong_long>::type
|
||||
typename std::enable_if<!is_integer<T>::value, unsigned long long>::type
|
||||
operator()(T value) {
|
||||
FMT_THROW(format_error("precision is not integer"));
|
||||
return 0;
|
||||
@ -3308,7 +3289,7 @@ class specs_handler_base {
|
||||
|
||||
template <typename Handler, typename T, typename Context>
|
||||
inline void set_dynamic_spec(T &value, basic_arg<Context> arg) {
|
||||
ulong_long big_value = visit(Handler(), arg);
|
||||
unsigned long long big_value = visit(Handler(), arg);
|
||||
if (big_value > (std::numeric_limits<int>::max)())
|
||||
FMT_THROW(format_error("number is too big"));
|
||||
value = static_cast<int>(big_value);
|
||||
|
@ -124,7 +124,7 @@ void fmt::File::close() {
|
||||
throw system_error(errno, "cannot close file");
|
||||
}
|
||||
|
||||
fmt::long_long fmt::File::size() const {
|
||||
long long fmt::File::size() const {
|
||||
#ifdef _WIN32
|
||||
// Use GetFileSize instead of GetFileSizeEx for the case when _WIN32_WINNT
|
||||
// is less than 0x0500 as is the case with some default MinGW builds.
|
||||
@ -137,14 +137,14 @@ fmt::long_long fmt::File::size() const {
|
||||
if (error != NO_ERROR)
|
||||
throw windows_error(GetLastError(), "cannot get file size");
|
||||
}
|
||||
fmt::ulong_long long_size = size_upper;
|
||||
unsigned long long long_size = size_upper;
|
||||
return (long_size << sizeof(DWORD) * CHAR_BIT) | size_lower;
|
||||
#else
|
||||
typedef struct stat Stat;
|
||||
Stat file_stat = Stat();
|
||||
if (FMT_POSIX_CALL(fstat(fd_, &file_stat)) == -1)
|
||||
throw system_error(errno, "cannot get file attributes");
|
||||
FMT_STATIC_ASSERT(sizeof(fmt::long_long) >= sizeof(file_stat.st_size),
|
||||
FMT_STATIC_ASSERT(sizeof(long long) >= sizeof(file_stat.st_size),
|
||||
"return type of File::size is not large enough");
|
||||
return file_stat.st_size;
|
||||
#endif
|
||||
|
@ -322,7 +322,7 @@ class File {
|
||||
|
||||
// Returns the file size. The size has signed type for consistency with
|
||||
// stat::st_size.
|
||||
long_long size() const;
|
||||
long long size() const;
|
||||
|
||||
// Attempts to read count bytes from the file into the specified buffer.
|
||||
std::size_t read(void *buffer, std::size_t count);
|
||||
|
@ -119,7 +119,7 @@ class ArgConverter {
|
||||
// glibc's printf doesn't sign extend arguments of smaller types:
|
||||
// std::printf("%lld", -42); // prints "4294967254"
|
||||
// but we don't have to do the same because it's a UB.
|
||||
arg_ = internal::make_arg<Context>(static_cast<long_long>(value));
|
||||
arg_ = internal::make_arg<Context>(static_cast<long long>(value));
|
||||
} else {
|
||||
arg_ = internal::make_arg<Context>(
|
||||
static_cast<typename internal::make_unsigned<U>::type>(value));
|
||||
@ -486,7 +486,7 @@ void printf_context<Char, AF>::format(
|
||||
break;
|
||||
case 'l':
|
||||
if (*it == 'l')
|
||||
convert_arg<fmt::long_long>(arg, *++it);
|
||||
convert_arg<long long>(arg, *++it);
|
||||
else
|
||||
convert_arg<long>(arg, *it);
|
||||
break;
|
||||
|
@ -56,11 +56,10 @@ struct ValueExtractor {
|
||||
};
|
||||
|
||||
TEST(FormatTest, ArgConverter) {
|
||||
fmt::long_long value = std::numeric_limits<fmt::long_long>::max();
|
||||
long long value = std::numeric_limits<long long>::max();
|
||||
auto arg = fmt::internal::make_arg<fmt::context>(value);
|
||||
visit(fmt::internal::ArgConverter<
|
||||
fmt::long_long, fmt::context>(arg, 'd'), arg);
|
||||
EXPECT_EQ(value, visit(ValueExtractor<fmt::long_long>(), arg));
|
||||
visit(fmt::internal::ArgConverter<long long, fmt::context>(arg, 'd'), arg);
|
||||
EXPECT_EQ(value, visit(ValueExtractor<long long>(), arg));
|
||||
}
|
||||
|
||||
TEST(FormatTest, FormatNegativeNaN) {
|
||||
|
@ -277,7 +277,7 @@ TEST(FileTest, Size) {
|
||||
write_file("test", content);
|
||||
File f("test", File::RDONLY);
|
||||
EXPECT_GE(f.size(), 0);
|
||||
EXPECT_EQ(content.size(), static_cast<fmt::ulong_long>(f.size()));
|
||||
EXPECT_EQ(content.size(), static_cast<unsigned long long>(f.size()));
|
||||
#ifdef _WIN32
|
||||
fmt::memory_buffer message;
|
||||
fmt::internal::format_windows_error(
|
||||
|
@ -269,8 +269,8 @@ TEST(PrintfTest, DynamicPrecision) {
|
||||
"argument index out of range");
|
||||
EXPECT_THROW_MSG(fmt::sprintf("%.*d", BIG_NUM, 42), format_error,
|
||||
"number is too big");
|
||||
if (sizeof(fmt::long_long) != sizeof(int)) {
|
||||
fmt::long_long prec = static_cast<fmt::long_long>(INT_MIN) - 1;
|
||||
if (sizeof(long long) != sizeof(int)) {
|
||||
long long prec = static_cast<long long>(INT_MIN) - 1;
|
||||
EXPECT_THROW_MSG(fmt::sprintf("%.*d", prec, 42), format_error,
|
||||
"number is too big");
|
||||
}
|
||||
@ -288,16 +288,16 @@ SPECIALIZE_MAKE_SIGNED(unsigned char, signed char);
|
||||
SPECIALIZE_MAKE_SIGNED(unsigned short, short);
|
||||
SPECIALIZE_MAKE_SIGNED(unsigned, int);
|
||||
SPECIALIZE_MAKE_SIGNED(unsigned long, long);
|
||||
SPECIALIZE_MAKE_SIGNED(fmt::ulong_long, fmt::long_long);
|
||||
SPECIALIZE_MAKE_SIGNED(unsigned long long, long long);
|
||||
|
||||
// Test length format specifier ``length_spec``.
|
||||
template <typename T, typename U>
|
||||
void TestLength(const char *length_spec, U value) {
|
||||
fmt::long_long signed_value = 0;
|
||||
fmt::ulong_long unsigned_value = 0;
|
||||
long long signed_value = 0;
|
||||
unsigned long long unsigned_value = 0;
|
||||
// Apply integer promotion to the argument.
|
||||
using std::numeric_limits;
|
||||
fmt::ulong_long max = numeric_limits<U>::max();
|
||||
unsigned long long max = numeric_limits<U>::max();
|
||||
using fmt::internal::const_check;
|
||||
if (const_check(max <= static_cast<unsigned>(numeric_limits<int>::max()))) {
|
||||
signed_value = static_cast<int>(value);
|
||||
@ -308,7 +308,7 @@ void TestLength(const char *length_spec, U value) {
|
||||
}
|
||||
using fmt::internal::make_unsigned;
|
||||
if (sizeof(U) <= sizeof(int) && sizeof(int) < sizeof(T)) {
|
||||
signed_value = static_cast<fmt::long_long>(value);
|
||||
signed_value = static_cast<long long>(value);
|
||||
unsigned_value = static_cast<typename make_unsigned<unsigned>::type>(value);
|
||||
} else {
|
||||
signed_value = static_cast<typename make_signed<T>::type>(value);
|
||||
@ -339,20 +339,20 @@ void TestLength(const char *length_spec) {
|
||||
TestLength<T>(length_spec, -42);
|
||||
TestLength<T>(length_spec, min);
|
||||
TestLength<T>(length_spec, max);
|
||||
TestLength<T>(length_spec, fmt::long_long(min) - 1);
|
||||
fmt::ulong_long long_long_max = std::numeric_limits<fmt::long_long>::max();
|
||||
if (static_cast<fmt::ulong_long>(max) < long_long_max)
|
||||
TestLength<T>(length_spec, fmt::long_long(max) + 1);
|
||||
TestLength<T>(length_spec, static_cast<long long>(min) - 1);
|
||||
unsigned long long long_long_max = std::numeric_limits<long long>::max();
|
||||
if (static_cast<unsigned long long>(max) < long_long_max)
|
||||
TestLength<T>(length_spec, static_cast<long long>(max) + 1);
|
||||
TestLength<T>(length_spec, std::numeric_limits<short>::min());
|
||||
TestLength<T>(length_spec, std::numeric_limits<unsigned short>::max());
|
||||
TestLength<T>(length_spec, std::numeric_limits<int>::min());
|
||||
TestLength<T>(length_spec, std::numeric_limits<int>::max());
|
||||
TestLength<T>(length_spec, std::numeric_limits<unsigned>::min());
|
||||
TestLength<T>(length_spec, std::numeric_limits<unsigned>::max());
|
||||
TestLength<T>(length_spec, std::numeric_limits<fmt::long_long>::min());
|
||||
TestLength<T>(length_spec, std::numeric_limits<fmt::long_long>::max());
|
||||
TestLength<T>(length_spec, std::numeric_limits<fmt::ulong_long>::min());
|
||||
TestLength<T>(length_spec, std::numeric_limits<fmt::ulong_long>::max());
|
||||
TestLength<T>(length_spec, std::numeric_limits<long long>::min());
|
||||
TestLength<T>(length_spec, std::numeric_limits<long long>::max());
|
||||
TestLength<T>(length_spec, std::numeric_limits<unsigned long long>::min());
|
||||
TestLength<T>(length_spec, std::numeric_limits<unsigned long long>::max());
|
||||
}
|
||||
|
||||
TEST(PrintfTest, Length) {
|
||||
@ -363,8 +363,8 @@ TEST(PrintfTest, Length) {
|
||||
TestLength<unsigned short>("h");
|
||||
TestLength<long>("l");
|
||||
TestLength<unsigned long>("l");
|
||||
TestLength<fmt::long_long>("ll");
|
||||
TestLength<fmt::ulong_long>("ll");
|
||||
TestLength<long long>("ll");
|
||||
TestLength<unsigned long long>("ll");
|
||||
TestLength<intmax_t>("j");
|
||||
TestLength<std::size_t>("z");
|
||||
TestLength<std::ptrdiff_t>("t");
|
||||
@ -391,7 +391,7 @@ TEST(PrintfTest, Int) {
|
||||
TEST(PrintfTest, long_long) {
|
||||
// fmt::printf allows passing long long arguments to %d without length
|
||||
// specifiers.
|
||||
fmt::long_long max = std::numeric_limits<fmt::long_long>::max();
|
||||
long long max = std::numeric_limits<long long>::max();
|
||||
EXPECT_PRINTF(fmt::format("{}", max), "%d", max);
|
||||
}
|
||||
|
||||
|
@ -510,8 +510,8 @@ VISIT_TYPE(unsigned short, unsigned);
|
||||
VISIT_TYPE(long, int);
|
||||
VISIT_TYPE(unsigned long, unsigned);
|
||||
#else
|
||||
VISIT_TYPE(long, fmt::long_long);
|
||||
VISIT_TYPE(unsigned long, fmt::ulong_long);
|
||||
VISIT_TYPE(long, long long);
|
||||
VISIT_TYPE(unsigned long, unsigned long long);
|
||||
#endif
|
||||
|
||||
VISIT_TYPE(float, double);
|
||||
@ -533,7 +533,7 @@ class NumericArgTest : public testing::Test {};
|
||||
|
||||
typedef ::testing::Types<
|
||||
bool, signed char, unsigned char, signed, unsigned short,
|
||||
int, unsigned, long, unsigned long, fmt::long_long, fmt::ulong_long,
|
||||
int, unsigned, long, unsigned long, long long, unsigned long long,
|
||||
float, double, long double> Types;
|
||||
TYPED_TEST_CASE(NumericArgTest, Types);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user