Skip to content

Commit

Permalink
fix: use random_shuffle
Browse files Browse the repository at this point in the history
`random_shuffle` was removed in C++17, however, we're using C++11 here, so there should be no harm.
  • Loading branch information
Panquesito7 committed May 26, 2023
1 parent 2202ea1 commit 8cd0a77
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions games/memory_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* biggest table size and hardest mode. The bigger the size, **the more letters are available**.
*
* @author [David Leal](https://github.com/Panquesito7)
*/
*/

#include <iostream> /// for IO operations
#include <ctime> /// for std::time()
Expand All @@ -25,19 +25,6 @@
#include <unistd.h> /// for sleep
#endif

// `std::random_shuffle` was deprecated in C++14. To keep support with most compilers, we need to check the C++ version.
#if __cplusplus >= 201402L
template <typename T>
constexpr auto SHUFFLE(T a, T b) -> void {
return std::shuffle(a, b, std::mt19937(std::random_device()()));
}
#else
template <typename T>
constexpr auto SHUFFLE(T a, T b) -> void {
return std::random_shuffle(a, b);
}
#endif

/**
* @namespace
* @brief (Mini)game implementations.
Expand Down Expand Up @@ -95,7 +82,7 @@ void init(std::vector<T> *table) {
pairs.push_back(letter);
}

SHUFFLE(pairs.begin(), pairs.end());
std::random_shuffle(pairs.begin(), pairs.end());

for (int i = 0; i < (*table).size(); i++) {
(*table)[i] = pairs[i];
Expand Down

0 comments on commit 8cd0a77

Please sign in to comment.