mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-03 17:56:21 +03:00
0032909: Coding Rules - replace (removed from C++17) std::random_shuffle
with std::shuffle
for random permutation algorithm
Since C++17 the accessible version of permutation function left the function: template< class RandomIt, class URBG > void shuffle( RandomIt first, RandomIt last, URBG&& g ); See details and example of use: https://en.cppreference.com/w/cpp/algorithm/random_shuffle
This commit is contained in:
parent
e455c54bf0
commit
7021de2fe7
@ -38,18 +38,11 @@
|
||||
#include <set>
|
||||
#include <typeinfo>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
|
||||
//! Size of test data sets.
|
||||
const int THE_TEST_SIZE = 5000;
|
||||
|
||||
namespace {
|
||||
// Auxiliary class to use in std::random_shuffle()
|
||||
struct RandomGenerator {
|
||||
RandomGenerator () { srand(1); }
|
||||
ptrdiff_t operator () (ptrdiff_t upper) const { return rand() % upper; }
|
||||
};
|
||||
}
|
||||
|
||||
template<class CollectionType, class StlType>
|
||||
struct CollectionFiller
|
||||
{
|
||||
@ -951,11 +944,13 @@ void TestPerformanceRandomIterator(Draw_Interpretor& di)
|
||||
aTimer.Reset();
|
||||
aTimer.Start();
|
||||
{
|
||||
RandomGenerator aRandomGen;
|
||||
std::random_device ran_dev;
|
||||
std::mt19937 gen(ran_dev());
|
||||
gen.seed(0x03ac38f2);
|
||||
for (Standard_Integer anIdx = 0; anIdx < 10; ++anIdx)
|
||||
{
|
||||
std::sort (aVector->begin(), aVector->end());
|
||||
std::random_shuffle (aVector->begin(), aVector->end(), aRandomGen);
|
||||
std::sort (aVector->begin(), aVector->end());
|
||||
std::shuffle (aVector->begin(), aVector->end(), gen);
|
||||
}
|
||||
}
|
||||
aTimer.Stop();
|
||||
@ -965,11 +960,13 @@ void TestPerformanceRandomIterator(Draw_Interpretor& di)
|
||||
aTimer.Reset();
|
||||
aTimer.Start();
|
||||
{
|
||||
RandomGenerator aRandomGen;
|
||||
std::random_device ran_dev;
|
||||
std::mt19937 gen(ran_dev());
|
||||
gen.seed(0x03ac38f2);
|
||||
for (Standard_Integer anIdx = 0; anIdx < 10; ++anIdx)
|
||||
{
|
||||
std::sort (aCollec->begin(), aCollec->end());
|
||||
std::random_shuffle (aCollec->begin(), aCollec->end(), aRandomGen);
|
||||
std::sort (aCollec->begin(), aCollec->end());
|
||||
std::shuffle (aCollec->begin(), aCollec->end(), gen);
|
||||
}
|
||||
}
|
||||
aTimer.Stop();
|
||||
@ -981,7 +978,7 @@ void TestPerformanceRandomIterator(Draw_Interpretor& di)
|
||||
|
||||
// check that result is the same
|
||||
if ( ! std::equal (aVector->begin(), aVector->end(), aCollec->begin()) )
|
||||
di << "Error: sequences are not the same at the end!\n";
|
||||
di << "Error: sequences are not the same at the end (random iterator)!\n";
|
||||
|
||||
delete aVector;
|
||||
delete aCollec;
|
||||
@ -1033,7 +1030,7 @@ void TestPerformanceForwardIterator(Draw_Interpretor& di)
|
||||
|
||||
// check that result is the same
|
||||
if ( ! std::equal (aVector->begin(), aVector->end(), aCollec->begin()) )
|
||||
di << "Error: sequences are not the same at the end!\n";
|
||||
di << "Error: sequences are not the same at the end (forward iterator)!\n";
|
||||
|
||||
delete aVector;
|
||||
delete aCollec;
|
||||
@ -1085,7 +1082,7 @@ void TestPerformanceBidirIterator(Draw_Interpretor& di)
|
||||
|
||||
// check that result is the same
|
||||
if ( ! std::equal (aVector->begin(), aVector->end(), aCollec->begin()) )
|
||||
di << "Error: sequences are not the same at the end!\n";
|
||||
di << "Error: sequences are not the same at the end (bidir iterator)!\n";
|
||||
|
||||
delete aVector;
|
||||
delete aCollec;
|
||||
|
Loading…
x
Reference in New Issue
Block a user