changed return from choice to const ref

This commit is contained in:
Bob Polis 2021-12-02 18:14:34 +01:00
parent 94043b3aac
commit 145a056a3b

View File

@ -26,13 +26,13 @@ namespace sc {
static double double_between(double from, double to); static double double_between(double from, double to);
template <typename T> template <typename T>
static T choice(const std::vector<T>& vec) { static const T& choice(const std::vector<T>& vec) {
std::uniform_int_distribution<int> dist {0, static_cast<int>(vec.size()) - 1}; std::uniform_int_distribution<int> dist {0, static_cast<int>(vec.size()) - 1};
return vec[dist(instance()._reng)]; return vec[dist(instance()._reng)];
} }
template <typename T, typename Iter> template <typename T, typename Iter>
static T choice(Iter from, Iter to) { static const T& choice(Iter from, Iter to) {
std::uniform_int_distribution<int> dist {0, static_cast<int>(to - from) - 1}; std::uniform_int_distribution<int> dist {0, static_cast<int>(to - from) - 1};
return *(from + dist(instance()._reng)); return *(from + dist(instance()._reng));
} }