std::ranges::crbegin
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |   定义于头文件  <ranges>
  | 
||
|   inline namespace /*unspecified*/ {     inline constexpr /*unspecified*/ crbegin = /*unspecified*/;  | 
 (C++20 起)  (定制点对象)  | 
|
|   调用签名  | 
||
|   template< class T >     requires /* see below */  | 
||
返回指向被当作逆向序列的 const 限定实参的首元素的迭代器。
令 CT
-  若实参为左值(即 
T为左值引用类型)则为 const std::remove_reference_t<T>& , - 否则为 const T ,
 
则调用 ranges::crbegin 表达式等价于 ranges::rbegin(static_cast<CT&&>(t)) 。
两种情况下返回类型都实现 std::input_or_output_iterator 。
表达式等价
表达式 e 表达式等价于表达式 f ,若 e 与 f 拥有相同效果,均为潜在抛出或均非潜在抛出(即 noexcept(e) == noexcept(f) ),且均为常量子表达式或均非常量子表达式。
定制点对象
名字 ranges::crbegin 代表一个定制点对象,它是字面 semiregular 类类型(为说明目的以 crbegin_ftor 表示)的 const 函数对象。crbegin_ftor 的所有实例均相等。从而能自由地复制 ranges::crbegin ,且能交替使用其副本。
给定类型集合 Args... ,若 std::declval<Args>()... 满足上面对于 ranges::crbegin 的参数要求,则 crbegin_ftor 将满足 std::invocable<const crbegin_ftor&, Args...> 。否则, crbegin_ftor 的函数调用运算符不参与重载决议。
示例
运行此代码
#include <iostream> #include <vector> #include <iterator> int main() { std::vector<int> v = { 3, 1, 4 }; auto vi = std::ranges::crbegin(v); std::cout << *vi << '\n'; int a[] = { -5, 10, 15 }; auto ai = std::ranges::crbegin(a); std::cout << *ai << '\n'; }
输出:
4 15
参阅
|    (C++20)  | 
  返回指向范围的逆向迭代器  (定制点对象)  | 
|    (C++14)  | 
  返回指向一个容器或数组的逆向迭代器  (函数模板)  |