namespace std {
template <class T>
consteval const remove_cvref_t<T>* define_static_object(T&& t);
}
概要
コンパイル時に計算したオブジェクトを静的ストレージに配置し、そのポインタを返す。
戻り値
tのコピーを保持する静的ストレージ上のオブジェクトへのポインタを返す。
例
#include <meta>
#include <print>
struct Config {
int width;
int height;
};
int main() {
constexpr auto* p = std::define_static_object(Config{1920, 1080});
std::println("{}x{}", p->width, p->height);
}
出力
1920x1080
バージョン
言語
- C++26
処理系
- Clang: ??
- GCC: 16 (
-freflectionオプション指定) ✅ - Visual C++: ??