tuple: add function caller with argument unpacking

This commit is contained in:
Danny Robson 2015-08-10 15:44:15 +10:00
parent 840b930e8d
commit a4127441a6

View File

@ -22,6 +22,7 @@
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#include <functional>
namespace util { namespace tuple { namespace util { namespace tuple {
@ -65,6 +66,36 @@ namespace util { namespace tuple {
{ return for_type<decltype(t)> (f); } { return for_type<decltype(t)> (f); }
///////////////////////////////////////////////////////////////////////////
// unpack a tuple as function arguments
namespace detail {
template <
typename Func,
typename ...Args,
size_t ...I
>
auto
call (const Func &func, std::tuple<Args...> args, indices<I...>)
{
// quiet unused variable warning with zero args
(void)args;
// XXX: Use `std::invoke' when gcc catches up with c++17
return func (std::get<I> (args)...);
}
}
template <
typename Func,
typename ...Args
>
auto
call (const Func &func, std::tuple<Args...> args)
{
return detail::call (func, args, typename make_indices<sizeof...(Args)>::type {});
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/// call a provided object with each value in a tuple /// call a provided object with each value in a tuple
template < template <