std::ranges::cend
|   定义于头文件  <ranges>
  | 
||
|   inline namespace /*unspecified*/ {     inline constexpr /*unspecified*/ cend = /*unspecified*/;  | 
 (C++20 起)  (定制点对象)  | 
|
|   调用签名  | 
||
|   template< class T >     requires /* see below */  | 
||
返回指示 const 限定范围的末尾的哨位。
令 CT
-  若实参为左值(即 
T为左值引用类型)则为 const std::remove_reference_t<T>& , - 否则为 const T ,
 
则调用 ranges::cend 表达式等价于 ranges::end(static_cast<CT&&>(t)) 。
若 ranges::cend(e) 对表达式 e 合法,其中 decltype((e)) 为 T ,则 CT 实现 std::ranges::range ,且所有情况下 std::sentinel_for<S, I> 为 true ,其中 S 为 decltype(ranges::cend(e)) 而 I 为 decltype(ranges::cbegin(e)) 。
表达式等价
表达式 e 表达式等价于表达式 f ,若 e 与 f 拥有相同效果,均为潜在抛出或均非潜在抛出(即 noexcept(e) == noexcept(f) ),且均为常量子表达式或均非常量子表达式。
定制点对象
名字 ranges::cend 代表一个定制点对象,它是字面 semiregular 类类型(为说明目的以 cend_ftor 表示)的 const 函数对象。cend_ftor 的所有实例均相等。从而能自由地复制 ranges::cend ,且能交替使用其副本。
给定类型集合 Args... ,若 std::declval<Args>()... 满足上面对于 ranges::cend 的参数要求,则 cend_ftor 将满足 std::invocable<const cend_ftor&, Args...> 。否则, cend_ftor 的函数调用运算符不参与重载决议。
示例
#include <algorithm> #include <iostream> #include <ranges> #include <vector> int main() { std::vector<int> v = { 3, 1, 4 }; namespace ranges = std::ranges; if (ranges::find(v, 5) != ranges::cend(v)) { std::cout << "found a 5 in vector v!\n"; } int a[] = { 5, 10, 15 }; if (ranges::find(a, 5) != ranges::cend(a)) { std::cout << "found a 5 in array a!\n"; } }
输出:
found a 5 in array a!
参阅
|    (C++20)  | 
  返回指示范围结尾的哨位   (定制点对象)  | 
|    (C++11)(C++14)  | 
  返回指向容器或数组结尾的迭代器  (函数模板)  |