diff options
Diffstat (limited to 'absl/container/flat_hash_map_test.cc')
-rw-r--r-- | absl/container/flat_hash_map_test.cc | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/absl/container/flat_hash_map_test.cc b/absl/container/flat_hash_map_test.cc index 03171f6d..d90fe9d5 100644 --- a/absl/container/flat_hash_map_test.cc +++ b/absl/container/flat_hash_map_test.cc @@ -14,14 +14,20 @@ #include "absl/container/flat_hash_map.h" +#include <cstddef> #include <memory> +#include <type_traits> +#include <utility> +#include <vector> -#include "absl/base/internal/raw_logging.h" +#include "gtest/gtest.h" #include "absl/container/internal/hash_generator_testing.h" #include "absl/container/internal/unordered_map_constructor_test.h" #include "absl/container/internal/unordered_map_lookup_test.h" #include "absl/container/internal/unordered_map_members_test.h" #include "absl/container/internal/unordered_map_modifiers_test.h" +#include "absl/log/check.h" +#include "absl/meta/type_traits.h" #include "absl/types/any.h" namespace absl { @@ -40,10 +46,10 @@ struct BeforeMain { BeforeMain() { absl::flat_hash_map<int, int> x; x.insert({1, 1}); - ABSL_RAW_CHECK(x.find(0) == x.end(), "x should not contain 0"); + CHECK(x.find(0) == x.end()) << "x should not contain 0"; auto it = x.find(1); - ABSL_RAW_CHECK(it != x.end(), "x should contain 1"); - ABSL_RAW_CHECK(it->second, "1 should map to 1"); + CHECK(it != x.end()) << "x should contain 1"; + CHECK(it->second) << "1 should map to 1"; } }; const BeforeMain before_main; @@ -102,6 +108,34 @@ TEST(FlatHashMap, StandardLayout) { } } +TEST(FlatHashMap, Relocatability) { + static_assert(absl::is_trivially_relocatable<int>::value, ""); + static_assert( + absl::is_trivially_relocatable<std::pair<const int, int>>::value, ""); + static_assert( + std::is_same<decltype(absl::container_internal::FlatHashMapPolicy< + int, int>::transfer<std::allocator<char>>(nullptr, + nullptr, + nullptr)), + std::true_type>::value, + ""); + + struct NonRelocatable { + NonRelocatable() = default; + NonRelocatable(NonRelocatable&&) {} + NonRelocatable& operator=(NonRelocatable&&) { return *this; } + void* self = nullptr; + }; + + EXPECT_FALSE(absl::is_trivially_relocatable<NonRelocatable>::value); + EXPECT_TRUE( + (std::is_same<decltype(absl::container_internal::FlatHashMapPolicy< + int, NonRelocatable>:: + transfer<std::allocator<char>>(nullptr, nullptr, + nullptr)), + std::false_type>::value)); +} + // gcc becomes unhappy if this is inside the method, so pull it out here. struct balast {}; @@ -150,9 +184,7 @@ struct Hash { struct Eq { using is_transparent = void; - bool operator()(size_t lhs, size_t rhs) const { - return lhs == rhs; - } + bool operator()(size_t lhs, size_t rhs) const { return lhs == rhs; } bool operator()(size_t lhs, const LazyInt& rhs) const { return lhs == rhs.value; } |