diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 6faf3e066f2d..42d2e1034062 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -387,13 +387,13 @@ inline std::tm gmtime(std::time_t time) { } namespace internal { -inline std::size_t strftime(char* str, std::size_t count, const char* format, - const std::tm* time) { +inline size_t strftime(char* str, size_t count, const char* format, + const std::tm* time) { return std::strftime(str, count, format, time); } -inline std::size_t strftime(wchar_t* str, std::size_t count, - const wchar_t* format, const std::tm* time) { +inline size_t strftime(wchar_t* str, size_t count, const wchar_t* format, + const std::tm* time) { return std::wcsftime(str, count, format, time); } } // namespace internal @@ -414,11 +414,10 @@ template struct formatter { template auto format(const std::tm& tm, FormatContext& ctx) -> decltype(ctx.out()) { basic_memory_buffer buf; - std::size_t start = buf.size(); + size_t start = buf.size(); for (;;) { - std::size_t size = buf.capacity() - start; - std::size_t count = - internal::strftime(&buf[start], size, &tm_format[0], &tm); + size_t size = buf.capacity() - start; + size_t count = internal::strftime(&buf[start], size, &tm_format[0], &tm); if (count != 0) { buf.resize(start + count); break; @@ -430,7 +429,7 @@ template struct formatter { // https://github.com/fmtlib/fmt/issues/367 break; } - const std::size_t MIN_GROWTH = 10; + const size_t MIN_GROWTH = 10; buf.reserve(buf.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH)); } return std::copy(buf.begin(), buf.end(), ctx.out()); diff --git a/include/fmt/color.h b/include/fmt/color.h index 96d9ab6b4382..9dfabdff4024 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -364,7 +364,7 @@ template struct ansi_color_escape { // 10 more. if (is_background) value += 10u; - std::size_t index = 0; + size_t index = 0; buffer[index++] = static_cast('\x1b'); buffer[index++] = static_cast('['); @@ -398,7 +398,7 @@ template struct ansi_color_escape { if (em_bits & static_cast(emphasis::strikethrough)) em_codes[3] = 9; - std::size_t index = 0; + size_t index = 0; for (int i = 0; i < 4; ++i) { if (!em_codes[i]) continue; buffer[index++] = static_cast('\x1b'); diff --git a/include/fmt/compile.h b/include/fmt/compile.h index ed4795d85b28..0cc18b9093cd 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -586,7 +586,7 @@ format_to_n_result format_to_n(OutputIt out, size_t n, } template -std::size_t formatted_size(const CompiledFormat& cf, const Args&... args) { +size_t formatted_size(const CompiledFormat& cf, const Args&... args) { return format_to(internal::counting_iterator(), cf, args...).count(); } diff --git a/include/fmt/core.h b/include/fmt/core.h index 0c2eaeea1e43..b6e36d4859f3 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -630,27 +630,27 @@ namespace internal { template class buffer { private: T* ptr_; - std::size_t size_; - std::size_t capacity_; + size_t size_; + size_t capacity_; protected: // Don't initialize ptr_ since it is not accessed to save a few cycles. FMT_SUPPRESS_MSC_WARNING(26495) - buffer(std::size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {} + buffer(size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {} - buffer(T* p = nullptr, std::size_t sz = 0, std::size_t cap = 0) FMT_NOEXCEPT + buffer(T* p = nullptr, size_t sz = 0, size_t cap = 0) FMT_NOEXCEPT : ptr_(p), size_(sz), capacity_(cap) {} /** Sets the buffer data and capacity. */ - void set(T* buf_data, std::size_t buf_capacity) FMT_NOEXCEPT { + void set(T* buf_data, size_t buf_capacity) FMT_NOEXCEPT { ptr_ = buf_data; capacity_ = buf_capacity; } /** Increases the buffer capacity to hold at least *capacity* elements. */ - virtual void grow(std::size_t capacity) = 0; + virtual void grow(size_t capacity) = 0; public: using value_type = T; @@ -667,10 +667,10 @@ template class buffer { const T* end() const FMT_NOEXCEPT { return ptr_ + size_; } /** Returns the size of this buffer. */ - std::size_t size() const FMT_NOEXCEPT { return size_; } + size_t size() const FMT_NOEXCEPT { return size_; } /** Returns the capacity of this buffer. */ - std::size_t capacity() const FMT_NOEXCEPT { return capacity_; } + size_t capacity() const FMT_NOEXCEPT { return capacity_; } /** Returns a pointer to the buffer data. */ T* data() FMT_NOEXCEPT { return ptr_; } @@ -681,7 +681,7 @@ template class buffer { /** Resizes the buffer. If T is a POD type new elements may not be initialized. */ - void resize(std::size_t new_size) { + void resize(size_t new_size) { reserve(new_size); size_ = new_size; } @@ -690,7 +690,7 @@ template class buffer { void clear() { size_ = 0; } /** Reserves space to store at least *capacity* elements. */ - void reserve(std::size_t new_capacity) { + void reserve(size_t new_capacity) { if (new_capacity > capacity_) grow(new_capacity); } @@ -715,7 +715,7 @@ class container_buffer : public buffer { Container& container_; protected: - void grow(std::size_t capacity) FMT_OVERRIDE { + void grow(size_t capacity) FMT_OVERRIDE { container_.resize(capacity); this->set(&container_[0], capacity); } @@ -869,12 +869,12 @@ constexpr bool is_arithmetic_type(type t) { template struct string_value { const Char* data; - std::size_t size; + size_t size; }; template struct named_arg_value { const named_arg_info* data; - std::size_t size; + size_t size; }; template struct custom_value { diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 4472768ba0a5..e78bf0679dda 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -41,7 +41,7 @@ // Dummy implementations of strerror_r and strerror_s called if corresponding // system functions are not available. inline fmt::internal::null<> strerror_r(int, char*, ...) { return {}; } -inline fmt::internal::null<> strerror_s(char*, std::size_t, ...) { return {}; } +inline fmt::internal::null<> strerror_s(char*, size_t, ...) { return {}; } FMT_BEGIN_NAMESPACE namespace internal { @@ -76,14 +76,14 @@ inline int fmt_snprintf(char* buffer, size_t size, const char* format, ...) { // other - failure // Buffer should be at least of size 1. FMT_FUNC int safe_strerror(int error_code, char*& buffer, - std::size_t buffer_size) FMT_NOEXCEPT { + size_t buffer_size) FMT_NOEXCEPT { FMT_ASSERT(buffer != nullptr && buffer_size != 0, "invalid buffer"); class dispatcher { private: int error_code_; char*& buffer_; - std::size_t buffer_size_; + size_t buffer_size_; // A noop assignment operator to avoid bogus warnings. void operator=(const dispatcher&) {} @@ -128,7 +128,7 @@ FMT_FUNC int safe_strerror(int error_code, char*& buffer, #endif public: - dispatcher(int err_code, char*& buf, std::size_t buf_size) + dispatcher(int err_code, char*& buf, size_t buf_size) : error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {} int run() { return handle(strerror_r(error_code_, buffer_, buffer_size_)); } @@ -145,7 +145,7 @@ FMT_FUNC void format_error_code(internal::buffer& out, int error_code, static const char SEP[] = ": "; static const char ERROR_STR[] = "error "; // Subtract 2 to account for terminating null characters in SEP and ERROR_STR. - std::size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2; + size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2; auto abs_value = static_cast>(error_code); if (internal::is_negative(error_code)) { abs_value = 0 - abs_value; diff --git a/include/fmt/format.h b/include/fmt/format.h index 832ad2eb6f50..5e938c31682a 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -337,12 +337,12 @@ inline typename Container::value_type* get_data(Container& c) { #if defined(_SECURE_SCL) && _SECURE_SCL // Make a checked iterator to avoid MSVC warnings. template using checked_ptr = stdext::checked_array_iterator; -template checked_ptr make_checked(T* p, std::size_t size) { +template checked_ptr make_checked(T* p, size_t size) { return {p, size}; } #else template using checked_ptr = T*; -template inline T* make_checked(T* p, std::size_t) { return p; } +template inline T* make_checked(T* p, size_t) { return p; } #endif template ::value)> @@ -350,15 +350,14 @@ template ::value)> __attribute__((no_sanitize("undefined"))) #endif inline checked_ptr -reserve(std::back_insert_iterator it, std::size_t n) { +reserve(std::back_insert_iterator it, size_t n) { Container& c = get_container(it); - std::size_t size = c.size(); + size_t size = c.size(); c.resize(size + n); return make_checked(get_data(c) + size, n); } -template -inline Iterator& reserve(Iterator& it, std::size_t) { +template inline Iterator& reserve(Iterator& it, size_t) { return it; } @@ -378,7 +377,7 @@ inline Iterator base_iterator(Iterator, Iterator it) { // discards them. class counting_iterator { private: - std::size_t count_; + size_t count_; public: using iterator_category = std::output_iterator_tag; @@ -393,7 +392,7 @@ class counting_iterator { counting_iterator() : count_(0) {} - std::size_t count() const { return count_; } + size_t count() const { return count_; } counting_iterator& operator++() { ++count_; @@ -412,10 +411,10 @@ class counting_iterator { template class truncating_iterator_base { protected: OutputIt out_; - std::size_t limit_; - std::size_t count_; + size_t limit_; + size_t count_; - truncating_iterator_base(OutputIt out, std::size_t limit) + truncating_iterator_base(OutputIt out, size_t limit) : out_(out), limit_(limit), count_(0) {} public: @@ -428,7 +427,7 @@ template class truncating_iterator_base { truncating_iterator_base; // Mark iterator as checked. OutputIt base() const { return out_; } - std::size_t count() const { return count_; } + size_t count() const { return count_; } }; // An output iterator that truncates the output and counts the number of objects @@ -446,7 +445,7 @@ class truncating_iterator public: using value_type = typename truncating_iterator_base::value_type; - truncating_iterator(OutputIt out, std::size_t limit) + truncating_iterator(OutputIt out, size_t limit) : truncating_iterator_base(out, limit) {} truncating_iterator& operator++() { @@ -469,7 +468,7 @@ template class truncating_iterator : public truncating_iterator_base { public: - truncating_iterator(OutputIt out, std::size_t limit) + truncating_iterator(OutputIt out, size_t limit) : truncating_iterator_base(out, limit) {} template truncating_iterator& operator=(T val) { @@ -568,7 +567,7 @@ template constexpr bool use_grisu() { template template void buffer::append(const U* begin, const U* end) { - std::size_t new_size = size_ + to_unsigned(end - begin); + size_t new_size = size_ + to_unsigned(end - begin); reserve(new_size); std::uninitialized_copy(begin, end, make_checked(ptr_, capacity_) + size_); size_ = new_size; @@ -619,7 +618,7 @@ enum { inline_buffer_size = 500 }; The output can be converted to an ``std::string`` with ``to_string(out)``. \endrst */ -template > class basic_memory_buffer : public internal::buffer { private: @@ -635,7 +634,7 @@ class basic_memory_buffer : public internal::buffer { } protected: - void grow(std::size_t size) FMT_OVERRIDE; + void grow(size_t size) FMT_OVERRIDE; public: using value_type = T; @@ -652,7 +651,7 @@ class basic_memory_buffer : public internal::buffer { void move(basic_memory_buffer& other) { alloc_ = std::move(other.alloc_); T* data = other.data(); - std::size_t size = other.size(), capacity = other.capacity(); + size_t size = other.size(), capacity = other.capacity(); if (data == other.store_) { this->set(store_, capacity); std::uninitialized_copy(other.store_, other.store_ + size, @@ -691,13 +690,13 @@ class basic_memory_buffer : public internal::buffer { Allocator get_allocator() const { return alloc_; } }; -template -void basic_memory_buffer::grow(std::size_t size) { +template +void basic_memory_buffer::grow(size_t size) { #ifdef FMT_FUZZ if (size > 5000) throw std::runtime_error("fuzz mode - won't grow that much"); #endif - std::size_t old_capacity = this->capacity(); - std::size_t new_capacity = old_capacity + old_capacity / 2; + size_t old_capacity = this->capacity(); + size_t new_capacity = old_capacity + old_capacity / 2; if (size > new_capacity) new_capacity = size; T* old_data = this->data(); T* new_data = @@ -1397,8 +1396,8 @@ inline OutputIt write_padded(OutputIt out, // Data for write_int that doesn't depend on output iterator type. It is used to // avoid template code bloat. template struct write_int_data { - std::size_t size; - std::size_t padding; + size_t size; + size_t padding; write_int_data(int num_digits, string_view prefix, const basic_format_specs& specs) @@ -1685,7 +1684,7 @@ class arg_formatter_base { // Attempts to reserve space for n extra characters in the output range. // Returns a pointer to the reserved range or a reference to out_. - auto reserve(std::size_t n) -> decltype(internal::reserve(out_, n)) { + auto reserve(size_t n) -> decltype(internal::reserve(out_, n)) { return internal::reserve(out_, n); } @@ -1764,7 +1763,7 @@ class arg_formatter_base { } template - void write(const Char* s, std::size_t size, const format_specs& specs) { + void write(const Char* s, size_t size, const format_specs& specs) { auto width = specs.width != 0 ? count_code_points(basic_string_view(s, size)) : 0; @@ -2868,7 +2867,7 @@ class format_int { explicit format_int(unsigned long long value) : str_(format_decimal(value)) {} /** Returns the number of characters written to the output buffer. */ - std::size_t size() const { + size_t size() const { return internal::to_unsigned(buffer_ - str_ + buffer_size - 1); } @@ -3302,7 +3301,7 @@ template inline std::wstring to_wstring(const T& value) { return format(L"{}", value); } -template +template std::basic_string to_string(const basic_memory_buffer& buf) { return std::basic_string(buf.data(), buf.size()); } @@ -3351,7 +3350,7 @@ inline typename buffer_context::iterator vformat_to( return internal::vformat_to(buf, to_string_view(format_str), args); } -template ::value, char_t>> inline typename buffer_context::iterator format_to( basic_memory_buffer& buf, const S& format_str, Args&&... args) { @@ -3406,7 +3405,7 @@ template struct format_to_n_result { /** Iterator past the end of the output range. */ OutputIt out; /** Total (not truncated) output size. */ - std::size_t size; + size_t size; }; template @@ -3426,7 +3425,7 @@ make_format_to_n_args(const Args&... args) { template ::value)> inline format_to_n_result vformat_to_n( - OutputIt out, std::size_t n, basic_string_view format_str, + OutputIt out, size_t n, basic_string_view format_str, format_to_n_args, type_identity_t> args) { auto it = vformat_to(internal::truncating_iterator(out, n), format_str, args); @@ -3443,7 +3442,7 @@ inline format_to_n_result vformat_to_n( template ::value&& internal::is_output_iterator::value)> -inline format_to_n_result format_to_n(OutputIt out, std::size_t n, +inline format_to_n_result format_to_n(OutputIt out, size_t n, const S& format_str, const Args&... args) { internal::check_format_string(format_str); @@ -3466,7 +3465,7 @@ std::basic_string internal::vformat( ``format(format_str, args...)``. */ template -inline std::size_t formatted_size(string_view format_str, const Args&... args) { +inline size_t formatted_size(string_view format_str, const Args&... args) { return format_to(internal::counting_iterator(), format_str, args...).count(); } @@ -3542,11 +3541,11 @@ FMT_CONSTEXPR internal::udl_formatter operator""_format() { \endrst */ FMT_CONSTEXPR internal::udl_formatter operator"" _format(const char* s, - std::size_t n) { + size_t n) { return {{s, n}}; } FMT_CONSTEXPR internal::udl_formatter operator"" _format( - const wchar_t* s, std::size_t n) { + const wchar_t* s, size_t n) { return {{s, n}}; } # endif // FMT_USE_UDL_TEMPLATE @@ -3561,12 +3560,11 @@ FMT_CONSTEXPR internal::udl_formatter operator"" _format( fmt::print("Elapsed time: {s:.2f} seconds", "s"_a=1.23); \endrst */ -FMT_CONSTEXPR internal::udl_arg operator"" _a(const char* s, - std::size_t) { +FMT_CONSTEXPR internal::udl_arg operator"" _a(const char* s, size_t) { return {s}; } FMT_CONSTEXPR internal::udl_arg operator"" _a(const wchar_t* s, - std::size_t) { + size_t) { return {s}; } } // namespace literals diff --git a/include/fmt/os.h b/include/fmt/os.h index a1a0d03b6352..a9c1b7d89462 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -313,10 +313,10 @@ class file { FMT_API long long size() const; // Attempts to read count bytes from the file into the specified buffer. - FMT_API std::size_t read(void* buffer, std::size_t count); + FMT_API size_t read(void* buffer, size_t count); // Attempts to write count bytes from the specified buffer to the file. - FMT_API std::size_t write(const void* buffer, std::size_t count); + FMT_API size_t write(const void* buffer, size_t count); // Duplicates a file descriptor with the dup function and returns // the duplicate as a file object. diff --git a/include/fmt/posix.h b/include/fmt/posix.h index 0e7bc646e072..da19e9d530c9 100644 --- a/include/fmt/posix.h +++ b/include/fmt/posix.h @@ -1,2 +1,2 @@ #include "os.h" -#warning "fmt/posix.h is deprecated; use fmt/os.h instead" \ No newline at end of file +#warning "fmt/posix.h is deprecated; use fmt/os.h instead" diff --git a/include/fmt/printf.h b/include/fmt/printf.h index a3f087d4cd02..3d80e90c302b 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -508,7 +508,8 @@ OutputIt basic_printf_context::format() { auto str_end = str + specs.precision; auto nul = std::find(str, str_end, Char()); arg = internal::make_arg(basic_string_view( - str, internal::to_unsigned(nul != str_end ? nul - str : specs.precision))); + str, + internal::to_unsigned(nul != str_end ? nul - str : specs.precision))); } if (specs.alt && visit_format_arg(internal::is_zero_int(), arg)) specs.alt = false; @@ -546,7 +547,7 @@ OutputIt basic_printf_context::format() { convert_arg(arg, t); break; case 'z': - convert_arg(arg, t); + convert_arg(arg, t); break; case 't': convert_arg(arg, t); @@ -651,7 +652,7 @@ inline int vfprintf( basic_format_args>> args) { basic_memory_buffer buffer; vprintf(buffer, to_string_view(format), args); - std::size_t size = buffer.size(); + size_t size = buffer.size(); return std::fwrite(buffer.data(), sizeof(Char), size, f) < size ? -1 : static_cast(size); diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index f8f9adb715cd..2faf3b262cea 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -33,7 +33,7 @@ template struct formatting_base { template struct formatting_range : formatting_base { - static FMT_CONSTEXPR_DECL const std::size_t range_length_limit = + static FMT_CONSTEXPR_DECL const size_t range_length_limit = FMT_RANGE_OUTPUT_LENGTH_LIMIT; // output only up to N items from the // range. Char prefix; @@ -118,26 +118,24 @@ template class is_tuple_like_ { #if defined(__cpp_lib_integer_sequence) || FMT_MSC_VER >= 1900 template using integer_sequence = std::integer_sequence; -template using index_sequence = std::index_sequence; -template -using make_index_sequence = std::make_index_sequence; +template using index_sequence = std::index_sequence; +template using make_index_sequence = std::make_index_sequence; #else template struct integer_sequence { using value_type = T; - static FMT_CONSTEXPR std::size_t size() { return sizeof...(N); } + static FMT_CONSTEXPR size_t size() { return sizeof...(N); } }; -template -using index_sequence = integer_sequence; +template using index_sequence = integer_sequence; -template +template struct make_integer_sequence : make_integer_sequence {}; template struct make_integer_sequence : integer_sequence {}; -template -using make_index_sequence = make_integer_sequence; +template +using make_index_sequence = make_integer_sequence; #endif template @@ -212,7 +210,7 @@ struct formatter::value>> { } formatting_tuple& formatting; - std::size_t& i; + size_t& i; typename std::add_lvalue_reference().out())>::type out; }; @@ -228,7 +226,7 @@ struct formatter::value>> { template auto format(const TupleT& values, FormatContext& ctx) -> decltype(ctx.out()) { auto out = ctx.out(); - std::size_t i = 0; + size_t i = 0; internal::copy(formatting.prefix, out); internal::for_each(values, format_each{formatting, i, out}); @@ -263,7 +261,7 @@ struct formatter 0) { if (formatting.add_prepostfix_space) *out++ = ' '; diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 828a8aeefefa..b876c151a8aa 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -10,10 +10,11 @@ #endif #include "fmt/chrono.h" -#include "gtest-extra.h" #include +#include "gtest-extra.h" + std::tm make_tm() { auto time = std::tm(); time.tm_mday = 1; diff --git a/test/color-test.cc b/test/color-test.cc index c1113a2e3fd9..454a0660d4cf 100644 --- a/test/color-test.cc +++ b/test/color-test.cc @@ -6,6 +6,7 @@ // For the license information refer to format.h. #include "fmt/color.h" + #include "gtest-extra.h" TEST(ColorsTest, ColorsPrint) { diff --git a/test/compile-test.cc b/test/compile-test.cc index 13bef488bca2..047d5ff86041 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -6,6 +6,7 @@ // For the license information refer to format.h. #include + #include #include #include diff --git a/test/core-test.cc b/test/core-test.cc index adda8943b49d..e6b9db8ace5a 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -83,20 +83,20 @@ TEST(BufferTest, Nonmoveable) { // A test buffer with a dummy grow method. template struct test_buffer : buffer { - void grow(std::size_t capacity) { this->set(nullptr, capacity); } + void grow(size_t capacity) { this->set(nullptr, capacity); } }; template struct mock_buffer : buffer { - MOCK_METHOD1(do_grow, void(std::size_t capacity)); + MOCK_METHOD1(do_grow, void(size_t capacity)); - void grow(std::size_t capacity) { + void grow(size_t capacity) { this->set(this->data(), capacity); do_grow(capacity); } mock_buffer() {} mock_buffer(T* data) { this->set(data, 0); } - mock_buffer(T* data, std::size_t capacity) { this->set(data, capacity); } + mock_buffer(T* data, size_t capacity) { this->set(data, capacity); } }; TEST(BufferTest, Ctor) { @@ -115,7 +115,7 @@ TEST(BufferTest, Ctor) { } { int dummy; - std::size_t capacity = std::numeric_limits::max(); + size_t capacity = std::numeric_limits::max(); mock_buffer buffer(&dummy, capacity); EXPECT_EQ(&dummy, &buffer[0]); EXPECT_EQ(static_cast(0), buffer.size()); @@ -375,7 +375,7 @@ struct check_custom { struct test_buffer : fmt::internal::buffer { char data[10]; test_buffer() : fmt::internal::buffer(data, 0, 10) {} - void grow(std::size_t) {} + void grow(size_t) {} } buffer; fmt::internal::buffer& base = buffer; fmt::format_parse_context parse_ctx(""); @@ -496,9 +496,9 @@ TEST(StringViewTest, Length) { // Check string_view's comparison operator. template