diff --git a/include/flatbuffers/flatbuffer_builder.h b/include/flatbuffers/flatbuffer_builder.h index 999419383..d34b4fc21 100644 --- a/include/flatbuffers/flatbuffer_builder.h +++ b/include/flatbuffers/flatbuffer_builder.h @@ -716,15 +716,18 @@ class FlatBufferBuilder { return CreateVector(elems); } - /// @brief Serialize a `std::vector` into a FlatBuffer `vector`. + /// @brief Serialize a `std::vector` 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> + template> Offset>> CreateVectorOfStrings( - const std::vector &v) { + const std::vector &v) { return CreateVectorOfStrings(v.cbegin(), v.cend()); } diff --git a/tests/test.cpp b/tests/test.cpp index c87ca85e3..06d6a08fa 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -136,6 +136,19 @@ flatbuffers::DetachedBuffer CreateFlatBufferTest(std::string &buffer) { names2.push_back("mary"); auto vecofstrings2 = builder.CreateVectorOfStrings(names2); + // Creating vectors from types that are different from std::string + std::vector names3; + names3.push_back("foo"); + names3.push_back("bar"); + builder.CreateVectorOfStrings(names3); // Also an accepted type + +#ifdef FLATBUFFERS_HAS_STRING_VIEW + std::vector names4; + names3.push_back("baz"); + names3.push_back("quux"); + builder.CreateVectorOfStrings(names4); // Also an accepted type +#endif + // Create many vectors of strings std::vector manyNames; for (auto i = 0; i < 100; i++) { manyNames.push_back("john_doe"); }