namespace std::meta {
consteval bool is_assignment(info r);
}
概要
代入演算子(コピー代入演算子およびムーブ代入演算子)であるかを判定する。
戻り値
rが代入演算子を表す場合にtrueを返す。
例
#include <meta>
#include <print>
struct S {
S& operator=(const S&) = default; // コピー代入演算子
S& operator=(S&&) = default; // ムーブ代入演算子
S& operator=(int) { return *this; } // 代入演算子ではない(通常のoperator=)
};
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_assignment={}",
std::meta::display_string_of(m),
std::meta::is_assignment(m));
}
}
}
出力例
constexpr S& S::operator=(const S&): is_assignment=true
constexpr S& S::operator=(S&&): is_assignment=true
S& S::operator=(int): is_assignment=true
constexpr S::S(): is_assignment=false
constexpr S::S(const S&): is_assignment=false
constexpr S::~S(): is_assignment=false
バージョン
言語
- C++26
処理系
- Clang: ??
- GCC: 16 (
-freflectionオプション指定) ✅ - Visual C++: ??