1111#include " absl/strings/cord.h"
1212#include " absl/strings/string_view.h"
1313#include " google/protobuf/repeated_field.h"
14+ #include " google/protobuf/repeated_field_proxy_traits.h"
1415#include " google/protobuf/repeated_ptr_field.h"
1516
1617
@@ -28,31 +29,6 @@ namespace internal {
2829template <typename ElementType>
2930class RepeatedFieldProxyInternalPrivateAccessHelper ;
3031
31- // A type trait to determine if a repeated field element of type `ElementType`
32- // is a string type.
33- template <typename ElementType>
34- static constexpr bool RepeatedElementTypeIsString =
35- std::is_same_v<ElementType, std::string> ||
36- std::is_same_v<ElementType, absl::string_view> ||
37- std::is_same_v<ElementType, absl::Cord>;
38-
39- // A type trait to determine if a repeated field element of type `ElementType`
40- // is a message type.
41- //
42- // We would like to use `std::is_base_of_v<MessageLite, ElementType>` to
43- // determine if `ElementType` is a message type, but that requires `ElementType`
44- // to be complete. In contexts where `ElementType` is not complete, such as
45- // generated protobuf source files/headers that forward declare external types,
46- // we only have the forward declaration of `ElementType`.
47- //
48- // Aside from strings, all element types other than messages are primitive
49- // types. Enums may be incomplete, but they are forward declared as `enum
50- // <EnumName> : int;`. We therefore can distinguish incomplete message elements
51- // with `std::is_class_v`.
52- template <typename ElementType>
53- static constexpr bool RepeatedElementTypeIsMessage =
54- std::is_class_v<ElementType> && !RepeatedElementTypeIsString<ElementType>;
55-
5632namespace string_util {
5733
5834template <typename StringType, typename T>
@@ -100,67 +76,6 @@ inline void SetElement(absl::Cord& element, T&& value) {
10076
10177} // namespace string_util
10278
103- // RepeatedFieldTraits is a type trait that maps an element type to the concrete
104- // container type that will back the repeated field in the containing message.
105- // This is currently either `RepeatedField` or `RepeatedPtrField`.
106- //
107- // Note that message and string types are specialized below this base template.
108- template <typename ElementType, typename Enable = void >
109- struct RepeatedFieldTraits {
110- static_assert (!std::is_const_v<ElementType>);
111- // The default specialization is only for primitive types. Messages and
112- // strings are specialized below.
113- static_assert (std::is_integral_v<ElementType> ||
114- std::is_floating_point_v<ElementType>);
115-
116- using type = RepeatedField<ElementType>;
117- using const_reference = ElementType;
118- using reference = ElementType;
119- using const_iterator = typename type::const_iterator;
120- using iterator = typename type::iterator;
121- };
122-
123- // Specialization for message types.
124- template <typename ElementType>
125- struct RepeatedFieldTraits <
126- ElementType, std::enable_if_t <RepeatedElementTypeIsMessage<ElementType>>> {
127- static_assert (!std::is_const_v<ElementType>);
128-
129- using type = RepeatedPtrField<ElementType>;
130- using const_reference = const ElementType&;
131- using reference = ElementType&;
132- using const_iterator = typename type::const_iterator;
133- using iterator = typename type::iterator;
134- };
135-
136- // Explicit specializations for string types.
137- template <>
138- struct RepeatedFieldTraits <absl::string_view> {
139- using type = RepeatedPtrField<std::string>;
140- using const_reference = absl::string_view;
141- using reference = absl::string_view;
142- using const_iterator = RepeatedPtrIterator<const absl::string_view>;
143- using iterator = RepeatedPtrIterator<absl::string_view>;
144- };
145-
146- template <>
147- struct RepeatedFieldTraits <std::string> {
148- using type = RepeatedPtrField<std::string>;
149- using const_reference = const std::string&;
150- using reference = std::string&;
151- using const_iterator = typename type::const_iterator;
152- using iterator = typename type::iterator;
153- };
154-
155- template <>
156- struct RepeatedFieldTraits <absl::Cord> {
157- using type = RepeatedField<absl::Cord>;
158- using const_reference = const absl::Cord&;
159- using reference = absl::Cord&;
160- using const_iterator = typename type::const_iterator;
161- using iterator = typename type::iterator;
162- };
163-
16479// The base class for both mutable and const repeated field proxies. Implements
16580// all of the common methods and dependent types for both classes.
16681template <typename ElementType>
0 commit comments