From e62c41ffb04d3e9cbe83e961292b85eeeaf4095f Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Thu, 3 Oct 2024 09:05:14 -0700 Subject: [PATCH] Conform `std::iterator_traits` to [iterator.traits]/1 (#4185) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Conform `std::iterator_traits` to [iterator.traits]/1 > In addition, the types > ```c++ > iterator_traits::pointer > iterator_traits::reference > ``` > shall be defined as the iterator’s pointer and reference types; that is, for an iterator object `a` of class type, the same type as `decltype(a.operator->())` and `decltype(*a)`, respectively. The type `iterator_traits::pointer` shall be void for an iterator of class type `I` that does not support `operator->`. Additionally, in the case of an output iterator, the types > ```c++ > iterator_traits::value_type > iterator_traits::difference_type > iterator_traits::reference > ``` > may be defined as `void`. * Remove unnecessary member types from basic_appender This reverts commit 1accf6c0a043fb445cbbfeefdbc1f91a08e3099f. * Address clang-format issue --- include/fmt/base.h | 5 ----- include/fmt/format.h | 10 ++++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index f91f8e825354..84b175c31007 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2382,11 +2382,6 @@ template class basic_appender { detail::buffer* container; public: - using iterator_category = int; - using value_type = T; - using pointer = T*; - using reference = T&; - using difference_type = decltype(pointer() - pointer()); using container_type = detail::buffer; FMT_CONSTEXPR basic_appender(detail::buffer& buf) : container(&buf) {} diff --git a/include/fmt/format.h b/include/fmt/format.h index 52af87b8b146..4892d682ffc4 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -119,11 +119,13 @@ #endif namespace std { -template <> struct iterator_traits { +template struct iterator_traits> { using iterator_category = output_iterator_tag; - using value_type = char; - using reference = char&; - using difference_type = fmt::appender::difference_type; + using value_type = T; + using difference_type = + decltype(static_cast(nullptr) - static_cast(nullptr)); + using pointer = void; + using reference = void; }; } // namespace std