Skip to content

Commit

Permalink
Breaking Change: proto2::Map::value_type changes to `std::pair<cons…
Browse files Browse the repository at this point in the history
…t K, V>`.

PiperOrigin-RevId: 503871374
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jan 23, 2023
1 parent dcbb00d commit 46656ed
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 58 deletions.
33 changes: 0 additions & 33 deletions src/google/protobuf/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions src/google/protobuf/map_test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
4 changes: 0 additions & 4 deletions src/google/protobuf/port_def.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/google/protobuf/port_undef.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 46656ed

Please sign in to comment.