最終更新日時(UTC):
が更新

履歴 編集

function
<meta>

std::meta::is_constructor(C++26)

namespace std::meta {
  consteval bool is_constructor(info r);
}

概要

コンストラクタであるかを判定する。

戻り値

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));
    }
  }
}

出力例

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

処理系

参照