Title
basic_const_iterator<volatile int*> is not a contiguous_iterator
Status
new
Section
[const.iterators]
Submitter
Hewill Kang

Created on 2024-05-14.00:00:00 last changed 6 months ago

Messages

Date: 2024-06-15.00:00:00

[ 2024-06-24; Reflector poll ]

Set priority to 4 after reflector poll. See also LWG 3813.

Date: 2024-05-14.00:00:00

Although volatile int* satisfies contiguous_iterator, due to the formula design of iter_const_reference_t, its result for the former will be int, which makes basic_const_iterator<volatile int*> no longer a contiguous_iterator even though its iterator_concept is defined as contiguous_iterator_tag and it has a valid operator->() that returns const volatile int*.

This seems to defeat the purpose of basic_const_iterator to preserve the behavior of the underlying iterator (except for indirection operators). The same goes for basic_const_iterator<const volatile int*>:

#include <iterator>
#include <span>

int main() {
  int i = 42;

  const volatile int* p = &i;
  static_assert(std::contiguous_iterator<decltype(p)>);
  std::span sp1{p, 1}; // ok
  
  std::basic_const_iterator it{p};
  static_assert(std::same_as<decltype(it.operator->()), const volatile int*>);
  static_assert(std::same_as<decltype(it)::iterator_concept, std::contiguous_iterator_tag>);
  static_assert(std::contiguous_iterator<decltype(it)>); // failed
  std::span sp2{it, 1}; // failed
}
History
Date User Action Args
2024-06-24 12:09:57adminsetmessages: + msg14193
2024-05-14 00:00:00admincreate