Skip to content

Commit f692a0b

Browse files
committed
Make parsing hashtables more easy:
Avoid unnecessary algorithm/container.h include
1 parent 651484e commit f692a0b

File tree

11 files changed

+90
-38
lines changed

11 files changed

+90
-38
lines changed

absl/algorithm/container.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ constexpr std::size_t c_size(T (&)[N]) {
127127

128128
} // namespace container_algorithm_internal
129129

130+
#include "absl/container/internal/is_unordered_flat_map.h"
131+
#include "absl/container/internal/is_unordered_flat_set.h"
132+
#include "absl/container/internal/is_unordered_node_map.h"
133+
#include "absl/container/internal/is_unordered_node_set.h"
134+
130135
// PUBLIC API
131136

132137
//------------------------------------------------------------------------------

absl/container/flat_hash_map.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include <type_traits>
3636
#include <utility>
3737

38-
#include "absl/algorithm/container.h"
3938
#include "absl/base/macros.h"
4039
#include "absl/container/internal/container_memory.h"
4140
#include "absl/container/internal/hash_function_defaults.h" // IWYU pragma: export
@@ -601,14 +600,7 @@ struct FlatHashMapPolicy {
601600

602601
} // namespace container_internal
603602

604-
namespace container_algorithm_internal {
605-
606-
// Specialization of trait in absl/algorithm/container.h
607-
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
608-
struct IsUnorderedContainer<
609-
absl::flat_hash_map<Key, T, Hash, KeyEqual, Allocator>> : std::true_type {};
610-
611-
} // namespace container_algorithm_internal
603+
#include "absl/container/internal/is_unordered_flat_map.h"
612604

613605
ABSL_NAMESPACE_END
614606
} // namespace absl

absl/container/flat_hash_map_test.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "absl/container/flat_hash_map.h"
16+
#include "absl/algorithm/container.h"
1617

1718
#include <memory>
1819

@@ -24,6 +25,9 @@
2425
#include "absl/container/internal/unordered_map_modifiers_test.h"
2526
#include "absl/types/any.h"
2627

28+
static_assert(absl::container_algorithm_internal::IsUnorderedContainer<
29+
absl::flat_hash_map<int, int>>::value);
30+
2731
namespace absl {
2832
ABSL_NAMESPACE_BEGIN
2933
namespace container_internal {
@@ -150,9 +154,7 @@ struct Hash {
150154

151155
struct Eq {
152156
using is_transparent = void;
153-
bool operator()(size_t lhs, size_t rhs) const {
154-
return lhs == rhs;
155-
}
157+
bool operator()(size_t lhs, size_t rhs) const { return lhs == rhs; }
156158
bool operator()(size_t lhs, const LazyInt& rhs) const {
157159
return lhs == rhs.value;
158160
}

absl/container/flat_hash_set.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <type_traits>
3333
#include <utility>
3434

35-
#include "absl/algorithm/container.h"
3635
#include "absl/base/macros.h"
3736
#include "absl/container/internal/container_memory.h"
3837
#include "absl/container/internal/hash_function_defaults.h" // IWYU pragma: export
@@ -491,14 +490,7 @@ struct FlatHashSetPolicy {
491490
};
492491
} // namespace container_internal
493492

494-
namespace container_algorithm_internal {
495-
496-
// Specialization of trait in absl/algorithm/container.h
497-
template <class Key, class Hash, class KeyEqual, class Allocator>
498-
struct IsUnorderedContainer<absl::flat_hash_set<Key, Hash, KeyEqual, Allocator>>
499-
: std::true_type {};
500-
501-
} // namespace container_algorithm_internal
493+
#include "absl/container/internal/is_unordered_flat_set.h"
502494

503495
ABSL_NAMESPACE_END
504496
} // namespace absl

absl/container/flat_hash_set_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "absl/algorithm/container.h"
1516
#include "absl/container/flat_hash_set.h"
1617

1718
#include <vector>
@@ -25,6 +26,9 @@
2526
#include "absl/memory/memory.h"
2627
#include "absl/strings/string_view.h"
2728

29+
static_assert(absl::container_algorithm_internal::IsUnorderedContainer<
30+
absl::flat_hash_set<int>>::value);
31+
2832
namespace absl {
2933
ABSL_NAMESPACE_BEGIN
3034
namespace container_internal {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#if defined(ABSL_ALGORITHM_CONTAINER_H_) && \
2+
defined(ABSL_CONTAINER_FLAT_HASH_MAP_H_)
3+
4+
#ifndef ABSL_CONTAINER_INTERNAL_IS_UNORDERED_FLAT_MAP_H_
5+
#define ABSL_CONTAINER_INTERNAL_IS_UNORDERED_FLAT_MAP_H_
6+
7+
namespace container_algorithm_internal {
8+
9+
// Specialization of trait in absl/algorithm/container.h
10+
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
11+
struct IsUnorderedContainer<
12+
absl::flat_hash_map<Key, T, Hash, KeyEqual, Allocator>> : std::true_type {};
13+
14+
} // namespace container_algorithm_internal
15+
16+
#endif // ABSL_CONTAINER_INTERNAL_IS_UNORDERED_FLAT_MAP_H_
17+
18+
#endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#if defined(ABSL_ALGORITHM_CONTAINER_H_) && \
2+
defined(ABSL_CONTAINER_FLAT_HASH_SET_H_)
3+
4+
#ifndef ABSL_CONTAINER_INTERNAL_IS_UNORDERED_FLAT_SET_H_
5+
#define ABSL_CONTAINER_INTERNAL_IS_UNORDERED_FLAT_SET_H_
6+
7+
namespace container_algorithm_internal {
8+
9+
// Specialization of trait in absl/algorithm/container.h
10+
template <class Key, class Hash, class KeyEqual, class Allocator>
11+
struct IsUnorderedContainer<absl::flat_hash_set<Key, Hash, KeyEqual, Allocator>>
12+
: std::true_type {};
13+
14+
} // namespace container_algorithm_internal
15+
16+
#endif // ABSL_CONTAINER_INTERNAL_IS_UNORDERED_FLAT_SET_H_
17+
18+
#endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#if defined(ABSL_ALGORITHM_CONTAINER_H_) && \
2+
defined(ABSL_CONTAINER_NODE_HASH_MAP_H_)
3+
4+
#ifndef ABSL_CONTAINER_INTERNAL_IS_UNORDERED_NODE_MAP_H_
5+
#define ABSL_CONTAINER_INTERNAL_IS_UNORDERED_NODE_MAP_H_
6+
7+
namespace container_algorithm_internal {
8+
9+
// Specialization of trait in absl/algorithm/container.h
10+
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
11+
struct IsUnorderedContainer<
12+
absl::node_hash_map<Key, T, Hash, KeyEqual, Allocator>> : std::true_type {};
13+
14+
} // namespace container_algorithm_internal
15+
16+
#endif // ABSL_CONTAINER_INTERNAL_IS_UNORDERED_NODE_MAP_H_
17+
18+
#endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#if defined(ABSL_ALGORITHM_CONTAINER_H_) && \
2+
defined(ABSL_CONTAINER_NODE_HASH_SET_H_)
3+
4+
#ifndef ABSL_CONTAINER_INTERNAL_IS_UNORDERED_NODE_SET_H_
5+
#define ABSL_CONTAINER_INTERNAL_IS_UNORDERED_NODE_SET_H_
6+
7+
namespace container_algorithm_internal {
8+
9+
// Specialization of trait in absl/algorithm/container.h
10+
template <class Key, class Hash, class KeyEqual, class Allocator>
11+
struct IsUnorderedContainer<absl::node_hash_set<Key, Hash, KeyEqual, Allocator>>
12+
: std::true_type {};
13+
14+
} // namespace container_algorithm_internal
15+
16+
#endif // ABSL_CONTAINER_INTERNAL_IS_UNORDERED_NODE_SET_H_
17+
18+
#endif

absl/container/node_hash_map.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include <type_traits>
4141
#include <utility>
4242

43-
#include "absl/algorithm/container.h"
4443
#include "absl/base/macros.h"
4544
#include "absl/container/internal/container_memory.h"
4645
#include "absl/container/internal/hash_function_defaults.h" // IWYU pragma: export
@@ -592,14 +591,7 @@ class NodeHashMapPolicy
592591
};
593592
} // namespace container_internal
594593

595-
namespace container_algorithm_internal {
596-
597-
// Specialization of trait in absl/algorithm/container.h
598-
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
599-
struct IsUnorderedContainer<
600-
absl::node_hash_map<Key, T, Hash, KeyEqual, Allocator>> : std::true_type {};
601-
602-
} // namespace container_algorithm_internal
594+
#include "absl/container/internal/is_unordered_node_set.h"
603595

604596
ABSL_NAMESPACE_END
605597
} // namespace absl

0 commit comments

Comments
 (0)