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:
Henner Zeller
2022-04-11 17:02:19 -07:00
committed by GitHub
parent 173ebb6944
commit 7f663b1204
2 changed files with 19 additions and 3 deletions

View File

@@ -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<const char *> names3;
names3.push_back("foo");
names3.push_back("bar");
builder.CreateVectorOfStrings(names3); // Also an accepted type
#ifdef FLATBUFFERS_HAS_STRING_VIEW
std::vector<flatbuffers::string_view> names4;
names3.push_back("baz");
names3.push_back("quux");
builder.CreateVectorOfStrings(names4); // Also an accepted type
#endif
// Create many vectors of strings
std::vector<std::string> manyNames;
for (auto i = 0; i < 100; i++) { manyNames.push_back("john_doe"); }