Created on 2025-03-06.00:00:00 last changed 1 month ago
[ 2025-10-21; Reflector poll. ]
Set priority to 2 after reflector poll.
The majority voted NAD, because the range shown in the issue is nonsensical. But enough people voted P2 that we should not close it without more discussion.
The standard does not explicitly prohibit ranges that are only const-iterable, i.e. a range with
const begin() and deleted or invalid non-const begin().
Unfortunately, those ranges cannot be formatted because the R in
formatter<R> is always without the const-qualifier,
which makes it never satisfy the range concept
(demo):
#include <print>
#include <ranges>
struct R {
int* begin() = delete;
int* end() = delete;
const int* begin() const;
const int* end() const;
};
int main() {
const R r;
static_assert(std::ranges::contiguous_range<decltype(r)>);
for (auto&& elem : r)
std::print("{} ", elem); // ok
std::ranges::for_each(
r, [](auto&& elem) { std::print("{} ", elem); }
); // ok
std::print("{}", r); // not ok
}
Although such type might be relatively rare, it does reflect an inconsistency in the general usage of formatting ranges, which do not support all valid ranges.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2025-10-21 14:07:47 | admin | set | messages: + msg15312 |
| 2025-03-06 00:00:00 | admin | create | |