std::ranges::cend
来自cppreference.com
<tbody>
</tbody>
| 在标头 <ranges> 定义
|
||
| 在标头 <iterator> 定义
|
||
inline namespace /* 未指明 */ { inline constexpr /* 未指明 */ cend = /* 未指明 */; } |
(C++20 起) (定制点对象) |
|
| 调用签名 |
||
template< class T > requires /* 见下文 */ constexpr /* see below */ auto cend( T&& t ); |
(C++20 起) | |
返回指示 const 限定的(C++23 前)范围的末尾的常量迭代器的(C++23 起)哨位。
|
令
对 |
(C++23 前) |
|
若实参为左值,或者
所有其他情况下,对 |
(C++23 起) |
若 ranges::cend(e) 对某个表达式 e 合法,其中 decltype((e)) 为 T,则 CT 实现 std::ranges::range,且(C++23 前)所有情况下 std::sentinel_for<S, I> 都为 true,其中 S 为 decltype(ranges::cend(e)) 而 I 为 decltype(ranges::cbegin(e))。此外,当 S 实现 input_iterator 时它也实现 constant-iterator。(C++23 起)
定制点对象
名字 ranges::cend 代表一个定制点对象,它是某个字面 semiregular 类类型的 const 函数对象。 细节参见定制点对象 (CustomizationPointObject) 。
示例
运行此代码
#include <algorithm>
#include <iostream>
#include <ranges>
#include <vector>
int main()
{
std::vector vec{3, 1, 4};
int arr[]{5, 10, 15};
assert(std::ranges::find(vec, 5) == std::ranges::cend(vec));
assert(std::ranges::find(arr, 5) != std::ranges::cend(arr));
}
参阅
(C++20) |
返回指示范围结尾的哨位 (定制点对象) |
(C++11)(C++14) |
返回指向容器或数组结尾的迭代器 (函数模板) |