There is a function which takes a float** parameter.
I have the values in a variable of type std::vector<std::vector<float>>.
Is it possible to make such a conversion without allocating a temporary float*[] ?
There is a function which takes a float** parameter.
I have the values in a variable of type std::vector<std::vector<float>>.
Is it possible to make such a conversion without allocating a temporary float*[] ?
This will work:
std::vector<std::vector<float>> source;
std::vector<float*> target(source.size());
for (int i = 0; i < source.size(); ++i)
target[i] = &*source[i].begin();
As you see you do not need to copy the inner std::vector<>s but you need to recreate the outer. A std::vector<> guarantees linear storage of its members (meaning it is compatible with a C-array) so it works for the inner vectors.
std::vector for target?&*source[i].begin() has undefined behavior. But since the function takes float** quite likely it expects rectangular data, and so hopefully that's what the questioner has.