title: Extract subset from boost dynamic_bitset
body: <p>I need to extract and decode the bits (idx, idx+1, ... idx+n_bits) from a given boost dynamic_bitset.
  I have created the following solution:</p>
  
  <pre><code>boost::dynamic_bitset&lt;&gt; mybitset(...);
  // build mask 2^{idx+n_bits} - 2^{idx}
  const boost::dynamic_bitset&lt;&gt; mask(mybitset.size(), (1 &lt;&lt; idx+n_bits) - (1 &lt;&lt; idx));
  // shift the masked result idx times and get long
  unsigned long u = ((mybitset &amp; mask) &gt;&gt; idx ).to_ulong();
  </code></pre>
  
  <p>It works well, but as this code is critical for the performance of my application, I am curious if there exists a better way to achieve this?</p>