title: Find index of iterator in STL container - need template function
body: <p>I want to have a function with interface like this:</p>
  
  <pre><code>template&lt;typename T, typename R&gt; int find_index (const T&amp; list, const R&amp; value);
  </code></pre>
  
  <p>As I know, there is <code>find()</code> in STL that returns iterator. I need to return index of iterator (even for non-indexed containers such as <code>std::list</code>). I tried this code:</p>
  
  <pre><code>template&lt;typename T, typename R&gt;
  int find_index (const T&amp; list, const R&amp; value)
  {
      int index = 0;
      for (T::const_iterator it = list.begin(); it != list.end(); it++, index++)
          if ((*it) == value)
              return index;
      return -1;
  }
  </code></pre>
  
  <p>But compiler shows error on <code>it</code> - seems like it is not allowed to get <code>const_iterator</code> from templated typename. Can I go around it?</p>
  
  <p>At the worst case I can pass begin and end iterators to find_index arguments, but it looks not so fine. Would be thankful for elegant solution.</p>