Breaking Change: `proto2::Map::value_type` changes to `std::pair<const K, V>`.

PiperOrigin-RevId: 503871374
pull/11625/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent dcbb00d753
commit 46656ed080
  1. 33
      src/google/protobuf/map.h
  2. 20
      src/google/protobuf/map_test.inc
  3. 4
      src/google/protobuf/port_def.inc
  4. 1
      src/google/protobuf/port_undef.inc

@ -981,42 +981,9 @@ class KeyMapBase : public UntypedMapBase {
} // namespace internal
#ifdef PROTOBUF_FUTURE_MAP_PAIR_UPGRADE
// This is the class for Map's internal value_type.
template <typename Key, typename T>
using MapPair = std::pair<const Key, T>;
#else
// This is the class for Map's internal value_type. Instead of using
// std::pair as value_type, we use this class which provides us more control of
// its process of construction and destruction.
template <typename Key, typename T>
struct PROTOBUF_ATTRIBUTE_STANDALONE_DEBUG MapPair {
using first_type = const Key;
using second_type = T;
MapPair(const Key& other_first, const T& other_second)
: first(other_first), second(other_second) {}
explicit MapPair(const Key& other_first) : first(other_first), second() {}
explicit MapPair(Key&& other_first)
: first(std::move(other_first)), second() {}
MapPair(const MapPair& other) : first(other.first), second(other.second) {}
~MapPair() {}
// Implicitly convertible to std::pair of compatible types.
template <typename T1, typename T2>
operator std::pair<T1, T2>() const { // NOLINT(runtime/explicit)
return std::pair<T1, T2>(first, second);
}
const Key first;
T second;
private:
friend class Arena;
friend class Map<Key, T>;
};
#endif
// Map is an associative container type used to store protobuf map
// fields. Each Map instance may or may not use a different hash function, a

@ -813,24 +813,6 @@ TEST_F(MapImplTest, Emplace) {
m, UnorderedElementsAre(Pair(1, "one"), Pair(2, "two"), Pair(42, "aaa")));
}
#ifndef PROTOBUF_FUTURE_MAP_PAIR_UPGRADE
TEST_F(MapImplTest, EmplaceKeyOnly) {
using ::testing::Pair;
using ::testing::UnorderedElementsAre;
Map<int32_t, std::string> m;
m.emplace(1);
EXPECT_EQ(m.size(), 1);
const int32_t key = 42;
m.emplace(key);
EXPECT_THAT(m, UnorderedElementsAre(Pair(1, ""), Pair(42, "")));
}
#else
TEST_F(MapImplTest, ValueTypeHasMoveConstructor) {
using vt = typename Map<ConstructorTag, ConstructorTag>::value_type;
ConstructorTag l, r;
@ -841,8 +823,6 @@ TEST_F(MapImplTest, ValueTypeHasMoveConstructor) {
EXPECT_EQ(pair.second.invoked_constructor, ConstructorType::kMove);
}
#endif // !PROTOBUF_FUTURE_MAP_PAIR_UPGRADE
TEST_F(MapImplTest, TryEmplaceExisting) {
Map<int32_t, CountedInstance> m;

@ -204,10 +204,6 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and
#ifdef PROTOBUF_FUTURE_BREAKING_CHANGES
// Used to upgrade google::protobuf::MapPair<K, V> to std::pair<const K, V>.
// Owner: mordberg@
#define PROTOBUF_FUTURE_MAP_PAIR_UPGRADE 1
// Used to remove the manipulation of cleared elements in RepeatedPtrField.
// Owner: mkruskal@
#define PROTOBUF_FUTURE_REMOVE_CLEARED_API 1

@ -117,7 +117,6 @@
#ifdef PROTOBUF_FUTURE_BREAKING_CHANGES
#undef PROTOBUF_FUTURE_BREAKING_CHANGES
#undef PROTOBUF_FUTURE_MAP_PAIR_UPGRADE
#undef PROTOBUF_FUTURE_REMOVE_CLEARED_API
#endif

Loading…
Cancel
Save