Support random::uniform_from with initializer_list
This commit is contained in:
parent
8e89679219
commit
d5abbb4762
1 changed files with 7 additions and 1 deletions
|
|
@ -9,7 +9,7 @@
|
|||
#include <psemek/util/exception.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
#include <stdexcept>
|
||||
#include <initializer_list>
|
||||
|
||||
namespace psemek::random
|
||||
{
|
||||
|
|
@ -71,4 +71,10 @@ namespace psemek::random
|
|||
return *std::next(begin(container), uniform<std::size_t>(rng, 0, size(container) - 1));
|
||||
}
|
||||
|
||||
template <typename RNG, typename T>
|
||||
decltype(auto) uniform_from(RNG && rng, std::initializer_list<T> const & list)
|
||||
{
|
||||
return *(list.begin() + uniform<std::size_t>(rng, 0, list.size() - 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue