Skip to content

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

Merged
vitaut merged 6 commits intofmtlib:masterfrom
CaseyCarter:iterator_traits
Oct 3, 2024
Merged

Conform std::iterator_traits<fmt::appender> to [iterator.traits]/1#4185
vitaut merged 6 commits intofmtlib:masterfrom
CaseyCarter:iterator_traits

Conversation

@CaseyCarter
Copy link
Copy Markdown
Contributor

@CaseyCarter CaseyCarter commented Oct 2, 2024

In addition, the types

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

iterator_traits<I>::value_type
iterator_traits<I>::difference_type
iterator_traits<I>::reference

may be defined as void.

Also removes the unnecessary member types from basic_appender.

> 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`.
@CaseyCarter
Copy link
Copy Markdown
Contributor Author

CaseyCarter commented Oct 2, 2024

Some C++20 tests that my naive local build didn't enable apparently want to use basic_appender without the iterator_traits specialization. I'll need to bring back at least the nested difference_type.

EDIT: Not exactly. The issue here was that I forgot the "void difference_type for output iterators" rule is only preserved for backwards compatibility with legacy iterators and all of the C++20 iterator concepts reject such an iterator.

The warning suppression just triggers another warning on a different compiler. Declare defeat.

This reverts commit 1accf6c.
@CaseyCarter
Copy link
Copy Markdown
Contributor Author

Ok, this now compiles FMT_PEDANTIC C++20 on at least MSVC and GCC. Sorry for the noisy PR =)

@vitaut vitaut merged commit e62c41f into fmtlib:master Oct 3, 2024
@vitaut
Copy link
Copy Markdown
Contributor

vitaut commented Oct 3, 2024

Thank you!

@CaseyCarter CaseyCarter deleted the iterator_traits branch October 3, 2024 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants