Title
Is input_iterator guaranteed to have iter_const_reference_t?
Status
new
Section
[const.iterators.alias]
Submitter
Hewill Kang

Created on 2023-01-26.00:00:00 last changed 21 months ago

Messages

Date: 2023-02-15.00:00:00

[ 2023-02-06; Reflector poll ]

Set priority to 2 after reflector poll. Seems contrived, should probably constrain not give a hard error. The question of whether each range needs to have const reference to elems is important.

Date: 2023-01-26.00:00:00

In the C++20 iterator system, input_iterator is guaranteed to have a common reference, which reflects the indirectly_readable requires common_reference_t<iter_reference_t<I>&&, iter_value_t<I>&> to be a valid type.

However, for iter_const_reference_t which with a similar form:

template<indirectly_readable It>
  using iter_const_reference_t =
    common_reference_t<const iter_value_t<It>&&, iter_reference_t<It>>;

it is still theoretically possible to create an input_iterator that does not have a valid iter_const_reference_t, for example:

#include <iterator>

struct ref {
  ref(int&);
};

struct rref {
  rref(const int&);
  rref(const ref&);
};

struct I {
  using value_type = int;
  using difference_type = std::ptrdiff_t;

  ref operator*() const;
  I& operator++();
  I operator++(int);

  friend rref iter_move(const I&);
};

static_assert(std::input_iterator<I>); // pass
using CR = std::iter_const_reference_t<I>;  // error: no type named 'type' in 'struct std::common_reference<const int&&, ref>'

which causes basic_const_iterator<I> to produce a hard error internally when it is instantiated.

History
Date User Action Args
2023-02-06 15:13:50adminsetmessages: + msg13271
2023-01-26 00:00:00admincreate