title: Slice a substring from a cyclic bitset
body: <p>I have a (cyclic) <code>bitset&lt;N&gt;</code> and would like to retrieve the substring <code>i...i+K-1</code> (where it could happen that <code>i = N - 1; K = 5</code>, so it has to wrap around and get <code>N-1; 0; 1; 2; 3</code>), as another <code>bitset&lt;K&gt;</code> (K is of course known at compile-time)</p>
  
  <p>The obvious thing doesn't work because <code>operator &amp;</code> doesn't allow operands of different sizes (although it would be trivial?)</p>
  
  <pre><code>bitset&lt;N&gt; data = ...;
  bitset&lt;K&gt; mask; mask = ~mask;
  bitset&lt;K&gt; rotated = in &lt;&lt; i | in &gt;&gt; (K - i);
  bitset&lt;K&gt; slice = rotated &amp; mask;
  </code></pre>
  
  <p>The next best thing doesn't work with large <code>N</code></p>
  
  <pre><code>bitset&lt;K&gt; slice( rotated.to_ullong() &amp; mask.to_ullong() );
  </code></pre>
  
  <p>What to do, short of implementing <code>bitset&lt;min&lt;N,K&gt;::value&gt; operator &amp;(bitset&lt;N&gt;,bitset&lt;K&gt;)</code>? (and maybe not as terribly inefficient, this approach copies the set 3 times)</p>