std::ranges::crend
来自cppreference.com
<tbody>
</tbody>
| 在标头 <ranges> 定义
|
||
| 在标头 <iterator> 定义
|
||
inline namespace /* 未指明 */ { inline constexpr /* 未指明 */ crend = /* 未指明 */; } |
(C++20 起) (定制点对象) |
|
| 调用签名 |
||
template< class T > requires /* 见下文 */ constexpr /* 见下文 */ auto crend( T&& t ); |
(C++20 起) | |
返回指示被当作逆向序列的 const 限定的(C++23 前)范围结尾的常量迭代器的(C++23 起)哨位。
|
令
则对 |
(C++23 前) |
|
若实参为左值,或者
所有其他情况下,对 |
(C++23 起) |
若 ranges::crend(e) 对于表达式 e 合法,其中 decltype((e)) 为 T,则 CT 实现 std::ranges::range,并且(C++23 前) std::sentinel_for<S, I> 在所有情况下都为 true,其中 S 为 decltype(ranges::crend(e)) 而 I 为 decltype(ranges::crbegin(e))。此外,如果 S 实现了 input_iterator 则它也实现 constant-iterator。(C++23 起)
定制点对象
名字 ranges::crend 代表一个定制点对象,它是某个字面 semiregular 类类型的 const 函数对象。 细节参见定制点对象 (CustomizationPointObject) 。
示例
运行此代码
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
int main()
{
int a[]{4, 6, -3, 9, 10};
std::cout << "数组从后向前:";
namespace ranges = std::ranges;
ranges::copy(ranges::rbegin(a), ranges::rend(a),
std::ostream_iterator<int>(std::cout, " "));
std::cout << '\n';
std::cout << "向量从后向前:";
std::vector v{4, 6, -3, 9, 10};
ranges::copy(ranges::rbegin(v), ranges::rend(v),
std::ostream_iterator<int>(std::cout, " "));
std::cout << '\n';
}
输出:
数组从后向前:10 9 -3 6 4
向量从后向前:10 9 -3 6 4
参阅
(C++20) |
返回指向范围的逆向尾迭代器 (定制点对象) |
(C++14) |
返回容器或数组的逆向尾迭代器 (函数模板) |