const_reverse_iterator crbegin() const noexcept; // (1) C++11
constexpr const_reverse_iterator crbegin() const noexcept; // (1) C++20
概要
末尾を指す読み取り専用逆イテレータを取得する
戻り値
reverse_iterator(end())
例外
投げない
例
#include <iostream>
#include <string>
int main()
{
std::string s = "hello";
// 末尾への逆イテレータを取得
decltype(s)::const_reverse_iterator it = s.crbegin();
// イテレータが指している要素を参照
const char& c = *it;
std::cout << c << std::endl;
}
出力
o
参照
- P0980R1 Making
std::stringconstexpr - LWG Issue 1192.
basic_stringmissing definitions for cbegin / cend / crbegin / crend- C++11で、これらのメンバ関数が追加された。ほかのコンテナには追加されていたが、
basic_stringには記載が漏れていた
- C++11で、これらのメンバ関数が追加された。ほかのコンテナには追加されていたが、