Skip to content

Latest commit

 

History

History
73 lines (59 loc) · 1.76 KB

File metadata and controls

73 lines (59 loc) · 1.76 KB

is_constructor

  • 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

処理系

参照