Skip to content

Commit fdc64e2

Browse files
Quincunx271copybara-github
authored andcommitted
Support C++20 iterators in raw_hash_map's random-access iterator detection
Missed in 9e764b4. Allows random-access iterators with a value-type `reference` (e.g. zip iterators) to hit this fast path, because of ae4b0c5. PiperOrigin-RevId: 727356112 Change-Id: I4a2499cc1d0403b51a802297c84449531cfb9d5e
1 parent cc70e83 commit fdc64e2

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

absl/container/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ cc_library(
697697
"//absl/base:core_headers",
698698
"//absl/base:dynamic_annotations",
699699
"//absl/base:endian",
700+
"//absl/base:iterator_traits_internal",
700701
"//absl/base:prefetch",
701702
"//absl/base:raw_logging_internal",
702703
"//absl/functional:function_ref",

absl/container/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@ absl_cc_library(
765765
absl::hash_policy_traits
766766
absl::hashtable_debug_hooks
767767
absl::hashtablez_sampler
768+
absl::iterator_traits_internal
768769
absl::memory
769770
absl::meta
770771
absl::optional

absl/container/internal/raw_hash_set.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
#include "absl/base/attributes.h"
197197
#include "absl/base/config.h"
198198
#include "absl/base/internal/endian.h"
199+
#include "absl/base/internal/iterator_traits.h"
199200
#include "absl/base/internal/raw_logging.h"
200201
#include "absl/base/macros.h"
201202
#include "absl/base/optimization.h"
@@ -1601,10 +1602,8 @@ size_t SelectBucketCountForIterRange(InputIter first, InputIter last,
16011602
if (bucket_count != 0) {
16021603
return bucket_count;
16031604
}
1604-
using InputIterCategory =
1605-
typename std::iterator_traits<InputIter>::iterator_category;
1606-
if (std::is_base_of<std::random_access_iterator_tag,
1607-
InputIterCategory>::value) {
1605+
if (base_internal::IsAtLeastIterator<std::random_access_iterator_tag,
1606+
InputIter>()) {
16081607
return GrowthToLowerboundCapacity(
16091608
static_cast<size_t>(std::distance(first, last)));
16101609
}

0 commit comments

Comments
 (0)