#include <vector>
#include <iostream>
+
+#if __cplusplus >= 201103L
+#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
+
namespace ba = boost::algorithm;
template <typename Iter>
BOOST_CHECK_EQUAL(v[5], 5);
// Mix them up and try again - single element
- std::random_shuffle(v.begin(), v.end());
+ do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b + 7, b + 8);
check_sequence (b, v.end(), b + 7, b + 8);
BOOST_CHECK_EQUAL(v[7], 7);
// Mix them up and try again - at the end
- std::random_shuffle(v.begin(), v.end());
+ do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b + 7, v.end());
check_sequence (b, v.end(), b + 7, v.end());
BOOST_CHECK_EQUAL(v[9], 9);
// Mix them up and try again - at the beginning
- std::random_shuffle(v.begin(), v.end());
+ do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b, b + 2);
check_sequence (b, v.end(), b, b + 2);
BOOST_CHECK_EQUAL(v[1], 1);
// Mix them up and try again - empty subrange
- std::random_shuffle(v.begin(), v.end());
+ do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b, b);
check_sequence (b, v.end(), b, b);
// Mix them up and try again - entire subrange
- std::random_shuffle(v.begin(), v.end());
+ do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b, v.end());
check_sequence (b, v.end(), b, v.end());
}
BOOST_CHECK_EQUAL(v[5], 4);
// Mix them up and try again - single element
- std::random_shuffle(v.begin(), v.end());
+ do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b + 7, b + 8, std::greater<int>());
check_sequence (b, v.end(), b + 7, b + 8, std::greater<int>());
BOOST_CHECK_EQUAL(v[7], 2);
// Mix them up and try again - at the end
- std::random_shuffle(v.begin(), v.end());
+ do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b + 7, v.end(), std::greater<int>());
check_sequence (b, v.end(), b + 7, v.end(), std::greater<int>());
BOOST_CHECK_EQUAL(v[9], 0);
// Mix them up and try again - at the beginning
- std::random_shuffle(v.begin(), v.end());
+ do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b, b + 2, std::greater<int>());
check_sequence (b, v.end(), b, b + 2, std::greater<int>());
BOOST_CHECK_EQUAL(v[1], 8);
// Mix them up and try again - empty subrange
- std::random_shuffle(v.begin(), v.end());
+ do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b, b, std::greater<int>());
check_sequence (b, v.end(), b, b, std::greater<int>());
// Mix them up and try again - entire subrange
- std::random_shuffle(v.begin(), v.end());
+ do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b, v.end(), std::greater<int>());
check_sequence (b, v.end(), b, v.end(), std::greater<int>());
}