forked from boostorg/algorithm
Conditionally replace deprecated c++98 features by c++11 ones
change std::random_shuffle -> std::shuffle + random_engine if indicated by the supported language level or Boost configuration macro. Signed-off-by: Daniela Engert <dani@ngrt.de>
This commit is contained in:
@ -20,6 +20,19 @@
|
|||||||
#define BOOST_TEST_MAIN
|
#define BOOST_TEST_MAIN
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#if (__cplusplus >= 201103L) || defined(BOOST_NO_CXX98_RANDOM_SHUFFLE)
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
std::default_random_engine gen;
|
||||||
|
template<typename RandomIt>
|
||||||
|
void do_shuffle(RandomIt first, RandomIt last)
|
||||||
|
{ std::shuffle(first, last, gen); }
|
||||||
|
#else
|
||||||
|
template<typename RandomIt>
|
||||||
|
void do_shuffle(RandomIt first, RandomIt last)
|
||||||
|
{ std::random_shuffle(first, last); }
|
||||||
|
#endif
|
||||||
|
|
||||||
class custom {
|
class custom {
|
||||||
int m_x;
|
int m_x;
|
||||||
friend bool operator<(custom const& x, custom const& y);
|
friend bool operator<(custom const& x, custom const& y);
|
||||||
@ -183,7 +196,7 @@ void test_minmax(CIterator first, CIterator last, int n)
|
|||||||
|
|
||||||
template <class Container, class Iterator, class Value>
|
template <class Container, class Iterator, class Value>
|
||||||
void test_container(Iterator first, Iterator last, int n,
|
void test_container(Iterator first, Iterator last, int n,
|
||||||
Container* dummy = 0
|
Container* /* dummy */ = 0
|
||||||
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Value) )
|
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Value) )
|
||||||
{
|
{
|
||||||
Container c(first, last);
|
Container c(first, last);
|
||||||
@ -223,7 +236,7 @@ void test(int n BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Value))
|
|||||||
test_range(first, last, n);
|
test_range(first, last, n);
|
||||||
|
|
||||||
// Populate test vector with random values
|
// Populate test vector with random values
|
||||||
std::random_shuffle(first, last);
|
do_shuffle(first, last);
|
||||||
test_range(first, last, n);
|
test_range(first, last, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#if __cplusplus >= 201103L
|
#if (__cplusplus >= 201103L) || defined(BOOST_NO_CXX98_RANDOM_SHUFFLE)
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
std::default_random_engine gen;
|
std::default_random_engine gen;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#if __cplusplus >= 201103L
|
#if (__cplusplus >= 201103L) || defined(BOOST_NO_CXX98_RANDOM_SHUFFLE)
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
std::default_random_engine gen;
|
std::default_random_engine gen;
|
||||||
|
Reference in New Issue
Block a user