Can vector <bool>, initialized int
I want to list the views of bool [0,31] and save it in tries for future use.
static const int N = 5; vector<bool> tries(N); for(int i = 0;i < (2<<N); i++){ //can vector<bool> initialized by int? //so I don't have to do bit operation for (int t = 0; t < N; ++t) { tries[t] = i&(1UL<<t); } ... } +4
1 answer
std::vector< bool > cannot do this, but std::bitset can. Since the size of your vector is constant in your case, you should use std::bitset< 5 > . Just initialize it with the non-negative integer value you want.
Note that bitset does not provide (or does not mimic) the Container interface, but provides operator [] return a bit proxy object, such as vector<bool> .
+4