Created on 2023-01-06.00:00:00 last changed 12 months ago
Proposed resolution:
This wording is relative to N4917.
Modify [const.iterators] as indicated:
namespace std { template<class I> concept not-a-const-iterator = see below; template<input_iterator Iterator> class basic_const_iterator { Iterator current_ = Iterator(); // exposition only using reference = iter_const_reference_t<Iterator>; // exposition only public: […] constexpr reference operator*() const; constexpr const auto[…]value_type* operator->() const requires is_lvalue_reference_v<iter_reference_t<Iterator>> && same_as<remove_cvref_t<iter_reference_t<Iterator>>, value_type>; […] }; }constexpr const autovalue_type* operator->() const requires is_lvalue_reference_v<iter_reference_t<Iterator>> && same_as<remove_cvref_t<iter_reference_t<Iterator>>, value_type>;-7- Returns: If Iterator models contiguous_iterator, to_address(current_); otherwise, addressof(*current_).
[ 2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Voting → WP. ]
[ 2023-02-01; Reflector poll ]
Set status to Tentatively Ready after six votes in favour during reflector poll.
Currently, basic_const_iterator::operator-> constrains the value type of the underlying iterator to be only the cv-unqualified type of its reference type, which is true for raw pointers.
However, since it also explicitly specifies returning a pointer to a const value type, this will cause a hard error when the value type is actually volatile-qualified:
std::basic_const_iterator<volatile int*> it;
auto* p = it.operator->(); // invalid conversion from 'volatile int*' to 'const int*'
The proposed resolution changes the return type from const value_type* to const auto*, which makes it deduce the correct type in the above example, i.e. const volatile int*.
History | |||
---|---|---|---|
Date | User | Action | Args |
2023-11-22 15:47:43 | admin | set | status: wp -> c++23 |
2023-02-13 10:17:57 | admin | set | messages: + msg13372 |
2023-02-13 10:17:57 | admin | set | status: voting -> wp |
2023-02-06 15:33:48 | admin | set | status: ready -> voting |
2023-02-01 20:39:10 | admin | set | messages: + msg13246 |
2023-02-01 20:39:10 | admin | set | status: new -> ready |
2023-01-06 16:24:01 | admin | set | messages: + msg13193 |
2023-01-06 00:00:00 | admin | create |