Fixed compile error under VS2015 /c++:latest, caused by using random_shuffle

Now if we detect C++11 compiler, or MSVC in version corresponding to VS2015,
we switch from using `std::random_shuffle` to `std::shuffle`.

`std::random_shuffle` was officially deprecated in C++14, and removed in C++17.

Also removed guarded inclusion of `<random>` header, as there was nothing
in the header that used it.
This commit is contained in:
Martin Hořeňovský 2017-01-07 12:58:01 +01:00
parent b50572bbfd
commit 6991549457
2 changed files with 9 additions and 6 deletions

View File

@ -115,6 +115,7 @@
#if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015)) #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
#define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT #define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
#define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS #define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
#define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
#endif #endif
#endif // _MSC_VER #endif // _MSC_VER
@ -180,7 +181,9 @@
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) # if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
# endif # endif
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE)
# define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
# endif
#endif // __cplusplus >= 201103L #endif // __cplusplus >= 201103L
@ -215,6 +218,9 @@
#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
# define CATCH_CONFIG_COUNTER # define CATCH_CONFIG_COUNTER
#endif #endif
#if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11)
# define CATCH_CONFIG_CPP11_SHUFFLE
#endif
#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS

View File

@ -19,9 +19,6 @@
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#ifdef CATCH_CPP14_OR_GREATER
#include <random>
#endif
namespace Catch { namespace Catch {
@ -30,7 +27,7 @@ namespace Catch {
result_type operator()( result_type n ) const { return std::rand() % n; } result_type operator()( result_type n ) const { return std::rand() % n; }
#ifdef CATCH_CPP14_OR_GREATER #ifdef CATCH_CONFIG_CPP11_SHUFFLE
static constexpr result_type min() { return 0; } static constexpr result_type min() { return 0; }
static constexpr result_type max() { return 1000000; } static constexpr result_type max() { return 1000000; }
result_type operator()() const { return std::rand() % max(); } result_type operator()() const { return std::rand() % max(); }
@ -38,7 +35,7 @@ namespace Catch {
template<typename V> template<typename V>
static void shuffle( V& vector ) { static void shuffle( V& vector ) {
RandomNumberGenerator rng; RandomNumberGenerator rng;
#ifdef CATCH_CPP14_OR_GREATER #ifdef CATCH_CONFIG_CPP11_SHUFFLE
std::shuffle( vector.begin(), vector.end(), rng ); std::shuffle( vector.begin(), vector.end(), rng );
#else #else
std::random_shuffle( vector.begin(), vector.end(), rng ); std::random_shuffle( vector.begin(), vector.end(), rng );