- memory[meta header]
- std[meta namespace]
- polymorphic[meta class]
- function[meta id-type]
- cpp26[meta cpp]
constexpr const_pointer operator->() const noexcept; // (1)
constexpr pointer operator->() noexcept; // (2)所有するオブジェクトのメンバへ、基底型Tとしてアクセスするためのポインタを取得する。
*thisが無効値状態でないこと。
所有するオブジェクトを指すポインタ。
投げない。
#include <cassert>
#include <memory>
struct Base {
virtual ~Base() = default;
virtual int f() const { return 0; }
};
struct Derived : Base {
int x = 42;
Derived() = default;
Derived(int x) : x(x) {}
int f() const override { return x; }
};
int main()
{
std::polymorphic<Base> a{std::in_place_type<Derived>};
assert(a->f() == 42); // 基底型Baseのメンバへアクセス(仮想ディスパッチ)
}- std::polymorphic[color ff0000]
- std::in_place_type[link /reference/utility/in_place_type_t.md]
- C++26
- Clang: 22 [mark noimpl]
- GCC: 16.1 [mark verified]
- Visual C++: 2026 Update 2 [mark noimpl]