constexpr reference back(); // (1) C++26
constexpr const_reference back() const; // (2) C++26
概要
末尾要素への参照を取得する。
- (1) : 非
constな文脈で末尾要素への参照を取得する。 - (2) :
constな文脈で末尾要素への読み取り専用参照を取得する。
戻り値
末尾要素への参照
計算量
定数時間
例
#include <print>
#include <inplace_vector>
int main()
{
std::inplace_vector<int, 5> iv = {3, 1, 4};
int& x = iv.back();
std::println("{}", x);
}
出力
4
バージョン
言語
- C++26
処理系
- Clang: 23 ✅
- GCC: 16 ✅
- Visual C++: 2026 Update 2 ❌