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:
Daniela Engert
2017-04-22 17:13:39 +02:00
parent f14719c3a9
commit 8ae18ae455
3 changed files with 25 additions and 12 deletions

View File

@ -8,7 +8,7 @@
#include <vector>
#include <iostream>
#if __cplusplus >= 201103L
#if (__cplusplus >= 201103L) || defined(BOOST_NO_CXX98_RANDOM_SHUFFLE)
#include <random>
std::default_random_engine gen;
@ -34,7 +34,7 @@ void check_sequence ( Iter first, Iter last, Iter sf, Iter sl )
// }
// if (sl == last) std::cout << "<";
// std::cout << '\n';
if (sf == sl) return;
for (Iter i = first; i < sf; ++i)
BOOST_CHECK(*i < *sf);
@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE( test_main )
std::vector<int> v;
for ( int i = 0; i < 10; ++i )
v.push_back(i);
const std::vector<int>::iterator b = v.begin();
ba::partition_subrange(b, v.end(), b + 3, b + 6);
check_sequence (b, v.end(), b + 3, b + 6);
@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE( test_main )
// BOOST_CHECK_EQUAL(v[3], 3);
// BOOST_CHECK_EQUAL(v[4], 4);
// BOOST_CHECK_EQUAL(v[5], 5);
// Mix them up and try again - single element
do_shuffle(v.begin(), v.end());
ba::partition_subrange(b, v.end(), b + 7, b + 8);
@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE( test_main )
std::vector<int> v;
for ( int i = 0; i < 10; ++i )
v.push_back(i);
const std::vector<int>::iterator b = v.begin();
ba::partition_subrange(b, v.end(), b + 3, b + 6, std::greater<int>());
check_sequence (b, v.end(), b + 3, b + 6, std::greater<int>());