std::basic_const_iterator<Iter>::operator constant-iterator
出自cppreference.com
| |
(1) | (C++23 起) |
| |
(2) | (C++23 起) |
返回底層迭代器 current 可以顯式或隱式轉換成的常量迭代器。
若且唯若 CI 不是 basic_const_iterator 的特化時,CI 滿足僅用於闡釋的概念 /*not-a-const-iterator*/。
返回值
1)
current2)
std::move(current)示例
運行此代碼
#include <iterator>
#include <ranges>
#include <vector>
void foo(std::vector<int>::const_iterator) {}
int main()
{
auto v = std::vector<int>();
{
// 下面的 ranges::cbegin 返回 vector<int>::const_iterator
auto i1 = std::ranges::cbegin(v);
foo(i1); // OK
}
auto t = v | std::views::take_while([](int const x) { return x < 100; });
{
// 下面的 ranges::cbegin 返回 basic_const_iterator<vector<int>::iterator>
auto i2 = std::ranges::cbegin(t);
foo(i2); // P2836R1 前报错
}
}
缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
| 缺陷報告 | 應用於 | 出版時的行為 | 正確行為 |
|---|---|---|---|
| P2836R1 | C++23 | basic_const_iterator 不遵守其底層類型的可轉換性
|
提供轉換運算符 |