Fix CreateVector/CreateVectorOfStructs for non-std vector types (cpp_vec_type)

When cpp_vec_type is set to a non-std container, Pack methods for scalar,
bool, and plain-struct vectors now use the pointer+size overloads of
CreateVector/CreateVectorOfStructs instead of the std::vector-only overloads.
Extends the combined cpp_vec_type+native_type test to also cover scalar
(ubyte) vectors with a custom container type.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-09 20:48:32 +02:00
parent 19aa2ce420
commit 505ec2fb6a
3 changed files with 29 additions and 5 deletions

View File

@@ -1051,12 +1051,17 @@ void CppVecTypeNativeTypeTest() {
CppVecNativeTypeTest::CustomVec<
CppVecNativeTypeTest::Native::Vec3>>::value,
"points should be CustomVec<Native::Vec3>");
static_assert(
std::is_same<decltype(CppVecNativeTypeTest::ContainerT{}.bytes),
CppVecNativeTypeTest::CustomVec<uint8_t>>::value,
"bytes should be CustomVec<uint8_t>");
const int N = 3;
CppVecNativeTypeTest::ContainerT src;
for (int i = 0; i < N; ++i) {
src.points.push_back(
CppVecNativeTypeTest::Native::Vec3(1.0f * i, 2.0f * i, 3.0f * i));
src.bytes.push_back(static_cast<uint8_t>(i * 10));
}
flatbuffers::FlatBufferBuilder fbb;
@@ -1071,6 +1076,11 @@ void CppVecTypeNativeTypeTest() {
TEST_EQ(dst->points[i].y, 2.0f * i);
TEST_EQ(dst->points[i].z, 3.0f * i);
}
TEST_EQ(dst->bytes.size(), static_cast<size_t>(N));
for (int i = 0; i < N; ++i) {
TEST_EQ(dst->bytes[i], static_cast<uint8_t>(i * 10));
}
}
// Guard against -Wunused-function on platforms without file tests.