Fix random::uniform_from to work with rvalue containers and return types
This commit is contained in:
parent
1f1612f7e6
commit
e304b09f9f
1 changed files with 2 additions and 2 deletions
|
|
@ -56,9 +56,9 @@ namespace psemek::random
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename RNG, typename Container>
|
template <typename RNG, typename Container>
|
||||||
auto & uniform_from(RNG && rng, Container & container)
|
decltype(auto) uniform_from(RNG && rng, Container && container)
|
||||||
{
|
{
|
||||||
if (container.empty())
|
if (container.size() == 0)
|
||||||
throw std::runtime_error("cannot sample from empty container");
|
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(container.begin(), uniform<std::size_t>(rng, 0, container.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue