- meta[meta header]
- std[meta namespace]
- function template[meta id-type]
- cpp26[meta cpp]
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オプション指定) [mark verified] - Visual C++: ??