title: finding the correct entry in a C++ map using upper and lower bound
body: <p>I'm trying to optimize my search in a <code>C++</code> <code>map</code> by using the <code>upper_bound</code> function:
  The <code>map</code> is the variable <code>table</code>:</p>
  
  <pre><code>Foo&amp; search(uint64 id, uint64 hash) {
  
     std::map&lt;std::pair&lt;uint64, uint64&gt;, Foo&gt;::const_iterator iter;
  
     std::pair&lt;uint64, uint64&gt; key(id, hash);
     iter = table.upper_bound(key);
     // for completeness I search for those elements which may be a match
     // they may fall into a different hash range
  
     for( ; iter != table.end() || iter != table.begin(); --iter ) {
           const Foo foo = iter-&gt;second;
           if(foo.id() == foo.first_hash() &lt;= hash &amp;&amp;
              hash &lt;= foo.second_hash()) {
              if( foo.state() == NORMAL) {
                     return foo;
              }
              else {
              // do something else
              }
          }
     }
  </code></pre>
  
  <p>However, when I execute the program it just hangs ... it looks like the search is not working at all, and I don't have the logs to tell me where the mistake was ... What am I doing wrong here? When I do a linear search, it works fine, but now when I try to improve the algorithm it fails ... </p>