std::unordered_map::find using a type different than the Key type?
<p>I have an <code>unordered_map</code> that uses a string-type as a key:</p>

<pre><code>std::unordered_map&lt;string, value&gt; map;
</code></pre>

<p>A <code>std::hash</code> specialization is provided for <code>string</code>, as well as a 
suitable <code>operator==</code>. </p>

<p>Now I also have a "string view" class, which is a weak pointer into an existing string, avoiding heap allocations:</p>

<pre><code>class string_view {
    string *data;
    size_t begin, len;
    // ...
};  
</code></pre>

<p>Now I'd like to be able to check if a key exists in the map using a <code>string_view</code> object. Unfortunately,  <code>std::unordered_map::find</code> takes a <code>Key</code> argument, not a generic <code>T</code> argument.</p>

<p>(Sure, I can "promote" one to a <code>string</code>, but that causes an allocation I'd like to avoid.)</p>

<p>What I would've liked instead was something like</p>

<pre><code>template&lt;class Key, class Value&gt;
class unordered_map
{
    template&lt;class T&gt; iterator find(const T &amp;t);
};
</code></pre>

<p>which would require <code>operator==(T, Key)</code> and <code>std::hash&lt;T&gt;()</code> to be suitably defined, and would return an iterator to a matching value. </p>

<p>Is there any workaround?</p>