Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason is that your <code>K</code> and <code>V</code> type parameters are in a non-deducible context, so your function template is never even instantiated during overload resolution. </p> <p>Look at it again:</p> <pre><code>template &lt;typename K, typename V&gt; map_keys_iterator&lt;K,V&gt; map_keys(const typename std::map&lt;K,V&gt;::iterator &amp;i) </code></pre> <p>For this to work, the C++ compiler would somehow have to walk from a specific <code>iterator</code> class to its "parent container" type - <code>map</code> in this case - to get its <code>K</code> and <code>V</code>. In general, this is impossible - after all, a particular <code>iterator</code> might be a typedef for some other class, and the actual type of argument in the call is that other class; there's no way the compiler can "retrace" it. So, per C++ standard, it doesn't even try in this case - and, more generally, in any case where you have <code>typename SomeType&lt;T&gt;::OtherType</code>, and <code>T</code> is a type parameter.</p> <p>What you can do is make the entire parameter type a template type parameter. This requires some trickery to derive <code>K</code> and <code>V</code>, though.</p> <pre><code>template &lt;typename Iterator&gt; map_keys_iterator&lt; typename std::iterator_traits&lt;Iterator&gt;::value_type::first_type, typename std::iterator_traits&lt;Iterator&gt;::value_type::second_type &gt; map_keys(Iterator i) </code></pre> <p>Unfortunately, you'll have to repeat those two in the body of the function as well, when invoking the constructor of your type.</p> <p>As a side note, iterators are generally passed by value (they're meant to be lightweight).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload