Can someone explain this code please? how is it that the function bar accepts a reference to the first element of the vector?
jintArray arry;
std::vector<int> foo = GetIntegerArray(env, arry);
bar(&foo[0])
where the protoytpe of bar is
bar(int* array)
This is valid as long as the template type isn’t
bool. The C++ vector type specifies that the vector elements are consecutive in memory like that so that you can do exactly this.The reason why it doesn’t work with
boolis due to template specialization. Where the bools are compressed down to a bitfield.http://en.wikipedia.org/wiki/Vector_%28C%2B%2B%29#vector.3Cbool.3E_specialization