template <typename Res, typename... ArgTypes>
class Function<Res(ArgTypes...)> : private Moveable<Function<Res(ArgTypes...)>>
Upp::Function is wrapper to represent callable operation. It is similar to std::function with two differences:
Calling empty Function is allowed (and NOP). Returns zero.
Functions can be combined (chained) using operator<<.
Function()
Function(const Nuller&)
Creates empty Function. Invoking empty function is NOP and eventual return value is Res() (which results in 0 for fundamental types). Variant with Nuller is useful when defining function declaration with optional Function parameters like void Foo(Function<void ()> = Null);
template <class F> Function(F fn)
This is the 'catch lambda' constructor which allows converting generic lambda to Function value.
Function(const Function& src)
Function& operator=(const Function& src)
Function(Function&& src)
Function& operator=(Function&& src)
Usual copy/move constructors and assignment operators.
Function Proxy() const
Returns a new Function, which, when invoked, invokes this Function. This is useful when some Function is to changed later, but we need another Function to represent it.
template <class F> Function& operator<<(F fn)
Function& operator<<(const Function& fn)
Function& operator<<(Function&& fn)
These operators combine two Functions or function with lambda. Original 'this' function is invoked first and then fn. If either of Functions returns value, value of fn (argument to the right of <<) represents the value of whole Function.
Res operator()(ArgTypes... args) const
Performs the Functions.
operator bool() const
Returns true if Function is not empty.
void Clear()
Sets Function empty.
Two most common types of Function in U++ are those that return 'void' and those that return 'bool'. U++ defines two convenience template aliases:
template <typename... ArgTypes> using Event = Function<void (ArgTypes...)>
Creates alias for Function returning void. For example, Event<int, String> is equivalent of Function<void (int, String)>.
template <typename... ArgTypes> using Gate = Function<bool (ArgTypes...)>
Creates alias for Function returning bool. For example, Gate<int, String> is equivalent of Function<bool (int, String)>. Note that empty Gate returns false (because empty Function returns bool(0), which is false).
Despide the power of C++11, there are still situations where it is better to put the callable code into member function. C++11 lamda syntax can be tedious in that case. MemFn template function and THISFN serve to reduce typing overhead.
template <class Ptr, class Class, class Res, class... ArgTypes> Event<ArgTypes...> MemFn(Ptr object, Res (Class::*member_function)(ArgTypes...))
Equivalent of std::mem_fn returning U++ Function. Creates Function that represents calling member_function of instance object.
THISFN(x)
This macro is defined a MemFn(this, &CLASSNAME::x).
|