From b9c8da9de8fb40ae0910578cee71016f5a6d5d33 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Fri, 12 Jul 2024 17:39:04 -0700 Subject: [PATCH] Only use random_shuffle with older Boost std::shuffle is superior to std::random_shuffle so we should only use the old deprecated function if we really need to - specifically, with older Boost (e.g. on Ubuntu 22.04). --- modules/domino/src/particle_states.cpp | 7 +++++-- modules/integrative_docking/bin/interface_cross_links.cpp | 5 ++++- modules/kinematics/src/RRT.cpp | 7 +++++-- modules/misc/include/MetricClosePairsFinder.h | 5 ++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/modules/domino/src/particle_states.cpp b/modules/domino/src/particle_states.cpp index 58c81b4fec..c69b4b517a 100644 --- a/modules/domino/src/particle_states.cpp +++ b/modules/domino/src/particle_states.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include IMPDOMINO_BEGIN_NAMESPACE @@ -173,7 +174,7 @@ void RecursiveStates::load_particle_state(unsigned int i, } } -#if IMP_COMPILER_HAS_RANDOM_SHUFFLE +#if IMP_COMPILER_HAS_RANDOM_SHUFFLE && BOOST_VERSION < 107500 namespace { struct RandomWrapper { int operator()(int i) { @@ -193,7 +194,9 @@ PermutationStates::PermutationStates(ParticleStates *inner) for (unsigned int i = 0; i < permutation_.size(); ++i) { permutation_[i] = i; } -#if IMP_COMPILER_HAS_RANDOM_SHUFFLE +#if IMP_COMPILER_HAS_RANDOM_SHUFFLE && BOOST_VERSION < 107500 + // Older Boost RNG has non-constexpr min(), max() which won't compile + // with std::shuffle, so use the older random_shuffle instead RandomWrapper rr; std::random_shuffle(permutation_.begin(), permutation_.end(), rr); #else diff --git a/modules/integrative_docking/bin/interface_cross_links.cpp b/modules/integrative_docking/bin/interface_cross_links.cpp index 796a0101d0..246724aaaa 100644 --- a/modules/integrative_docking/bin/interface_cross_links.cpp +++ b/modules/integrative_docking/bin/interface_cross_links.cpp @@ -21,6 +21,7 @@ #include #include +#include #include namespace po = boost::program_options; #include @@ -232,7 +233,9 @@ int main(int argc, char** argv) { } select_cross_links(cross_links, selected_cross_links); -#if IMP_COMPILER_HAS_RANDOM_SHUFFLE +#if IMP_COMPILER_HAS_RANDOM_SHUFFLE && BOOST_VERSION < 107500 + // Older Boost RNG has non-constexpr min(), max() which won't compile + // with std::shuffle, so use the older random_shuffle instead std::random_shuffle(selected_cross_links.begin(), selected_cross_links.end()); #else std::shuffle(selected_cross_links.begin(), selected_cross_links.end(), diff --git a/modules/kinematics/src/RRT.cpp b/modules/kinematics/src/RRT.cpp index bdb2f70537..6926d59e13 100644 --- a/modules/kinematics/src/RRT.cpp +++ b/modules/kinematics/src/RRT.cpp @@ -7,6 +7,7 @@ */ #include #include +#include IMPKINEMATICS_BEGIN_NAMESPACE @@ -21,14 +22,16 @@ std::ostream& operator<<(std::ostream& s, const RRT::Parameters& p) { namespace { -#if IMP_COMPILER_HAS_RANDOM_SHUFFLE +#if IMP_COMPILER_HAS_RANDOM_SHUFFLE && BOOST_VERSION < 107500 int myrandom (int i) { return std::rand()%i;} #endif std::vector select_k_out_of_n_dofs(unsigned int k, unsigned int n) { std::vector arr(n); for(unsigned int i=0; i #include #include +#include #include #include #include @@ -51,7 +52,9 @@ class MetricClosePairsFinder : public core::ClosePairsFinder { Index get_index(Model *m, ParticleIndexes inputs) const { unsigned int index_size = std::min( 1U, std::sqrt(static_cast(inputs.size()))); -#if IMP_COMPILER_HAS_RANDOM_SHUFFLE +#if IMP_COMPILER_HAS_RANDOM_SHUFFLE && BOOST_VERSION < 107500 + // Older Boost RNG has non-constexpr min(), max() which won't compile + // with std::shuffle, so use the older random_shuffle instead std::random_shuffle(inputs.begin(), inputs.end()); #else std::shuffle(inputs.begin(), inputs.end(), random_number_generator);