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

履歴 編集

function
<meta>

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

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

概要

演算子関数テンプレートであるかを判定する。演算子関数テンプレートとは、template <class T> bool operator==(const T&)のようなテンプレート化された演算子関数のことである。

戻り値

rが演算子関数テンプレートを表す場合にtrueを返す。

#include <meta>

struct S {
  bool operator==(const S&) const = default;  // 演算子関数
  template <class T>
  S operator+(const T& other) const { return *this; }  // 演算子関数テンプレート
  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_operator_function_template(m)) {
      // template <class T> operator+(const T&) のみがここに到達する
      static_assert(std::meta::is_template(m));
      static_assert(!std::meta::is_operator_function(m));
    }
  }
}

出力

バージョン

言語

  • C++26

処理系

参照