title: Implement in_array in c++
body: <p>It's easy to find an item in a vector and we know how. It's also possible to find an item in an array if we know the length of the array. But starting from c++11 with the announcement of std:: end(), it looks like we can get the size of the array by calling its pointer, right?</p>
  
  <p>So this code works:</p>
  
  <pre><code>int arr[] = {1,2,3,4,5};
  int needle = 3;
  
  std::find(begin(arr), end(arr), needle);
  int* result = find(begin(arr), end(arr), needle);
  bool exists = result!=end(arr);
  </code></pre>
  
  <p>However, if this converted to a function:</p>
  
  <pre><code>bool in_array(int arr[], int needle){
      int* result = std::find(begin(arr), end(arr), needle);
      return result!=end(arr);
  }
  </code></pre>
  
  <p>Will not compile:</p>
  
  <blockquote>
    <p>error: no matching function for call to ‘begin(int*&amp;)’ int* result =
    std::find( std::begin(arr), std::end(arr), needle);</p>
  </blockquote>
  
  <p>The goal is to make a working function to send any type of array to it, just like <code>in_array</code> of Php:</p>
  
  <pre><code>template &lt;typename T&gt;
  T in_array(T arr[],T needle){
      T* result = std::find(begin(arr), end(arr), needle);
      return result!=end(arr);
  }
  </code></pre>
  
  <p>Why does this code not work? Does C++ compiler store some kind of a local variable to determine the end of <code>arr</code>?</p>