title: Count elements in vector or check whether element is in array in D
body: <p>How can I check whether an element is in an array or count occurences of a specific element?</p>
  
  <p>I know that I can hack that myself:</p>
  
  <pre><code>int main()
  {
    int [] a = [1,2,3,4,3,4,5,6,6,3,3,3];
    assert(count(a,6) == 2);
    assert(contains(a,7) == false);
    return 0;
  }
  
  uint count(T)(T[] a, T t){
    uint cnt = 0;
    foreach(elem; a){
      if(elem == t) ++cnt;
    }
    return cnt;
  }
  
  bool contains(T)(T[] a, T t){
    foreach(elem; a){
      if(elem == t) return true;
    }
    return false;
  }
  </code></pre>
  
  <p>but there must be a "library-way" to do it!</p>
  
  <p><strong>edit:</strong> I just compared std.algorithm's <code>canFind()</code> and my <code>contains()</code> and it turns out, that <code>contains</code> is faster. Strange but true.</p>