std::counted_iterator<I>::count
来自 cppreference.com
< cpp | iterator | counted iterator
constexpr std::iter_difference_t<I> count() const noexcept; |
(自 C++20 起) | |
返回底层 长度,即到末尾的距离。
内容 |
[edit] 参数
(无)
[edit] 返回值
底层 长度。
[edit] 示例
运行此代码
#include <cassert> #include <iostream> #include <iterator> int main() { constexpr static auto il = {1, 2, 3, 4, 5}; constexpr std::counted_iterator i1{il.begin() + 1, 3}; static_assert(i1.count() == 3); auto i2{i1}; for (; std::default_sentinel != i2; ++i2) std::cout << "*i2: " << *i2 << ", count(): " << i2.count() << '\n'; assert(i2.count() == 0); }
输出
*i2: 2, count(): 3 *i2: 3, count(): 2 *i2: 4, count(): 1
[edit] 另请参阅
(C++20) |
访问底层迭代器 (公共成员函数) |