X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d1f1e22acb2e2342b535c3847e804b4a5fee3167..e55e975804ae9c6ec82a5fbac2c7ea2497757a28:/include/xbt/functional.hpp diff --git a/include/xbt/functional.hpp b/include/xbt/functional.hpp index 31f9430ea4..537ba8f9dc 100644 --- a/include/xbt/functional.hpp +++ b/include/xbt/functional.hpp @@ -15,6 +15,7 @@ #include #include +#include namespace simgrid { namespace xbt { @@ -117,6 +118,41 @@ std::function wrapMain(F code, int argc, const char*const* argv) return wrapMain(std::move(code), args(argc, argv)); } +namespace bits { +template +constexpr auto apply(F&& f, Tuple&& t, simgrid::xbt::index_sequence) + -> decltype(std::forward(f)(std::get(std::forward(t))...)) +{ + return std::forward(f)(std::get(std::forward(t))...); +} +} + +/** Call a functional object with the values in the given tuple (from C++17) + * + * @code{.cpp} + * int foo(int a, bool b); + * + * auto args = std::make_tuple(1, false); + * int res = apply(foo, args); + * @encode + **/ +template +constexpr auto apply(F&& f, Tuple&& t) + -> decltype(simgrid::xbt::bits::apply( + std::forward(f), + std::forward(t), + simgrid::xbt::make_index_sequence< + std::tuple_size::type>::value + >())) +{ + return simgrid::xbt::bits::apply( + std::forward(f), + std::forward(t), + simgrid::xbt::make_index_sequence< + std::tuple_size::type>::value + >()); +} + } }