I know it's a bad habit, but I'd like to know some workaround or hack for this problem. I have a class like this:
template <class T>
class A : std::vector<T> {
T& operator()(int index) { // returns a _reference_ to an object
return this->operator[](index);
}
};
It's possible to do things like this:
A<int> a{1,2,3,4};
a(3) = 10;
But it stops working if somebody uses bool as a template parameter
A<bool> a{true, false, true};
std::cout << a(0) << std::endl; // not possible
if (a(1)) { /* something */ } // not possible
std::vector<bool>
is a specialized version of vector (http://www.cplusplus.com/reference/vector/vector-bool/) which doesn't allow such things.
Is there a way how to get a reference of boolean variable from std::Vector? Or any different solution?
See Question&Answers more detail:os