From a4127441a620955e34b40fa44f5dee6638dcf935 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 10 Aug 2015 15:44:15 +1000 Subject: [PATCH] tuple: add function caller with argument unpacking --- tuple.hpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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 <