In this piece of code
void legacyFunction(int length, bool *bitset)
{
// stuff, lots of stuff
}
int main()
{
int somenumber = 6;
// somenumber is set to some value here
bool *isBitXSet = new bool[somenumber];
// initialisation of isBitXSet.
legacyFunction(somenumber, isBitXSet);
delete[] isBitXSet;
return 0;
}
I'd like to replace bool *isBitXSet = new bool[somenumber]; by something like
std::vector<bool> isBitXset(somenumber, false);
But I cannot do
legacyFunction(somenumber, isBitXSet.data());
because data() doesn't exist for std::vector<bool>. And I cannot change the interface of legacyFunction().
Is there a good alternative to the C-style bool array?
data()member function is not the only problem.std::vector<bool>is a specialization that may provide a more space-efficient implementation. So the elements ofvector<bool>and a C-styleboolarray may not overlap.