std::ranges::crbegin
定義於標頭檔案 <ranges> |
||
定義於標頭檔案 <iterator> |
||
inline namespace /* 未指定 */ { inline constexpr /* 未指定 */ crbegin = /* 未指定 */; |
(C++20 起) (定製點物件) |
|
呼叫簽名 (Call signature) |
||
template< class T > requires /* 見下文 */ |
(C++20 起) | |
返回一個迭代器,指向被視為反向序列的 const 限定引數的第一個元素。 |
(直至 C++23) |
返回一個常量迭代器,指向被視為反向序列的引數的第一個元素。 |
(C++23 起) |
令
呼叫 |
(直至 C++23) |
如果引數是左值或 ranges::enable_borrowed_range<std::remove_cv_t<T>> 為 true,則呼叫
在所有其他情況下,呼叫 |
(C++23 起) |
在所有情況下,返回型別都滿足 std::input_or_output_iterator 和 constant-iterator
(從 C++23 開始)。
自定義點物件
名稱 ranges::crbegin
指示一個定製點物件,它是 字面量 semiregular
類型別的 const 函式物件。為了說明目的,其型別中 cv 非限定版本表示為 __crbegin_fn
。
__crbegin_fn
的所有例項均相等。在相同實參上呼叫 __crbegin_fn
型別的不同例項的效果是等價的,無論指示例項的表示式是左值還是右值,以及是否為 const 限定(然而,不要求 volatile 限定例項是可呼叫的)。因此,ranges::crbegin
可以自由複製,並且其副本可以互換使用。
給定一組型別 Args...
,若 std::declval<Args>()... 滿足上述 ranges::crbegin
的實參要求,則 __crbegin_fn
滿足
- std::invocable<__crbegin_fn, Args...>,
- std::invocable<const __crbegin_fn, Args...>,
- std::invocable<__crbegin_fn&, Args...>,以及
- std::invocable<const __crbegin_fn&, Args...>.
否則,__crbegin_fn
的任何函式呼叫運算子都不參與過載決議。
[編輯] 示例
#include <cassert> #include <iterator> #include <span> #include <vector> int main() { std::vector<int> v{3, 1, 4}; auto vi = std::ranges::crbegin(v); assert(*vi == 4); ++vi; // OK, iterator object is mutable assert(*vi == 1); // *vi = 13; // Error: underlying element is read-only int a[]{-5, 10, 15}; auto ai = std::ranges::crbegin(a); assert(*ai == 15); // auto x_x = std::ranges::crbegin(std::vector<int>{6, 6, 6}); // ill-formed: the argument is an rvalue (see Notes ↑) auto si = std::ranges::crbegin(std::span{a}); // OK assert(*si == 15); static_assert ( std::ranges::enable_borrowed_range<std::remove_cv_t<decltype(std::span{a})>> ); }
[編輯] 參閱
(C++20) |
返回指向範圍的反向迭代器 (定製點物件) |
(C++14) |
返回指向容器或陣列開頭的反向迭代器 (函式模板) |