Remove IsMovable and inline the assertions in the right place instead.

We don't need SFINAE or generic support because the set of types allowed in RepeatedPtrField is closed.

PiperOrigin-RevId: 681476008
pull/18584/head
Protobuf Team Bot 5 months ago committed by Copybara-Service
parent a089fad8bd
commit 1254c8daa0
  1. 30
      src/google/protobuf/repeated_field_unittest.cc
  2. 14
      src/google/protobuf/repeated_ptr_field.h

@ -940,36 +940,6 @@ TEST(RepeatedField, MoveAssign) {
}
}
TEST(Movable, Works) {
class NonMoveConstructible {
public:
NonMoveConstructible(NonMoveConstructible&&) = delete;
NonMoveConstructible& operator=(NonMoveConstructible&&) { return *this; }
};
class NonMoveAssignable {
public:
NonMoveAssignable(NonMoveAssignable&&) {}
NonMoveAssignable& operator=(NonMoveConstructible&&) = delete;
};
class NonMovable {
public:
NonMovable(NonMovable&&) = delete;
NonMovable& operator=(NonMovable&&) = delete;
};
EXPECT_TRUE(internal::IsMovable<std::string>::value);
EXPECT_FALSE(std::is_move_constructible<NonMoveConstructible>::value);
EXPECT_TRUE(std::is_move_assignable<NonMoveConstructible>::value);
EXPECT_FALSE(internal::IsMovable<NonMoveConstructible>::value);
EXPECT_TRUE(std::is_move_constructible<NonMoveAssignable>::value);
EXPECT_FALSE(std::is_move_assignable<NonMoveAssignable>::value);
EXPECT_FALSE(internal::IsMovable<NonMoveAssignable>::value);
EXPECT_FALSE(internal::IsMovable<NonMovable>::value);
}
TEST(RepeatedField, MutableDataIsMutable) {
RepeatedField<int> field;
field.Add(1);

@ -81,11 +81,6 @@ inline void memswap(char* PROTOBUF_RESTRICT a, char* PROTOBUF_RESTRICT b) {
std::swap_ranges(a, a + N, b);
}
template <typename T>
struct IsMovable
: std::integral_constant<bool, std::is_move_constructible<T>::value &&
std::is_move_assignable<T>::value> {};
// A trait that tells offset of `T::arena_`.
//
// Do not use this struct - it exists for internal use only.
@ -106,7 +101,6 @@ class GenericTypeHandler;
// class TypeHandler {
// public:
// using Type = MyType;
// using Movable = ...;
//
// static Type*(*)(Arena*) GetNewFunc();
// static void GetArena(Type* value);
@ -198,10 +192,10 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
return cast<TypeHandler>(AddMessageLite(TypeHandler::GetNewFunc()));
}
template <
typename TypeHandler,
typename std::enable_if<TypeHandler::Movable::value>::type* = nullptr>
template <typename TypeHandler>
inline void Add(Value<TypeHandler>&& value) {
static_assert(std::is_move_constructible<Value<TypeHandler>>::value, "");
static_assert(std::is_move_assignable<Value<TypeHandler>>::value, "");
if (current_size_ < allocated_size()) {
*cast<TypeHandler>(element_at(ExchangeCurrentSize(current_size_ + 1))) =
std::move(value);
@ -818,7 +812,6 @@ template <typename GenericType>
class GenericTypeHandler {
public:
using Type = GenericType;
using Movable = IsMovable<Type>;
static constexpr auto GetNewFunc() { return Arena::DefaultConstruct<Type>; }
static inline Arena* GetArena(Type* value) {
@ -896,7 +889,6 @@ template <>
class GenericTypeHandler<std::string> {
public:
using Type = std::string;
using Movable = IsMovable<Type>;
static constexpr auto GetNewFunc() { return NewStringElement; }
static inline Arena* GetArena(Type*) { return nullptr; }

Loading…
Cancel
Save