I'm using a third-party API (CryptEncrypt, to be precise) which takes a C array as an in-out parameter. Logically, the API boils down to the following function:
void add1(int *inout, size_t length)
{
for(size_t i = 0; i < length; i++)
{
inout[i] += 1;
}
}
I'm trying to avoid the use of raw arrays, so my question is can I use the std::vector as an input to the API above? Something like the following:
#include <vector>
int main()
{
std::vector<int> v(10); // vector with 10 zeros
add1(&v[0], v.size()); // vector with 10 ones?
}
Can I use the 'contiguous storage' guarantee of a vector to write data to it? I'm inclined to believe that this is OK (it works with my compiler), but I'd feel a lot better if someone more knowledgeable than me can confirm if such usage doesn't violate the C++ standard guarantees. :)
Thanks in advance!