Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

c++ - Why are std::shuffle methods being deprecated in C++14?

According to the cppreference.com reference site on std::shufle, the following method is being deprecated in c++14:

template< class RandomIt >
void random_shuffle( RandomIt first, RandomIt last );

Why will we no longer be able to call the following function without passing a third parameter?

std::random_shuffle(v.begin(),v.end()); //no longer valid in c++14

It doesn't appear as though a different function deceleration has a default parameter set. What is the reason behind this? Was there some kind of alternative added?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

std::random_shuffle may make use, under the hood, of random C family of functions. These functions use global state for seeds and other state.

So it is being deprecated because shuffle will do the same, but better. Namely, it uses the new <random> header from C++11 that doesn't use global state, but its own objects making use of generators, devices and distributions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...