Core/Algorithm: Replace UnpackTuple by Apply
Former-commit-id: dccf9a102e4287035184053e1d60abc0edaf1a1d
This commit is contained in:
parent
4d5cea8afe
commit
481a191693
|
|
@ -11,8 +11,8 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
|
template<typename F, typename Tuple> auto NzApply(F&& fn, Tuple&& t);
|
||||||
template<typename T> void NzHashCombine(std::size_t& seed, const T& v);
|
template<typename T> void NzHashCombine(std::size_t& seed, const T& v);
|
||||||
template<typename F, typename... ArgsT> void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t);
|
|
||||||
|
|
||||||
#include <Nazara/Core/Algorithm.inl>
|
#include <Nazara/Core/Algorithm.inl>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,27 +8,20 @@
|
||||||
|
|
||||||
#include <Nazara/Core/Debug.hpp>
|
#include <Nazara/Core/Debug.hpp>
|
||||||
|
|
||||||
///TODO: Améliorer l'implémentation de UnpackTuple
|
// http://www.cppsamples.com/common-tasks/apply-tuple-to-function.html
|
||||||
|
template<typename F, typename Tuple, size_t ...S >
|
||||||
template<unsigned int N>
|
auto NzApplyImpl(F&& fn, Tuple&& t, std::index_sequence<S...>)
|
||||||
struct NzImplTupleUnpack
|
|
||||||
{
|
{
|
||||||
template <typename F, typename... ArgsT, typename... Args>
|
return std::forward<F>(fn)(std::get<S>(std::forward<Tuple>(t))...);
|
||||||
void operator()(F func, const std::tuple<ArgsT...>& t, Args&... args)
|
|
||||||
{
|
|
||||||
NzImplTupleUnpack<N-1>()(func, t, std::get<N-1>(t), args...);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
template<typename F, typename Tuple>
|
||||||
struct NzImplTupleUnpack<0>
|
auto NzApply(F&& fn, Tuple&& t)
|
||||||
{
|
{
|
||||||
template <typename F, typename... ArgsT, typename... Args>
|
std::size_t constexpr tSize = std::tuple_size<typename std::remove_reference<Tuple>::type>::value;
|
||||||
void operator()(F func, const std::tuple<ArgsT...>&, Args&... args)
|
|
||||||
{
|
return NzApplyImpl(std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>());
|
||||||
func(args...);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
// Algorithme venant de CityHash par Google
|
// 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
|
// 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<std::size_t>(b * kMul);
|
seed = static_cast<std::size_t>(b * kMul);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F, typename... ArgsT>
|
|
||||||
void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t)
|
|
||||||
{
|
|
||||||
NzImplTupleUnpack<sizeof...(ArgsT)>()(func, t);
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Nazara/Core/DebugOff.hpp>
|
#include <Nazara/Core/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ m_args(std::forward<Args>(args)...)
|
||||||
template<typename F, typename... Args>
|
template<typename F, typename... Args>
|
||||||
void NzFunctorWithArgs<F, Args...>::Run()
|
void NzFunctorWithArgs<F, Args...>::Run()
|
||||||
{
|
{
|
||||||
NzUnpackTuple(m_func, m_args);
|
NzApply(m_func, m_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue