diff --git a/include/Nazara/Core/Algorithm.hpp b/include/Nazara/Core/Algorithm.hpp index 26c9efbcf..ba9a31c8b 100644 --- a/include/Nazara/Core/Algorithm.hpp +++ b/include/Nazara/Core/Algorithm.hpp @@ -11,8 +11,8 @@ #include #include +template auto NzApply(F&& fn, Tuple&& t); template void NzHashCombine(std::size_t& seed, const T& v); -template void NzUnpackTuple(F func, const std::tuple& t); #include diff --git a/include/Nazara/Core/Algorithm.inl b/include/Nazara/Core/Algorithm.inl index 1fa2a9032..fb393fcf9 100644 --- a/include/Nazara/Core/Algorithm.inl +++ b/include/Nazara/Core/Algorithm.inl @@ -8,27 +8,20 @@ #include -///TODO: Améliorer l'implémentation de UnpackTuple - -template -struct NzImplTupleUnpack +// http://www.cppsamples.com/common-tasks/apply-tuple-to-function.html +template +auto NzApplyImpl(F&& fn, Tuple&& t, std::index_sequence) { - template - void operator()(F func, const std::tuple& t, Args&... args) - { - NzImplTupleUnpack()(func, t, std::get(t), args...); - } -}; + return std::forward(fn)(std::get(std::forward(t))...); +} -template<> -struct NzImplTupleUnpack<0> +template +auto NzApply(F&& fn, Tuple&& t) { - template - void operator()(F func, const std::tuple&, Args&... args) - { - func(args...); - } -}; + std::size_t constexpr tSize = std::tuple_size::type>::value; + + return NzApplyImpl(std::forward(fn), std::forward(t), std::make_index_sequence()); +} // Algorithme venant de CityHash par Google // http://stackoverflow.com/questions/8513911/how-to-create-a-good-hash-combine-with-64-bit-output-inspired-by-boosthash-co @@ -47,10 +40,4 @@ void NzHashCombine(std::size_t& seed, const T& v) seed = static_cast(b * kMul); } -template -void NzUnpackTuple(F func, const std::tuple& t) -{ - NzImplTupleUnpack()(func, t); -} - #include diff --git a/include/Nazara/Core/Functor.inl b/include/Nazara/Core/Functor.inl index bdc4bc1f9..df9f4b8e4 100644 --- a/include/Nazara/Core/Functor.inl +++ b/include/Nazara/Core/Functor.inl @@ -26,7 +26,7 @@ m_args(std::forward(args)...) template void NzFunctorWithArgs::Run() { - NzUnpackTuple(m_func, m_args); + NzApply(m_func, m_args); }