Skip to content

Commit

Permalink
Conform std::iterator_traits<fmt::appender> to [iterator.traits]/1 (f…
Browse files Browse the repository at this point in the history
…mtlib#4185)

* Conform `std::iterator_traits<fmt::appender>` to [iterator.traits]/1

> In addition, the types
> ```c++
> iterator_traits<I>::pointer
> iterator_traits<I>::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<I>::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<I>::value_type
> iterator_traits<I>::difference_type
> iterator_traits<I>::reference
> ```
> may be defined as `void`.

* Remove unnecessary member types from basic_appender

This reverts commit 1accf6c.

* Address clang-format issue
  • Loading branch information
CaseyCarter authored Oct 3, 2024
1 parent 1879289 commit e62c41f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 0 additions & 5 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -2382,11 +2382,6 @@ template <typename T> class basic_appender {
detail::buffer<T>* 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<T>;

FMT_CONSTEXPR basic_appender(detail::buffer<T>& buf) : container(&buf) {}
Expand Down
10 changes: 6 additions & 4 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@
#endif

namespace std {
template <> struct iterator_traits<fmt::appender> {
template <class T> struct iterator_traits<fmt::basic_appender<T>> {
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<int*>(nullptr) - static_cast<int*>(nullptr));
using pointer = void;
using reference = void;
};
} // namespace std

Expand Down

0 comments on commit e62c41f

Please sign in to comment.