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

履歴 編集

<functional>

std::function_ref::推論補助(C++26)

namespace std {
  template<class F>
  function_ref(F*) -> function_ref<F>; // (1)

  template<auto f>
  function_ref(nontype_t<f>) -> function_ref<see below>; // (2)

  template<auto f, class T>
  function_ref(nontype_t<f>, T&&) -> function_ref<see below>; // (3)
}

概要

std::function_refクラステンプレートの型推論補助。

テンプレートパラメータ制約

  • (1) : is_function<F>trueであること。
  • (2) : Fremove_pointer_t<decltype(f)>としたとき、is_function<F>trueであること。
  • (3) : Fdecltype(f)としたとき
    • Gに対してFR(G::*)(A...) /*cv*/ & noexcept(E)の形式(参照修飾子&は省略可、Ebool値)、または
    • Gとオブジェクト型Mに対してFM G::*の形式、または
    • Gに対してFR(*)(G, A...) noexcept(E)の形式(Ebool値)であること

備考

  • (2) : Fremove_pointer_t<decltype(f)>としたとき、型function_ref<F>に推論される。
  • (3) : 型function_ref<R(A...) noexcept(E)>に推論される。

#include <functional>

int ident(int x) { return x; }

struct X {
  int data;
  int mf(int x) { return x; }
};

int fun(X& obj) { return obj.data; }

int main()
{
  // (1) 関数ポインタ
  std::function_ref f1{&ident};

  // (2) 関数ポインタ/NTTP
  std::function_ref f2{std::nontype<&ident>};

  // (3a) メンバ関数+オブジェクト束縛
  X obj{42};
  std::function_ref f3a{std::nontype<&X::mf>, obj};
  // (3b) メンバ変数+オブジェクト束縛
  std::function_ref f3b{std::nontype<&X::data>, obj};
  // (3c) 関数ポインタ+第1引数束縛
  std::function_ref f3c{std::nontype<&fun>, obj};
}

出力

バージョン

言語

  • C++26

処理系

参照