template<typename result_t, typename... arguments_t>
class xtd::delegate< result_t(arguments_t...)>
Represents a delegate, which is a data structure that refers to a static method or to a class instance && an instance method of that class.
- Header
-
- Namespace
- xtd
- Library
- xtd.core
- Examples
- The following example shows how to define a delegate named my Method delegate. Instances of this delegate are created for an instance method && a static method of the nested mySampleClass class. The delegate for the instance method requires an instance of mySampleClass. The mySampleClass instance is saved in a variable named mySC.
#include <xtd/console>
#include <xtd/delegate>
}
public:
console::write_line("Hello {}", s);
}
};
auto main()->int {
auto f = example_function {instance, &::object::hello};
return 0;
}
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
delegate()=default
Initializes an empty delegate.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:32
object()=default
Create a new instance of the ultimate base class object.
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
|
using | no_arguments_function_t = std::function< result_t()> |
| no_arguments_function_t pointer type
|
|
using | function_t = std::function< result_t(arguments_t...)> |
| function_t pointer type
|
|
|
| delegate ()=default |
| Initializes an empty delegate.
|
|
| delegate (const function_t &function) noexcept |
| Initializes a delegate that invokes the specified instance method.
|
|
template<typename object1_t , typename object2_t > |
| delegate (const object1_t &object, result_t(object2_t::*method)() const) noexcept |
| Initializes a delegate that invokes the specified instance method on the specified class instance.
|
|
template<typename object1_t , typename object2_t > |
| delegate (const object1_t &object, result_t(object2_t::*method)()) noexcept |
| Initializes a delegate that invokes the specified instance method on the specified class instance.
|
|
|
async_result | begin_invoke (arguments_t... arguments) |
| Executes the method represented by the current delegate asynchronously on the thread that the control's underlying handle was created on.
|
|
async_result | begin_invoke (xtd::async_callback async_callback, arguments_t... arguments) |
| Executes the method represented by the current delegate asynchronously on the thread that the control's underlying handle was created on.
|
|
async_result | begin_invoke (xtd::async_callback async_callback, std::any async_state, arguments_t... arguments) |
| Executes the method represented by the current delegate asynchronously on the thread that the control's underlying handle was created on.
|
|
result_t | end_invoke (async_result async) |
| Retrieves the return value of the asynchronous operation represented by the async_result_invoke passed.
|
|
result_t | invoke (arguments_t... arguments) const |
| invokes the method represented by the current delegate.
|
|
bool | equals (const delegate &delegate) const noexcept override |
| Determines whether this instance and another specified delegateType object have the same value.
|
|
|
result_t | operator() (arguments_t... arguments) const |
| invokes the method represented by the current delegate.
|
|
|
static delegate | combine (const std::vector< delegate > &delegates) noexcept |
| Concatenates the invocation lists of an array of delegates.
|
|
static delegate | combine (const delegate &a, const delegate &b) noexcept |
| Concatenates the invocation lists of two delegates.
|
|
static delegate | remove (const delegate &source, const delegate &value) noexcept |
| removes the last occurrence of the invocation list of a delegate from the invocation list of another delegate.
|
|
static delegate | remove_all (const delegate &source, const delegate &value) noexcept |
| removes all occurrences of the invocation list of a delegate from the invocation list of another delegate.
|
|
|
| object ()=default |
| Create a new instance of the ultimate base class object.
|
|
bool | equals (const object &obj) const noexcept |
| Determines whether the specified object is equal to the current object.
|
|
virtual size_t | get_hash_code () const noexcept |
| Serves as a hash function for a particular type.
|
|
virtual type_object | get_type () const noexcept |
| Gets the type of the current instance.
|
|
template<typename object_t > |
std::unique_ptr< object_t > | memberwise_clone () const noexcept |
| Creates a shallow copy of the current object.
|
|
virtual xtd::ustring | to_string () const noexcept |
| Returns a sxd::ustring that represents the current object.
|
|
virtual bool | equals (const delegate< result_t(arguments_t...)> &) const noexcept=0 |
| Indicates whether the current object is equal to another object of the same type.
|
|
static bool | equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are considered equal.
|
|
static bool | reference_equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are the same instance.
|
|
◆ function_t
template<typename result_t , typename... arguments_t>
using xtd::delegate< result_t(arguments_t...)>::function_t = std::function <result_t(arguments_t...)> |
◆ no_arguments_function_t
template<typename result_t , typename... arguments_t>
using xtd::delegate< result_t(arguments_t...)>::no_arguments_function_t = std::function <result_t()> |
no_arguments_function_t pointer type
◆ delegate() [1/4]
template<typename result_t , typename... arguments_t>
xtd::delegate< result_t(arguments_t...)>::delegate |
( |
| ) |
|
|
default |
Initializes an empty delegate.
◆ delegate() [2/4]
template<typename result_t , typename... arguments_t>
xtd::delegate< result_t(arguments_t...)>::delegate |
( |
const function_t & |
function | ) |
|
|
inlinenoexcept |
Initializes a delegate that invokes the specified instance method.
- Parameters
-
function | the method instance. |
◆ delegate() [3/4]
template<typename result_t , typename... arguments_t>
template<typename object1_t , typename object2_t >
xtd::delegate< result_t(arguments_t...)>::delegate |
( |
const object1_t & |
object, |
|
|
result_t(object2_t::*)() const |
method |
|
) |
| |
|
inlinenoexcept |
Initializes a delegate that invokes the specified instance method on the specified class instance.
- Parameters
-
object | the class instance. |
function | the method instance. |
◆ delegate() [4/4]
template<typename result_t , typename... arguments_t>
template<typename object1_t , typename object2_t >
xtd::delegate< result_t(arguments_t...)>::delegate |
( |
const object1_t & |
object, |
|
|
result_t(object2_t::*)() |
method |
|
) |
| |
|
inlinenoexcept |
Initializes a delegate that invokes the specified instance method on the specified class instance.
- Parameters
-
object | the class instance. |
function | the method instance. |
◆ begin_invoke() [1/3]
template<typename result_t , typename... arguments_t>
async_result xtd::delegate< result_t(arguments_t...)>::begin_invoke |
( |
arguments_t... |
arguments | ) |
|
Executes the method represented by the current delegate asynchronously on the thread that the control's underlying handle was created on.
- Parameters
-
async_callback | The asynchronous callback that will be called at the end of the invocation. |
async_state | The asynchronous state associated with the invocation. |
arguments | The parameter list. |
- Returns
- An async_result_invoke that represents the result of the begin_invoke operation.
- Examples
- The following examples shows hot tu use xtd::delegate::begin_invoke, xtd::delegate::end_invoke, xtd::delegate::invoke methods.
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/delegate>
auto main()->int {
console::write_line(
"(Thread {}) Hello {}!", thread::current_thread().managed_thread_id(), name);
return name == "xtd" ? 42 : 24;
}};
auto result =
d1.begin_invoke(
"Gammasoft");
}
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.h:10
◆ begin_invoke() [2/3]
template<typename result_t , typename... arguments_t>
Executes the method represented by the current delegate asynchronously on the thread that the control's underlying handle was created on.
- Parameters
-
async_callback | The asynchronous callback that will be called at the end of the invocation. |
arguments | The parameter list. |
- Returns
- An async_result_invoke that represents the result of the begin_invoke operation.
- Examples
- The following examples shows hot tu use xtd::delegate::begin_invoke, xtd::delegate::end_invoke, xtd::delegate::invoke methods.
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/delegate>
auto main()->int {
console::write_line(
"(Thread {}) Hello {}!", thread::current_thread().managed_thread_id(), name);
return name == "xtd" ? 42 : 24;
}};
auto result =
d1.begin_invoke(
"Gammasoft");
}
◆ begin_invoke() [3/3]
template<typename result_t , typename... arguments_t>
Executes the method represented by the current delegate asynchronously on the thread that the control's underlying handle was created on.
- Parameters
-
arguments | The parameter list. |
- Returns
- An async_result_invoke that represents the result of the begin_invoke operation.
- Examples
- The following examples shows hot tu use xtd::delegate::begin_invoke, xtd::delegate::end_invoke, xtd::delegate::invoke methods.
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/delegate>
auto main()->int {
console::write_line(
"(Thread {}) Hello {}!", thread::current_thread().managed_thread_id(), name);
return name == "xtd" ? 42 : 24;
}};
auto result =
d1.begin_invoke(
"Gammasoft");
}
◆ combine() [1/2]
template<typename result_t , typename... arguments_t>
static delegate xtd::delegate< result_t(arguments_t...)>::combine |
( |
const delegate< result_t(arguments_t...)> & |
a, |
|
|
const delegate< result_t(arguments_t...)> & |
b |
|
) |
| |
|
inlinestaticnoexcept |
Concatenates the invocation lists of two delegates.
- Parameters
-
a | The delegate whose invocation list comes first. |
b | The delegate whose invocation list comes second. |
- Returns
- delegateType A new delegate with an invocation list that concatenates the invocation lists of a and b in that order. Returns a if b is null, returns b if a is a null reference, and returns a null reference if both a and b are null references.
◆ combine() [2/2]
template<typename result_t , typename... arguments_t>
static delegate xtd::delegate< result_t(arguments_t...)>::combine |
( |
const std::vector< delegate< result_t(arguments_t...)> > & |
delegates | ) |
|
|
inlinestaticnoexcept |
Concatenates the invocation lists of an array of delegates.
- Parameters
-
delegates | The array of delegates to combine. |
- Returns
- Delegate A new delegate with an invocation list that concatenates the invocation lists of the delegates in the delegates array. Returns null if delegates is null, if delegates contains zero elements, || if every entry in delegates is null.
◆ end_invoke()
template<typename result_t , typename... arguments_t>
result_t xtd::delegate< result_t(arguments_t...)>::end_invoke |
( |
async_result |
async | ) |
|
Retrieves the return value of the asynchronous operation represented by the async_result_invoke passed.
- Parameters
-
async | The async_result_invoke that represents a specific invoke asynchronous operation, returned when calling begin_invoke. |
- Examples
- The following examples shows hot tu use xtd::delegate::begin_invoke, xtd::delegate::end_invoke, xtd::delegate::invoke methods.
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/delegate>
auto main()->int {
console::write_line(
"(Thread {}) Hello {}!", thread::current_thread().managed_thread_id(), name);
return name == "xtd" ? 42 : 24;
}};
auto result =
d1.begin_invoke(
"Gammasoft");
}
◆ equals()
template<typename result_t , typename... arguments_t>
bool xtd::delegate< result_t(arguments_t...)>::equals |
( |
const delegate< result_t(arguments_t...)> & |
delegate | ) |
const |
|
inlineoverridenoexcept |
Determines whether this instance and another specified delegateType object have the same value.
- Parameters
-
value | The delegateType to compare. |
- Returns
- bool true if the value of this instance is the same as the value of value; otherwise, false.
◆ functions()
template<typename result_t , typename... arguments_t>
const std::vector< function_t > & xtd::delegate< result_t(arguments_t...)>::functions |
( |
| ) |
const |
|
inline |
Gets the delegates array.
- Returns
- The delegates array.
◆ invoke()
template<typename result_t , typename... arguments_t>
result_t xtd::delegate< result_t(arguments_t...)>::invoke |
( |
arguments_t... |
arguments | ) |
const |
|
inline |
invokes the method represented by the current delegate.
- Parameters
-
arguments | The parameter list. |
- Returns
- result_t The return value.
- Examples
- The following examples shows hot tu use xtd::delegate::begin_invoke, xtd::delegate::end_invoke, xtd::delegate::invoke methods.
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/delegate>
auto main()->int {
console::write_line(
"(Thread {}) Hello {}!", thread::current_thread().managed_thread_id(), name);
return name == "xtd" ? 42 : 24;
}};
auto result =
d1.begin_invoke(
"Gammasoft");
}
◆ is_empty()
template<typename result_t , typename... arguments_t>
bool xtd::delegate< result_t(arguments_t...)>::is_empty |
( |
| ) |
const |
|
inlinenoexcept |
Return if the delegate is empty.
- Returns
- bool Return true if delegate is empty; otherwise false.
◆ no_arguments_functions()
template<typename result_t , typename... arguments_t>
const std::vector< no_arguments_function_t > & xtd::delegate< result_t(arguments_t...)>::no_arguments_functions |
( |
| ) |
const |
|
inline |
Gets the no arguments delegates array.
- Returns
- The delegates array.
◆ operator()()
template<typename result_t , typename... arguments_t>
result_t xtd::delegate< result_t(arguments_t...)>::operator() |
( |
arguments_t... |
arguments | ) |
const |
|
inline |
invokes the method represented by the current delegate.
- Parameters
-
arguments | The parameter list. |
- Returns
- result_t The return value.
◆ remove()
template<typename result_t , typename... arguments_t>
static delegate xtd::delegate< result_t(arguments_t...)>::remove |
( |
const delegate< result_t(arguments_t...)> & |
source, |
|
|
const delegate< result_t(arguments_t...)> & |
value |
|
) |
| |
|
inlinestaticnoexcept |
removes the last occurrence of the invocation list of a delegate from the invocation list of another delegate.
- Parameters
-
source | The delegate from which to remove the invocation list of value. |
value | The delegate that supplies the invocation list to remove from the invocation list of source. |
- Returns
- delegate A new delegate with an invocation list formed by taking the invocation list of source and removing the last occurrence of the invocation list of value, if the invocation list of value is found within the invocation list of source. Returns source if value is null || if the invocation list of value is ! found within the invocation list of source. Returns a null reference if the invocation list of value is equal to the invocation list of source || if source is a null reference.
◆ remove_all()
template<typename result_t , typename... arguments_t>
static delegate xtd::delegate< result_t(arguments_t...)>::remove_all |
( |
const delegate< result_t(arguments_t...)> & |
source, |
|
|
const delegate< result_t(arguments_t...)> & |
value |
|
) |
| |
|
inlinestaticnoexcept |
removes all occurrences of the invocation list of a delegate from the invocation list of another delegate.
- Parameters
-
source | The delegate from which to remove the invocation list of value. |
value | The delegate that supplies the invocation list to remove from the invocation list of source. |
- Returns
- delegate A new delegate with an invocation list formed by taking the invocation list of source && removing all occurrences of the invocation list of value, if the invocation list of value is found within the invocation list of source. Returns source if value is null || if the invocation list of value is ! found within the invocation list of source. Returns a null reference if the invocation list of value is equal to the invocation list of source, if source contains only a series of invocation lists that are equal to the invocation list of value, || if source is a null reference.
◆ size()
template<typename result_t , typename... arguments_t>
size_t xtd::delegate< result_t(arguments_t...)>::size |
( |
| ) |
const |
|
inlinenoexcept |
Return the size of invocation list.
- Returns
- Return the size of invocation list.
The documentation for this class was generated from the following file: