What is the best way to store an array of boolean values using the following containers from STL for maximum performance?
Explanation
Specialization vector<bool> stores values in bits, not in bool variables. Since there are no pointers and references to bits in C++, elements of vector<bool> are not addressable. Also vector<bool>::iterator is not a random access iterator, unlike vector<string>::iterator or vector<char>::iterator. This causes the following code to fail:
template <typename T> void func(vector<T> & vec)
{
 T & ref=vec.front(); //works with all types besides bool
}
Therefore, the best is to use vector<char>.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести