Provides support for functional programming. More...
Modules | |
Function objects submodule | |
Provides function objects to use. | |
Functions | |
template<typename First , typename... Rest> | |
constexpr detail::Composer < First, Rest...> | gears::functional::compose (First &&f, Rest &&...args) |
Function composition of functions. More... | |
template<typename Function , typename... Args> | |
constexpr curry_type< Function, detail::SpecialDecay< Args >...> | gears::functional::curry (Function &&f, Args &&...args) |
Applies function currying to functions. More... | |
template<typename... Args> | |
constexpr Result | gears::functional::invoke (Args &&...args) noexcept(NoExcept) |
Implements the INVOKE facility in the C++ standard. More... | |
This module provides multiple function objects (also called functors) and operations that make working in a functional manner easier.
All of the function objects have a constexpr
instantiation to allow working with the other components of the module easier. It also allows the user to use the function objects just like a regular function.
There's also basic support for currying and composition. More support for other things are coming soon.
Example usage:
Output:
1
constexpr detail::Composer<First, Rest...> gears::functional::compose | ( | First && | f, |
Rest &&... | args | ||
) |
Enables function composition of multiple functions. Note that the syntax goes left to right, so for example:
would be equivalent to f(g(h()))
f | First function to compose |
args | Rest of the functions to compose |
Definition at line 82 of file compose.hpp.
constexpr curry_type<Function, detail::SpecialDecay<Args>...> gears::functional::curry | ( | Function && | f, |
Args &&... | args | ||
) |
Curries functions together. More info on what currying is can be found here.
Example:
Output
15 20
f | First function to curry |
args | Rest of the functions to curry |
|
noexcept |
The INVOKE
facility in the standard is specified in §20.8.2 as follows:
Define INVOKE (f, t1, t2, ..., tN) as follows: — (t1.*f)(t2, ..., tN) when f is a pointer to a member function of a class T and t1 is an object of type T or a reference to an object of type T or a reference to an object of a type derived from T; — ((*t1).*f)(t2, ..., tN) when f is a pointer to a member function of a class T and t1 is not one of the types described in the previous item; — t1.*f when N == 1 and f is a pointer to member data of a class T and t1 is an object of type T or a reference to an object of type T or a reference to an object of a type derived from T; — (*t1).*f when N == 1 and f is a pointer to member data of a class T and t1 is not one of the types described in the previous item; — f(t1, t2, ..., tN) in all other cases.
t | arguments to pass to INVOKE facility. |
Definition at line 85 of file invoke.hpp.