title: How to use enable_if correctly?
body: <p>I need to learn how to use enable_if. For this I need to reimplement the distance function using enable_if. I tried this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;list&gt;
  #include &lt;utility&gt;
  #include &lt;type_traits&gt;
  
  template&lt;class In&gt;
  typename std::enable_if&lt;!std::is_random_acces_iterator&lt;In&gt;::value, std::iterator_traits&lt;In&gt;::difference_type&gt;::type  my_distance(In begin, In end, std::input_iterator_tag dummy){
    typename std::iterator_traits&lt;In&gt;::difference_type n = 0;
    while(begin!=end){
      ++begin; ++n;
    }
    std::cout &lt;&lt; "STEPPING" &lt;&lt; std::endl;
    return n;
  }
  
  template&lt;class Ran&gt;
  typename std::enable_if&lt;std::is_random_acces_iterator&lt;Ran&gt;::value, std::iterator_traits&lt;In&gt;::difference_type&gt;::type my_distance(Ran begin, Ran end, std::random_access_iterator_tag dummy){
    std::cout &lt;&lt; "RANDOM" &lt;&lt; std::endl;
    return end - begin;
  }
  
  template &lt;class I&gt; inline
  typename std::iterator_traits&lt;I&gt;::difference_type my_distance_wrapper(I begin, I end){
    typedef typename std::iterator_traits&lt;I&gt;::iterator_category cat;
    return my_distance(begin, end, cat());
  }
  
  int main() {
    std::vector&lt;int&gt; ve;
    std::list&lt;int&gt; li;
    for(int i = 0; i &lt; 3; i++){
      ve.push_back(i);
      li.push_back(i);
    }
    std::cout &lt;&lt; my_distance_wrapper(ve.begin(), ve.end()) &lt;&lt; std::endl;
    std::cout &lt;&lt; my_distance_wrapper(li.begin(), li.end()) &lt;&lt; std::endl;
    return 0;
  }
  </code></pre>
  
  <p>I thought I could do this by using some function like <code>std::is_random_acces_iterator&lt;In&gt;::value</code> similar to <code>std::is_pod&lt;In&gt;::value</code>
  I checked the <a href="http://www.cplusplus.com/reference/type_traits/" rel="nofollow noreferrer">type_traits</a> but could not find anything for checking if something is a specific iterator.
  How would I check if something is an random_acces_iterator? I know I could just do this in a function: </p>
  
  <pre><code>template&lt;class T&gt;
  bool f(){
    typedef typename std::iterator_traits&lt;T&gt;::iterator_category cat;
    return std::random_access_iterator_tag == cat();
  }
  </code></pre>
  
  <p>So my question is basically how do I do function f in a template? And no not using enable_if is not possible, it is a requirement of my task. And am I correct to believe that SFINAE would correctly discard the other function, if I could get function f into that template?</p>