System::Func< Args > Class Template Reference

Inherits MulticastDelegate<::System::Detail::FuncArgsReorderer< void(), Args... >::type >.

Public Member Functions

 Func ()
 Default constructor that creates null-Func. More...
 
template<typename T >
 Func (T &&arg)
 
 Func (const Func &func)
 
 Func (Func &&func) noexcept
 
 ~Func ()
 Destructor. More...
 
Funcoperator= (const Func &other)
 
Funcoperator= (Func &&other) noexcept
 

Detailed Description

template<typename... Args>
class System::Func< Args >

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.

#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
*/
Template Parameters
ArgsCall arguments, then mandatory return type.

Constructor & Destructor Documentation

◆ Func() [1/4]

template<typename... Args>
System::Func< Args >::Func ( )
inline

Default constructor that creates null-Func.

◆ Func() [2/4]

template<typename... Args>
template<typename T >
System::Func< Args >::Func ( T &&  arg)
inline

Constructor that constructs Func object and assigns value (either actual callback or nullptr) to it.

Template Parameters
TArgument type.
Parameters
argArgument.

◆ Func() [3/4]

template<typename... Args>
System::Func< Args >::Func ( const Func< Args > &  func)
inline

Copy constructor.

Parameters
funcObject to copy data from.

◆ Func() [4/4]

template<typename... Args>
System::Func< Args >::Func ( Func< Args > &&  func)
inlinenoexcept

Move constructor.

Parameters
funcObject to move data from.

◆ ~Func()

template<typename... Args>
System::Func< Args >::~Func ( )
inline

Destructor.

Member Function Documentation

◆ operator=() [1/2]

template<typename... Args>
Func& System::Func< Args >::operator= ( const Func< Args > &  other)
inline

Copy assignment.

Parameters
otherFunc delegate to copy to current object.
Returns
Reference to this.

◆ operator=() [2/2]

template<typename... Args>
Func& System::Func< Args >::operator= ( Func< Args > &&  other)
inlinenoexcept

Move assignment.

Parameters
otherFunc delegate to move to current object. The state can be changed.
Returns
Reference to this.