I have (circular) bitset<N>and would like to get a substring i...i+K-1(where it can happen that i = N - 1; K = 5, therefore, it should turn around and get N-1; 0; 1; 2; 3), as another one bitset<K>(K, of course, known at compile time)
The obvious thing does not work, because it operator &does not allow the use of operands of different sizes (although would this be trivial?)
bitset<N> data = ...;
bitset<K> mask; mask = ~mask;
bitset<K> rotated = in << i | in >> (K - i);
bitset<K> slice = rotated & mask;
The following best does not work with large N
bitset<K> slice( rotated.to_ullong() & mask.to_ullong() );
What if not done bitset<min<N,K>::value> operator &(bitset<N>,bitset<K>)? (and maybe not so terribly inefficient, this approach copies the set 3 times)
source
share