System::Func class

Func class

تفويض دالة. يجب تخصيص هذا النوع على المكدس وتمريره إلى الدوال بالقيمة أو بالمرجع. لا تستخدم أبداً صنف System::SmartPtr لإدارة كائنات هذا النوع.

template<typename...>class Func : public System::MulticastDelegate<::System::Detail::FuncArgsReorderer<void(), Args...>::type>
Parameterالوصف
المعلماتمعاملات الاستدعاء، ثم نوع الإرجاع الإلزامي.

الطرق

طريقةالوصف
Func()منشئ افتراضي ينشئ null-Func.
Func(T&&)منشئ يبني كائن Func ويعيّن له قيمة (إما رد نداء فعلي أو nullptr).
Func(const Func&)منشئ النسخ.
Func(Func&&)منشئ نقل.
operator=(const Func&)إسناد النسخ.
operator=(Func&&)إسناد النقل.
~Func()المدمر.

ملاحظات

#include "system/func.h"
#include <iostream>

// تقبل هذه الدالة كائنًا من المفوض System::Func كمعامل.
void Print(int x, const System::Func<int, int> &func)
{
  std::cout << func(x) << std::endl;
}

int main()
{
  // أنشئ كائنًا من المفوض System::Func.
  auto func = static_cast<System::Func<int, int>>([](int x) -> int
  {
    return x * x;
  });

  // مرّر الكائن المُنشأ كمعامل للدالة.
  Print(1, func);
  Print(2, func);
  Print(3, func);

  return 0;
}
/*
This code example produces the following output:
1
4
9
*/

انظر أيضًا