Fix compile error with a vector of non-std::strings. CreateVectorOfStrings() expects a vector of std::string types, but that's not always the case.

This commit is contained in:
Luca Longinotti
2019-03-01 16:35:29 +01:00
parent 92b90d7f0f
commit 371d4e0b79
2 changed files with 9 additions and 3 deletions

View File

@@ -2341,7 +2341,13 @@ class CppGenerator : public BaseGenerator {
auto vector_type = field.value.type.VectorType();
switch (vector_type.base_type) {
case BASE_TYPE_STRING: {
code += "_fbb.CreateVectorOfStrings(" + value + ")";
// Use by-function serialization to emulate CreateVectorOfStrings();
// this works also with non-std strings.
code += "_fbb.CreateVector<flatbuffers::Offset<flatbuffers::String>> ";
code += "(" + value + ".size(), ";
code += "[](size_t i, _VectorArgs *__va) { ";
code += "return __va->__fbb->CreateString(__va->_" + value + "[i]);";
code += " }, &_va )";
break;
}
case BASE_TYPE_STRUCT: {