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?
The shuffle() function in C++ is a function in vector library. It is a function that will rearrange the elements of any range by placing the elements at random positions. To shuffle it uses a uniform random generator which helps in shuffling the elements.
The random_shuffle algorithm shuffles the elements of a sequence (first..last) in a random order. The predicate version uses the pred function to generate the indices of the elements to swap. The pred has to be a function object that takes a parameter n and returns an integral random number in the range 0 to (n - 1).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With