mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-08 14:15:17 +00:00
Allow CreateVectorOfStrings() to work with any string-type. (#7238)
Any string type that is supported by CreateString(), e.g. const char* or string_view will now also work. Signed-off-by: Henner Zeller <hzeller@google.com>
This commit is contained in:
@@ -716,15 +716,18 @@ class FlatBufferBuilder {
|
||||
return CreateVector(elems);
|
||||
}
|
||||
|
||||
/// @brief Serialize a `std::vector<std::string>` into a FlatBuffer `vector`.
|
||||
/// @brief Serialize a `std::vector<StringType>` into a FlatBuffer `vector`.
|
||||
/// whereas StringType is any type that is accepted by the CreateString()
|
||||
/// overloads.
|
||||
/// This is a convenience function for a common case.
|
||||
/// @param v A const reference to the `std::vector` to serialize into the
|
||||
/// buffer as a `vector`.
|
||||
/// @return Returns a typed `Offset` into the serialized data indicating
|
||||
/// where the vector is stored.
|
||||
template<typename Alloc = std::allocator<std::string>>
|
||||
template<typename StringType = std::string,
|
||||
typename Alloc = std::allocator<std::string>>
|
||||
Offset<Vector<Offset<String>>> CreateVectorOfStrings(
|
||||
const std::vector<std::string, Alloc> &v) {
|
||||
const std::vector<StringType, Alloc> &v) {
|
||||
return CreateVectorOfStrings(v.cbegin(), v.cend());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user