namespace std::meta {
consteval bool is_operator_function(info r);
}
概要
演算子関数(operator+、operator==など、operatorキーワードで定義される関数)であるかを判定する。代入演算子operator=も演算子関数に含まれる。
戻り値
rが演算子関数を表す場合にtrueを返す。
例
#include <meta>
#include <print>
struct S {
int value;
S operator+(const S& other) const { return {value + other.value}; }
bool operator==(const S&) const = 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::meta::is_special_member_function(m)) {
std::println("{}: is_operator_function={}",
std::meta::display_string_of(m),
std::meta::is_operator_function(m));
}
}
}
出力例
S::operator+(const S&): is_operator_function=true
S::operator==(const S&): is_operator_function=true
S::f(): is_operator_function=false
バージョン
言語
- C++26
処理系
- Clang: ??
- GCC: 16 (
-freflectionオプション指定) ✅ - Visual C++: ??