System::Func class
Contents
[
Hide
]Func class
Function delegate. This type should be allocated on stack and passed to functions by value or by reference. Never use System::SmartPtr class to manage objects of this type.
template<typename...>class Func : public System::MulticastDelegate<::System::Detail::FuncArgsReorderer<void(), Args...>::type>
Parameter | Description |
---|---|
Args | Call arguments, then mandatory return type. |
Methods
Method | Description |
---|---|
Func() | Default constructor that creates null-Func. |
Func(T&&) | Constructor that constructs Func object and assigns value (either actual callback or nullptr) to it. |
Func(const Func&) | Copy constructor. |
Func(Func&&) | Move constructor. |
operator=(const Func&) | Copy assignment. |
operator=(Func&&) | Move assignment. |
~Func() | Destructor. |
Remarks
#include "system/func.h"
#include <iostream>
// This function accepts an instance of the System::Func delegate as a parameter.
void Print(int x, const System::Func<int, int> &func)
{
std::cout << func(x) << std::endl;
}
int main()
{
// Create an instance of the System::Func delegate.
auto func = static_cast<System::Func<int, int>>([](int x) -> int
{
return x * x;
});
// Pass the created instance as a function argument.
Print(1, func);
Print(2, func);
Print(3, func);
return 0;
}
/*
This code example produces the following output:
1
4
9
*/
See Also
- Namespace System
- Library Aspose.PDF for C++