System::Func class

Func class

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

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

الطرق

طريقةالوصف
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
*/

انظر أيضًا