c++ - Getting a bool reference from std::vector<bool> -


i know it's bad habit, i'd know workaround or hack problem. have class this:

template <class t> class : std::vector<t> {   t& operator()(int index) { // returns _reference_ object     return this->operator[](index);   } }; 

it's possible things this:

a<int> a{1,2,3,4}; a(3) = 10; 

but stops working if uses bool template parameter

a<bool> a{true, false, true}; std::cout << a(0) << std::endl; // not possible if (a(1)) { /* */ }   // not possible 

std::vector<bool> specialized version of vector (http://www.cplusplus.com/reference/vector/vector-bool/) doesn't allow such things.

is there way how reference of boolean variable std::vector? or different solution?

is there way how reference of boolean variable std::vector?

no.

or different solution?

return typename std::vector<t>::reference instead of t&. bool, return vector's proxy type; others, return regular reference.

or specialise a<bool> use other vector<bool>.

or use other type (perhaps char, or simple class wrapping bool) instead of bool.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -