From 0e72c98043cd4fc5e48ab91cd213f059c3a759ad Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 19 Jun 2019 14:11:34 -0700 Subject: [PATCH] Make undocumented output_range internal --- include/fmt/chrono.h | 2 +- include/fmt/format.h | 60 ++++++++++++++++++++------------------------ include/fmt/locale.h | 2 +- test/format | 7 +++--- 4 files changed, 32 insertions(+), 39 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index e080b958..77490665 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -696,7 +696,7 @@ struct formatter, Char> { // is not specified. basic_memory_buffer buf; auto out = std::back_inserter(buf); - typedef output_range range; + using range = internal::output_range; basic_writer w(range(ctx.out())); internal::handle_dynamic_spec( spec.width_, width_ref, ctx, format_str.begin()); diff --git a/include/fmt/format.h b/include/fmt/format.h index 505c309a..116cd26f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -225,54 +225,35 @@ template inline bool use_grisu() { sizeof(T) <= sizeof(double); } -// A range whose output iterator appends to a buffer. +// A range with an iterator appending to a buffer. template class buffer_range { public: using value_type = T; - using iterator = std::back_insert_iterator>; + using iterator = std::back_insert_iterator>; private: iterator begin_; public: - buffer_range(internal::buffer& buf) : begin_(std::back_inserter(buf)) {} + buffer_range(buffer& buf) : begin_(std::back_inserter(buf)) {} explicit buffer_range(iterator it) : begin_(it) {} iterator begin() const { return begin_; } }; -} // namespace internal +// A range with the specified output iterator and value type. template class output_range { private: OutputIt it_; - // Unused yet. - typedef void sentinel; - sentinel end() const; - public: - typedef OutputIt iterator; - typedef T value_type; + using value_type = T; + using iterator = OutputIt; explicit output_range(OutputIt it) : it_(it) {} OutputIt begin() const { return it_; } }; -template class basic_writer; -using writer = basic_writer>; -using wwriter = basic_writer>; - -/** A formatting error such as invalid format string. */ -class format_error : public std::runtime_error { - public: - explicit format_error(const char* message) : std::runtime_error(message) {} - explicit format_error(const std::string& message) - : std::runtime_error(message) {} - ~format_error() FMT_NOEXCEPT; -}; - -namespace internal { - #ifdef _SECURE_SCL // Make a checked iterator to avoid MSVC warnings. template using checked_ptr = stdext::checked_array_iterator; @@ -287,10 +268,9 @@ template inline T* make_checked(T* p, std::size_t) { return p; } template template void buffer::append(const U* begin, const U* end) { - std::size_t new_size = size_ + internal::to_unsigned(end - begin); + std::size_t new_size = size_ + to_unsigned(end - begin); reserve(new_size); - std::uninitialized_copy(begin, end, - internal::make_checked(ptr_, capacity_) + size_); + std::uninitialized_copy(begin, end, make_checked(ptr_, capacity_) + size_); size_ = new_size; } } // namespace internal @@ -436,6 +416,19 @@ void basic_memory_buffer::grow(std::size_t size) { typedef basic_memory_buffer memory_buffer; typedef basic_memory_buffer wmemory_buffer; +/** A formatting error such as invalid format string. */ +class format_error : public std::runtime_error { + public: + explicit format_error(const char* message) : std::runtime_error(message) {} + explicit format_error(const std::string& message) + : std::runtime_error(message) {} + ~format_error() FMT_NOEXCEPT; +}; + +template class basic_writer; +using writer = basic_writer>; +using wwriter = basic_writer>; + namespace internal { // A workaround for std::string not having mutable data() until C++17. @@ -2981,8 +2974,9 @@ struct formatter( specs_.precision, specs_.precision_ref, ctx, format_str_); - using range_type = output_range; + using range_type = + internal::output_range; return visit_format_arg(arg_formatter(ctx, nullptr, &specs_), internal::make_arg(val)); } @@ -3073,8 +3067,8 @@ template class dynamic_formatter { else if (specs_.has(HASH_FLAG)) checker.on_hash(); if (specs_.precision != -1) checker.end_precision(); - typedef output_range + typedef internal::output_range range; visit_format_arg(arg_formatter(ctx, nullptr, &specs_), internal::make_arg(val)); @@ -3373,7 +3367,7 @@ template >::type args) { - typedef output_range> range; + typedef internal::output_range> range; return vformat_to>(range(out), to_string_view(format_str), args); } diff --git a/include/fmt/locale.h b/include/fmt/locale.h index dd6def10..1faf9723 100644 --- a/include/fmt/locale.h +++ b/include/fmt/locale.h @@ -55,7 +55,7 @@ template ::type args) { - using range = output_range; + using range = internal::output_range; return vformat_to>( range(out), to_string_view(format_str), args, internal::locale_ref(loc)); } diff --git a/test/format b/test/format index 3da26344..f9315272 100644 --- a/test/format +++ b/test/format @@ -693,9 +693,8 @@ struct formatter { specs_.width_, specs_.width_ref, ctx, nullptr); fmt::internal::handle_dynamic_spec( specs_.precision, specs_.precision_ref, ctx, nullptr); - typedef fmt::output_range - range_type; + using range_type = fmt::internal::output_range; return visit_format_arg(arg_formatter(ctx, nullptr, &specs_), basic_format_arg(val)); } @@ -742,7 +741,7 @@ template template Out vformat_to(Out out, string_view fmt, format_args_t args) { - typedef fmt::output_range range; + using range = fmt::internal::output_range; detail::format_handler, char, basic_format_context> h(range(out), fmt, args, {}); fmt::internal::parse_format_string(fmt::to_string_view(fmt), h);