Replace deprecated usages of std::random_shuffle

std::random_shuffle is deprecated in C++14 and removed completely
in C++17. The two-iterator version of std::random_shuffle usually
depends on std::rand and also on a global state. The preferred
replacement is to use std::shuffle with a pseudo-random number
generator.
This commit is contained in:
Joe Loser
2018-06-20 07:49:22 -04:00
committed by Nik Bougalis
parent aab47e09b6
commit b0a1aef43d
2 changed files with 8 additions and 2 deletions

View File

@@ -21,6 +21,7 @@
#define RIPPLE_PEERFINDER_LIVECACHE_H_INCLUDED
#include <ripple/basics/Log.h>
#include <ripple/basics/random.h>
#include <ripple/peerfinder/PeerfinderManager.h>
#include <ripple/peerfinder/impl/iosformat.h>
#include <ripple/peerfinder/impl/Tuning.h>
@@ -29,6 +30,8 @@
#include <boost/intrusive/list.hpp>
#include <boost/iterator/transform_iterator.hpp>
#include <algorithm>
namespace ripple {
namespace PeerFinder {
@@ -482,7 +485,7 @@ Livecache <Allocator>::hops_t::shuffle()
v.reserve (list.size());
std::copy (list.begin(), list.end(),
std::back_inserter (v));
std::random_shuffle (v.begin(), v.end());
std::shuffle (v.begin(), v.end(), default_prng());
list.clear();
for (auto& e : v)
list.push_back (e);

View File

@@ -21,6 +21,7 @@
#define RIPPLE_PEERFINDER_LOGIC_H_INCLUDED
#include <ripple/basics/Log.h>
#include <ripple/basics/random.h>
#include <ripple/basics/contract.h>
#include <ripple/beast/container/aged_container_utility.h>
#include <ripple/beast/net/IPAddressConversion.h>
@@ -35,6 +36,8 @@
#include <ripple/peerfinder/impl/Source.h>
#include <ripple/peerfinder/impl/Store.h>
#include <ripple/peerfinder/impl/iosformat.h>
#include <algorithm>
#include <functional>
#include <map>
#include <memory>
@@ -590,7 +593,7 @@ public:
if (value.second->state() == Slot::active)
slots.emplace_back (value.second);
});
std::random_shuffle (slots.begin(), slots.end());
std::shuffle (slots.begin(), slots.end(), default_prng());
// build target vector
targets.reserve (slots.size());