Created on 2023-08-27.00:00:00 last changed 21 months ago
Proposed resolution:
This wording is relative to N4958.
Modify [const.iterators.iterator], class template basic_const_iterator synopsis, as indicated:
namespace std {
[…]
template<input_iterator Iterator>
class basic_const_iterator {
[…]
constexpr const Iterator& base() const & noexcept;
constexpr Iterator base() &&;
[…]
};
}
Modify [const.iterators.ops] as indicated:
constexpr const Iterator& base() const & noexcept;
-4- Effects: Equivalent to: return current_;constexpr Iterator base() &&;
-5- Effects: Equivalent to: return std::move(current_);
Modify [range.as.const.view] as indicated:
namespace std::ranges {
template<view V>
requires input_range<V>
class as_const_view : public view_interface<as_const_view<V>> {
[…]
constexpr V base() const & requires copy_constructible<V> { return base_; }
constexpr V base() && { return std::move(base_); }
[…]
};
}
[ 2024-03-15; move back to Open following LEWG feedback ]
SG9 approved the proposed change but then LEWG had no consensus for change. LWG should revisit in Tokyo.
[ Kona 2023-11-07; move to Ready ]
[ 2023-10-30; Reflector poll ]
Set priority to 3 after reflector poll. Send to SG9.
Currently, both as_const_view and basic_const_iterator provide base() members to return the underlying range and iterator, which seems to expose vulnerabilities in modifying them:
#include <vector>
#include <ranges>
int main() {
std::vector v{1, 2, 3};
auto f = [](std::span<int>::const_iterator i) {
*i.base() = 4;
};
f(std::span{v}.cbegin());
auto g = [](const std::ranges::constant_range auto& r) {
r.begin().base()[1] = 5;
r.base()[2] = 6;
};
g(std::ranges::as_const_view(v));
// v now becomes [4, 5, 6]
}
I don't think such a shortcut should be provided as it doesn't seem to be the intention and could be harmful.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2024-03-15 13:55:18 | admin | set | messages: + msg14017 |
| 2024-03-15 13:55:18 | admin | set | status: ready -> open |
| 2023-11-07 22:39:32 | admin | set | messages: + msg13830 |
| 2023-11-07 22:39:32 | admin | set | status: open -> ready |
| 2023-10-30 17:22:20 | admin | set | messages: + msg13795 |
| 2023-10-30 17:22:20 | admin | set | status: new -> open |
| 2023-10-02 14:58:03 | admin | set | messages: + msg13743 |
| 2023-08-27 00:00:00 | admin | create | |