Skip to content

Commit

Permalink
MSVC std::sample workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
ximinez authored and manojsdoshi committed Mar 30, 2022
1 parent bea9610 commit bc9773e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/ripple/app/ledger/impl/InboundLedger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,14 +1273,25 @@ struct PeerDataCounts
if (counts.empty())
return;

auto outFunc = [&f](auto&& v) { f(v.first); };
std::minstd_rand rng{std::random_device{}()};
#if _MSC_VER
std::vector<std::pair<std::shared_ptr<Peer>, int>> s;
s.reserve(n);
std::sample(
counts.begin(), counts.end(), std::back_inserter(s), n, rng);
for (auto& v : s)
{
outFunc(v);
}
#else
std::sample(
counts.begin(),
counts.end(),
boost::make_function_output_iterator(
[&f](auto&& v) { f(v.first); }),
boost::make_function_output_iterator(outFunc),
n,
rng);
#endif
}
};
} // namespace detail
Expand Down

0 comments on commit bc9773e

Please sign in to comment.