std::basic_const_iterator<Iter>::operator constant-iterator
來自 cppreference.com
< cpp | 迭代器 | basic_const_iterator
template< /*not-a-const-iterator*/ CI > requires /*constant-iterator*/<CI> && |
(1) | (C++23 起) |
template< /*not-a-const-iterator*/ CI > requires /*constant-iterator*/<CI> && |
(2) | (C++23 起) |
返回一個轉換後的常量迭代器,其底層迭代器 current 可以顯式或隱式地轉換為該常量迭代器。
CI 滿足僅用於說明的概念 /*not-a-const-iterator*/ 當且僅當它不是 basic_const_iterator
的特化。
[編輯] 返回值
1)
current
2) 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 below returns vector<int>::const_iterator auto i1 = std::ranges::cbegin(v); foo(i1); // okay } auto t = v | std::views::take_while([](int const x) { return x < 100; }); { // ranges::cbegin below returns basic_const_iterator<vector<int>::iterator> auto i2 = std::ranges::cbegin(t); foo(i2); // error until P2836R1 } }
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
P2836R1 | C++23 | basic_const_iterator 不遵循其底層型別的可轉換性 |
提供轉換運算子 |