Namespaces
Variants

std::ranges:: cend

From cppreference.net
Ranges library
Range adaptors
定义于头文件 <ranges>
定义于头文件 <iterator>
inline namespace /* 未指定 */ {

inline constexpr /* 未指定 */ cend = /* 未指定 */ ;

}
(C++20 起)
(定制点对象)
调用签名
template < class T >

requires /* 见下文 */

constexpr /* 见下文 */ auto cend ( T && t ) ;
(C++20 起)

返回一个哨兵 用于常量迭代器 (自 C++23 起) ,指示 const 限定 (直至 C++23) 范围的末尾。

range-begin-end.svg

CT

ranges::cend 的调用与 ranges:: end ( static_cast < CT && > ( t ) ) 表达式等价。

(C++23 前)

若实参为左值或 ranges:: enable_borrowed_range < std:: remove_cv_t < T >> true ,则对 ranges::cend 的调用表达式等价于:

其他情况下,对 ranges::cend 的调用非良构,当该调用出现在模板实例化的直接上下文时可能导致 替换失败

(C++23 起)

如果对于表达式 e ranges :: cend ( 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 类类型。详情请参阅 定制点对象

示例

#include <algorithm>
#include <cassert>
#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++11) (C++14)
返回容器或数组末尾的迭代器
(函数模板)