Make random::uniform_from work with raw arrays
This commit is contained in:
parent
2ea0427b0f
commit
9e65c02541
1 changed files with 4 additions and 2 deletions
|
|
@ -62,9 +62,11 @@ namespace psemek::random
|
|||
template <typename RNG, typename Container>
|
||||
decltype(auto) uniform_from(RNG && rng, Container && container)
|
||||
{
|
||||
if (container.size() == 0)
|
||||
using std::size;
|
||||
using std::begin;
|
||||
if (size(container) == 0)
|
||||
throw std::runtime_error("cannot sample from empty container");
|
||||
return *std::next(container.begin(), uniform<std::size_t>(rng, 0, container.size() - 1));
|
||||
return *std::next(begin(container), uniform<std::size_t>(rng, 0, size(container) - 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue