c++-gtk-utils
Functions
tuple

Functions

template<class Func , class... TupleArgs, class... OtherArgs>
auto Cgu::tuple_apply (Func &&func, const std::tuple< TupleArgs...> &t, OtherArgs &&...args) -> typename std::result_of< Func(const TupleArgs &..., OtherArgs &&...)>::type
 
template<class Func , class... TupleArgs, class... OtherArgs>
auto Cgu::tuple_apply (Func &&func, std::tuple< TupleArgs...> &t, OtherArgs &&...args) -> typename std::result_of< Func(TupleArgs &..., OtherArgs &&...)>::type
 
template<class Func , class... TupleArgs, class... OtherArgs>
auto Cgu::tuple_apply (Func &&func, std::tuple< TupleArgs...> &&t, OtherArgs &&...args) -> typename std::result_of< Func(TupleArgs &&..., OtherArgs &&...)>::type
 
template<class Obj , class Ret , class... FuncArgs, class Tuple , class... OtherArgs>
Ret Cgu::tuple_apply (Obj &obj, Ret(Obj::*func)(FuncArgs...), Tuple &&t, OtherArgs &&...args)
 
template<class Obj , class Ret , class... FuncArgs, class Tuple , class... OtherArgs>
Ret Cgu::tuple_apply (const Obj &obj, Ret(Obj::*func)(FuncArgs...) const, Tuple &&t, OtherArgs &&...args)
 

Detailed Description

#include <c++-gtk-utils/param.h>

From version 2.2.10, where this library is compiled with gcc >= 4.8 or clang >= 3.4, the library uses a backend for relevant closure/callback classes using std::tuple (unless that backend is explicitly disabled with the --without-tuple configuration option, in which case the implementation used prior to version 2.2.10 is retained). The tuple backend avoids code duplication and makes for a cleaner implementation, and enables Callback::make() and Callback::make_ref() to take up to 10 bound arguments instead of the previous 5 bound arguments. For compilers other than gcc and clang which adequately support std::tuple, the tuple backend can be manually selected with the --with-tuple configuration option. Both backends are ABI compatible, because for closure/callback implementation this library only exports the CallbackArg pure virtual class.

Where this library has been compiled with the tuple backend for callback classes, it uses the Cgu::tuple_apply() utility function to expand tuples into their component elements in order to pass those elements to functions as arguments on function calls. Because this utility function is of general use, it is made available by the library more generally in the param.h header.

Taking a function with the signature 'int my_func(int, double, int, double)', a tuple could be expanded to apply the my_func() function to it as follows:

int my_func(int, double, int, double);
auto tup = make_tuple(2, 3.0, 4, 5.0);
int res = Cgu::tuple_apply(my_func, tup);

Trailing arguments not comprising part of the tuple can also be passed to the function, so in the above example my_func() could be called as follows:

int my_func(int, double, int, double);
auto tup = make_tuple(2, 3.0);
int res = Cgu::tuple_apply(my_func, tup, 4, 5.0);

Overloads of the tuple_apply() function are provided which can apply any callable object (including a normal function, a static member function, the return value of std::bind() or a lambda expression) to a tuple, or which can apply a const or non-const non-static member function with object to the tuple.

Function Documentation

template<class Func , class... TupleArgs, class... OtherArgs>
auto Cgu::tuple_apply ( Func &&  func,
const std::tuple< TupleArgs...> &  t,
OtherArgs &&...  args 
) -> typename std::result_of<Func(const TupleArgs&..., OtherArgs&&...)>::type

#include <c++-gtk-utils/param.h>

This function expands a tuple and uses the tuple's elements as arguments to a call to a callable object, such as a normal function, a static member function, the return value of std::bind() or a lambda expression.

Parameters
funcThe callable object.
tThe std::tuple object to be expanded.
argsThe trailing arguments (if any) to be used in the function call.
Returns
The result of applying func to the tuple and any trailing arguments.
Note
This function is not available unless either (i) this library is compiled with gcc >= 4.8 or clang >= 3.4, or (ii) the library is compiled by another compiler with appropriate support for C++11 tuples using the --with-tuple configuration option.

Since 2.2.10

template<class Func , class... TupleArgs, class... OtherArgs>
auto Cgu::tuple_apply ( Func &&  func,
std::tuple< TupleArgs...> &  t,
OtherArgs &&...  args 
) -> typename std::result_of<Func(TupleArgs&..., OtherArgs&&...)>::type

#include <c++-gtk-utils/param.h>

This function expands a tuple and uses the tuple's elements as arguments to a call to a callable object, such as a normal function, a static member function, the return value of std::bind() or a lambda expression.

Parameters
funcThe callable object.
tThe std::tuple object to be expanded.
argsThe trailing arguments (if any) to be used in the function call.
Returns
The result of applying func to the tuple and any trailing arguments.
Note
This function is not available unless either (i) this library is compiled with gcc >= 4.8 or clang >= 3.4, or (ii) the library is compiled by another compiler with appropriate support for C++11 tuples using the --with-tuple configuration option.

Since 2.2.10

template<class Func , class... TupleArgs, class... OtherArgs>
auto Cgu::tuple_apply ( Func &&  func,
std::tuple< TupleArgs...> &&  t,
OtherArgs &&...  args 
) -> typename std::result_of<Func(TupleArgs&&..., OtherArgs&&...)>::type

#include <c++-gtk-utils/param.h>

This function expands a tuple and uses the tuple's elements as arguments to a call to a callable object, such as a normal function, a static member function, the return value of std::bind() or a lambda expression.

Parameters
funcThe callable object.
tThe std::tuple object to be expanded.
argsThe trailing arguments (if any) to be used in the function call.
Returns
The result of applying func to the tuple and any trailing arguments.
Note
This function is not available unless either (i) this library is compiled with gcc >= 4.8 or clang >= 3.4, or (ii) the library is compiled by another compiler with appropriate support for C++11 tuples using the --with-tuple configuration option.

Since 2.2.10

template<class Obj , class Ret , class... FuncArgs, class Tuple , class... OtherArgs>
Ret Cgu::tuple_apply ( Obj &  obj,
Ret(Obj::*)(FuncArgs...)  func,
Tuple &&  t,
OtherArgs &&...  args 
)

#include <c++-gtk-utils/param.h>

This function expands a tuple and uses the tuple's elements as arguments to a function call to a non-static class member function.

Parameters
objThe object whose member function is to be called.
funcThe non-static member function to be called.
tThe std::tuple object to be expanded.
argsThe trailing arguments (if any) to be used in the function call.
Returns
The result of applying func to the tuple and any trailing arguments.
Note
This function is not available unless either (i) this library is compiled with gcc >= 4.8 or clang >= 3.4, or (ii) the library is compiled by another compiler with appropriate support for C++11 tuples using the --with-tuple configuration option.

Since 2.2.10

template<class Obj , class Ret , class... FuncArgs, class Tuple , class... OtherArgs>
Ret Cgu::tuple_apply ( const Obj &  obj,
Ret(Obj::*)(FuncArgs...) const  func,
Tuple &&  t,
OtherArgs &&...  args 
)

#include <c++-gtk-utils/param.h>

This function expands a tuple and uses the tuple's elements as arguments to a function call to a non-static class member function.

Parameters
objThe object whose member function is to be called.
funcThe non-static member function to be called.
tThe std::tuple object to be expanded.
argsThe trailing arguments (if any) to be used in the function call.
Returns
The result of applying func to the tuple and any trailing arguments.
Note
This function is not available unless either (i) this library is compiled with gcc >= 4.8 or clang >= 3.4, or (ii) the library is compiled by another compiler with appropriate support for C++11 tuples using the --with-tuple configuration option.

Since 2.2.10