Convert between std :: bitset and std :: vector <bool>

I have it std::bitset, but now I want to use the STL algorithm on it.

I could use std::vector<bool>instead, but I like the constructor std::bitset, and I want bitwise operations std::bitset.

Do I have to go through a loop and everything in std::vector<bool>using STL algorithms and then copy it back to std::bitset, or is there a better way?

+4
source share
2 answers

Matthew Austern wrote an iterator for bitsethere: http://www.drdobbs.com/the-standard-librarian-bitsets-and-bit-v/184401382?pgno=2

100 , , , , . STL.

:

STL, - () . , , " ", * , ​​ b [n]. : .

:

, , . pre-STL, STL, .

, vector<bool>::iterator, Austern bitset_iterator::operator* bool&, : bitset<>::reference.

bitset_iterator :

std::bitset<10> foo;
std::vector<bool> bar(begin(foo), end(foo));
0

operator[] bitset, bitset::to_string() '1' '0'. ++ 11, , , '\0' '\1'.

, bitset ?

+1

Source: https://habr.com/ru/post/1570341/


All Articles