I have a std::bitset
but now I want to use an STL algorithm on it.
I could have used std::vector<bool>
instead, but I like std::bitset
's constructor and I want std::bitset
's bitwise operations.
Do I have to go through a loop and stuff everything in a std::vector<bool>
to use STL algorithms, and then copy that back to the std::bitset
, or is there a better way?
If you do not want to write loops using the operator[]
of the bitset
, then you might try using bitset::to_string()
to convert the bitset to a string of '1'
and '0'
. Since C++11, you can actually choose different characters than those two, so you could actually choose '\0'
and '\1'
.
Are you sure bitset
is the optimal type for your task?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With