- meta[meta header]
- std::meta[meta namespace]
- function[meta id-type]
- cpp26[meta cpp]
namespace std::meta {
consteval bool is_constructor(info r);
}- info[link info.md]
コンストラクタであるかを判定する。
rがコンストラクタを表す場合にtrueを返す。
#include <meta>
#include <print>
struct S {
S() = default; // デフォルトコンストラクタ
S(int) {} // 変換コンストラクタ
S(const S&) = default; // コピーコンストラクタ
void f() {} // 通常のメンバ関数
};
int main() {
template for (constexpr auto m :
std::define_static_array(std::meta::members_of(^^S, std::meta::access_context::unchecked()))) {
if constexpr (std::meta::is_function(m)) {
std::println("{}: is_constructor={}",
std::meta::display_string_of(m),
std::meta::is_constructor(m));
}
}
}- std::meta::members_of[link members_of.md]
- std::meta::is_function[link is_function.md]
- std::meta::display_string_of[link display_string_of.md]
- std::meta::access_context[link access_context.md]
- unchecked[link access_context/unchecked.md]
S::S(): is_constructor=true
S::S(int): is_constructor=true
S::S(const S&): is_constructor=true
S::f(): is_constructor=false
S::operator=(const S&): is_constructor=false
S::~S(): is_constructor=false
- C++26
- Clang: ??
- GCC: 16 (
-freflectionオプション指定) [mark verified] - Visual C++: ??