title: Fastest way to compare bitsets (< operator on bitsets)?
body: <p>What is the most optimized way to implement a <code>&lt;</code> operator for <code>std::bitset</code> corresponding to the comparison of the unsigned integer representation (it should work for bitsets of <code>more than 64 bits</code>) ? </p>
  
  <p>A trivial implementation would be:</p>
  
  <pre><code>template&lt;std::size_t N&gt;
  bool operator&lt;(const std::bitset&lt;N&gt;&amp; x, const std::bitset&lt;N&gt;&amp; y)
  {
      for (int i = N-1; i &gt;= 0; i--) {
          if (x[i] &amp;&amp; !y[i]) return false;
          if (!x[i] &amp;&amp; y[i]) return true;
      }
      return false;
  }
  </code></pre>
  
  <p>When I say "most optimized way" I am looking for implementations using bitwise operations and metaprogramming tricks (and things like that).</p>
  
  <p>EDIT: I think that I've found the trick: template metaprogramming for compile-time recursion and right bitshift in order to compare bitsets as several unsigned long long integers. But no clear idea of how to do that... </p>