mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
Remove fallback code in absl/algorithm/container.h
The fallback code is dead code since C++14 is no longer supported. PiperOrigin-RevId: 753219255 Change-Id: I79cf1d2c8678f066a4154e35f114b79a99fff90b
This commit is contained in:
committed by
Copybara-Service
parent
5f3435aba0
commit
3a074281f3
@@ -44,7 +44,6 @@
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include <numeric>
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
@@ -847,25 +846,9 @@ template <typename C, typename OutputIterator, typename Distance,
|
||||
typename UniformRandomBitGenerator>
|
||||
OutputIterator c_sample(const C& c, OutputIterator result, Distance n,
|
||||
UniformRandomBitGenerator&& gen) {
|
||||
#if defined(__cpp_lib_sample) && __cpp_lib_sample >= 201603L
|
||||
return std::sample(container_algorithm_internal::c_begin(c),
|
||||
container_algorithm_internal::c_end(c), result, n,
|
||||
std::forward<UniformRandomBitGenerator>(gen));
|
||||
#else
|
||||
// Fall back to a stable selection-sampling implementation.
|
||||
auto first = container_algorithm_internal::c_begin(c);
|
||||
Distance unsampled_elements = c_distance(c);
|
||||
n = (std::min)(n, unsampled_elements);
|
||||
for (; n != 0; ++first) {
|
||||
Distance r =
|
||||
std::uniform_int_distribution<Distance>(0, --unsampled_elements)(gen);
|
||||
if (r < n) {
|
||||
*result++ = *first;
|
||||
--n;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user