[C++] Automatically determine size of arrays
When creating objects that contain array members, we currently have to explicitly set the number of elements in the array, even though the count is implictly available internally.
struct Line
{
varsize numPositions : numPositions > 0;
Position pn[numPositions];
}
The generated C++ code for the above object allows us to write something like this:
BitStreamWriter bsw;
Line line;
line.setPn({Position(20, 50)});
line.write(bsw);
This compiles just fine, but will throw an exception at runtime, because numPositions was not explicitly set.
Instead we have to write:
BitStreamWriter bsw;
Line line;
line.setPn({Position(20, 50)});
line.setNumPositions(1);
line.write(bsw);
This is cumbersome and error-prone. Since the Line object in C++ internally holds pn as an std::vector, the element count is implicitly available and should be deduced when writing the object.
We could think about this but only for such trivial array size expressions. Unfortunately, we are not able to find out any generic solution for that. Consider the following schema:
struct Line
{
varsize numPositionsA : numPositionsA > 0;
varsize numPositionsB : numPositionsB > 0;
Position pn[numPositionsA + numPositionsB];
}
Now, we are not able to deduce from size of pn array what is numPositionsA and what is numPositionsB.
This is a duplicate of #556.