I have put together a theory that explains a phenomenon, but I'd like someone more knowledgeable to bear me up.
In the client code, I have:
vector<bool> candidates;
fillCandidates(candidates);
In the callee, I have:
void fillCandidates(vector<bool>& candidates)
{
// reserve space for two elements
candidates.reserve(2);
candidates[0] = true;
candidates[1] = false;
// here, candidates.size() == 0
}
When I check the size of candidates after the return of the function, it is 0! What's happening? I'm using gcc 4.6.3 called in a CMake script on a Ubuntu 12.04 64-bit (but I think all of this is actually irrelevant).
Note: I'm providing my interpretation as an answer.
Edit: The accepted answer and the comments beat me on timing, so my interpretation wouldn't add anything.