darts build fail after clang update to 16. I google it ,and found that "random_shuffle was deprecated in C++14 and completely removed in C++17". So, maybe we need to add some param to make it compile as c++14? Reproducible: Always
Created attachment 858767 [details] build log
Created attachment 858769 [details] emerge info
I can't reproduce this error. Build log: http://ix.io/4rSD
(In reply to listout from comment #3) > I can't reproduce this error. > Build log: http://ix.io/4rSD lack of -stdlib=libc++ in your CXXFLGAS, add it and try again?
Created attachment 861648 [details, diff] Patch using custom random_shuffle Thanks, I was able to reproduce the issue. Upstream seemed to be dead (the last commit was back in 2013), hence I patched it to use random_shuffle from https://en.cppreference.com/w/cpp/algorithm/random_shuffle
(In reply to listout from comment #5) > Created attachment 861648 [details, diff] [details, diff] > Patch using custom random_shuffle > > Thanks, I was able to reproduce the issue. Upstream seemed to be dead (the > last commit was back in 2013), hence I patched it to use random_shuffle from > https://en.cppreference.com/w/cpp/algorithm/random_shuffle Notes on cppreference says: """ The reason for removing std::random_shuffle in C++17 is that the iterator-only version usually depends on std::rand, which is now also discussed for deprecation. (std::rand should be replaced with the classes of the <random> header, as std::rand is considered harmful.) In addition, the iterator-only std::random_shuffle version usually depends on a global state. The std::shuffle's shuffle algorithm is the preferred replacement, as it uses a URBG as its 3rd parameter. """ Could you try using the std::shuffle suggestion with https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerator as the 3rd param?
(In reply to Sam James from comment #6) > Could you try using the std::shuffle suggestion with > https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerator as the > 3rd param? With http://ix.io/4vOZ diff --git a/src/lexicon.h b/src/lexicon.h index a2935f4..e39a1d0 100644 --- a/src/lexicon.h +++ b/src/lexicon.h @@ -11,6 +11,21 @@ #include "./mersenne-twister.h" +template<class RandomIt, class URBG> +void shuffle_t(RandomIt first, RandomIt last, URBG&& g) +{ + typedef typename std::iterator_traits<RandomIt>::difference_type diff_t; + typedef std::uniform_int_distribution<diff_t> distr_t; + typedef typename distr_t::param_type param_t; + + distr_t D; + for (diff_t i = last - first - 1; i > 0; --i) + { + using std::swap; + swap(first[i], first[D(g, param_t(0, i))]); + } +} + namespace Darts { class Lexicon { @@ -60,7 +75,7 @@ class Lexicon { void randomize() { Darts::MersenneTwister mt( static_cast<Darts::MersenneTwister::int_type>(std::time(NULL))); - std::random_shuffle(keys_.begin(), keys_.end(), mt); + shuffle_t(keys_.begin(), keys_.end(), mt); } void split(); I get http://ix.io/4vOY