I want to use std::vector for dynamically allocating memory. The scenario is:
int neededLength = computeLength(); // some logic here
// this will allocate the buffer
std::vector<TCHAR> buffer( neededLength );
// call a function that accepts TCHAR* and the number of elements
callFunction( &(buffer[0]), buffer.size() );
The code above works, but this &(buffer[0]) looks ugly. Is there a more elegant way to achieve the same?
Well, you can remove one set of parens:
but that is the common, idiomatic way of doing it. If it really offends you, I suppose you could use a template – something like: