constexpr const_pointer operator->() const noexcept; // (1)
constexpr pointer operator->() noexcept; // (2)
概要
所有するオブジェクトのメンバへアクセスするためのポインタを取得する。
事前条件
*thisが無効値状態でないこと。
戻り値
所有するオブジェクトを指すポインタ。
例外
投げない。
例
#include <cassert>
#include <memory>
#include <string>
int main()
{
std::indirect<std::string> s{std::string{"hello"}};
assert(s->size() == 5); // 所有するstringのメンバにアクセス
s->push_back('!');
assert(*s == "hello!");
}
出力
バージョン
言語
- C++26
処理系
- Clang: 22 ❌
- GCC: 16.1 ✅
- Visual C++: 2026 Update 2 ❌