mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-09-02 02:37:55 +00:00
Fix UB when sorting empty vecs
This commit is contained in:
2
game.cpp
2
game.cpp
@@ -44,7 +44,7 @@ EX int hrand(int i) {
|
||||
#if HDR
|
||||
template<class T, class... U> T pick(T x, U... u) { std::initializer_list<T> i = {x,u...}; return *(i.begin() + hrand(1+sizeof...(u))); }
|
||||
template<class T> void hrandom_shuffle(T* x, int n) { for(int k=1; k<n; k++) swap(x[k], x[hrand(k+1)]); }
|
||||
template<class T> void hrandom_shuffle(T& container) { hrandom_shuffle(&container[0], isize(container)); }
|
||||
template<class T> void hrandom_shuffle(T& container) { hrandom_shuffle(container.data(), isize(container)); }
|
||||
template<class U> auto hrand_elt(U& container) -> decltype(container[0]) { return container[hrand(isize(container))]; }
|
||||
template<class T, class U> T hrand_elt(U& container, T default_value) {
|
||||
if(container.empty()) return default_value;
|
||||
|
Reference in New Issue
Block a user