Delegate< ReturnType(ArgumentTypes...)>

Delegate< ReturnType(ArgumentTypes…)> class

Represents a pointer to a function, method or a function object. 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<class ReturnType,class...>class Delegate< ReturnType(ArgumentTypes...)> : public System::Details::DelegateHoldingVariables

Template parameters

ParameterDescription
ReturnTypeThe return type of a function, method or a function object pointer to which is represented by the class
ArgumentTypesThe argument list of a function, method or a function object pointer to which is represented by the class

Methods

MethodDescription
Delegate()Default constructor. Constructs the delegate object that does not point to anything.
Delegate(const Delegate&)
Delegate(Delegate&&)Moving copy constructor. Takes the ownership of an entity pointed to by the specified delegate.
Delegate(T, typename std::enable_if<!std::is_bind_expression<T>::value&&std::is_pointer<T>::value&&std::is_function<typename std::remove_pointer<T>::type>::value>::type *)Constructor. Constructs a delegate object from the specified pointer to free function or static method.
Delegate(T, typename std::enable_if<std::is_bind_expression<T>::value>::type *)Constructor. Constructs a delegate from the specified pointer to the function object generated by std::bind().
Delegate(int, T&)Constructor. Constructs a delegate from the specified function object.
Delegate(long, T&&)Moving constructor. Constructs a delegate from the specified function object.
Delegate(MemberType ClassType::*, ClassType *)Constructor. Constructs a delegate that points to the specified non-static method of the specified object.
Delegate(MemberType MemberClass::*, const SharedPtr<ClassType>&)Constructor. Constructs a delegate that points to the specified non-static method of the specified object.
Delegate(std::function<R(Args…)>)Constructs a delegate object that points to an std::function function object.
bool Empty() constDetermines if the current delegate object is empty, e.g. does not point to any entity.
ReturnType operator()(ArgumentTypes…) constInvokes a function, method or a function object that is pointed to by current delegate object.
Delegate& operator=(const Delegate&)
Delegate& operator=(Delegate&&)Moving assignment operator. Takes the ownership of an entity pointed to by the specified delegate.
bool operator==(const Delegate&) constCompares two delegate objects to check if they point to the same entity.

Remarks

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

// Declare the delegate.
using Message = System::Delegate<void()>;

void PrintMessage()
{
  std::cout << "Hello, world!" << std::endl;
}

int main()
{
  // Assign to variable the address of the PrintMessage function.
  Message mes = Message(&PrintMessage);

  // Call the function.
  mes();

  return 0;
}
/*
This code example produces the following output:
Hello, world!
*/

See Also