I want to create a random number generation util for C++ and I want to create a method SetSeed
that would generate and set a seed from input variadic arguments.
I have such methods:
void SetSeedDirectly(int seed);
template<typename... Args>
void SetSeed(Args... args);
And the SetSeed
method must generate a seed from args
and call the SetSeedDirectly
method. But I don't know how to generate a seed. I guess that I should use std::hash
to generate a hash(seed) from args.
I know how to get a hash from one value, but not from multiple values.
I've tried to use tuple
:
template <typename... Args>
void SetSeed(Args... args) {
std::tuple<Args...> t(args...);
std::hash<std::tuple<Args...>> h;
size_t seed = h(t);
this->SetSeedDirectly(static_cast<uint32_t>(seed));
}
But for some reason it doesn't work and compiler outputs errors like this:
'std::hash<std::tuple<int,std::string>>::hash(void)': function was implicitly deleted because a base class invokes a deleted or inaccessible function 'std::_Conditionally_enabled_hash<_Kty,false>::_Conditionally_enabled_hash(void)'
Hope for your help! Thanks in advance!