diff --git a/tuple.hpp b/tuple.hpp index 0eaa3111..7104072b 100644 --- a/tuple.hpp +++ b/tuple.hpp @@ -22,6 +22,7 @@ #include #include +#include namespace util { namespace tuple { @@ -65,6 +66,36 @@ namespace util { namespace tuple { { return for_type (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, indices) + { + // quiet unused variable warning with zero args + (void)args; + + // XXX: Use `std::invoke' when gcc catches up with c++17 + return func (std::get (args)...); + } + } + + template < + typename Func, + typename ...Args + > + auto + call (const Func &func, std::tuple args) + { + return detail::call (func, args, typename make_indices::type {}); + } + + /////////////////////////////////////////////////////////////////////////// /// call a provided object with each value in a tuple template <