SYNOPSIS top
Creating and defining
Creating and defining
omni::delegate
types can get quite verbose when dealing with a function with multiple parameters. To alleviate this, you can use this helper macro to define an omni::delegate
with a number of parameters and a specific return type:int function0() { return 42; } int function3(int x, int y, int z) { return (x * y) / z; } int main(int argc, char* argv[]) { // omni::delegate<int> f0 = &function0; omni_delegate(int) f0 = &function0; // omni::delegate3<int, int, int, int> f3 = &function3; omni_delegate(int, int, int, int) f3 = &function3; std::cout << f3(f0(), f0(), f0()) << std::endl; return 0; }
DESCRIPTION top
This helper macro allows you to define an
So that you do not have to specify the specific delegate type, you can use the omni_delegate helper macro to define the correct
You can even use the macro in
This helper macro allows you to define an
omni::delegate
of any parameter length without having to specify the specific omni::delegate
type. In other words, usually one would have to define an omni::delegate
with 2 parameter types by declaring it as such omni::delegate2
<void, int, int> additionally, one would have to define an omni::delegate
that takes 1 parameter as such omni::delegate1
<void, int> this is true for any of the omni::delegate
types up to 16 parameters.So that you do not have to specify the specific delegate type, you can use the omni_delegate helper macro to define the correct
omni::delegate
type without having to be specific each time, reducing code and confusion.int function0() { return 42; } int function3(int x, int y, int z) { return (x * y) / z; } int main(int argc, char* argv[]) { // omni::delegate<int> f0 = &function0; omni_delegate(int) f0 = &function0; // omni::delegate3<int, int, int, int> f3 = &function3; omni_delegate(int, int, int, int) f3 = &function3; std::cout << f3(f0(), f0(), f0()) << std::endl; return 0; }
typedef
definitions:typedef omni_delegate(int, int, int, int) functor3; typedef omni_delegate(int) functor1; int function0() { return 42; } int function3(int x, int y, int z) { return (x * y) / z; } int main(int argc, char* argv[]) { functor1 f1 = &function1; functor3 f3 = &function3; std::cout << f3(f1(), f1(), f1()) << std::endl; return 0; }