title: Why cannot bind ‘const char*’ lvalue to ‘const char* const&&?
body: <p>I am doing exercises on "C++ Primer 5th" ex16.63 and 64, and the description about these exercises is following.</p>
  
  <p>Exercise 16.63: Define a function template to count the number of occurrences of a given value in a vector. Test your program by passing it a vector of doubles, a vector of ints, and a vector of strings.</p>
  
  <p>Exercise 16.64: Write a specialized version of the template from the
  previous exercise to handle vector&lt; const char* > and a program that
  uses this specialization.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  
  // ex16_63
  template&lt;typename T&gt;
  std::size_t VecCount(const std::vector&lt;T&gt; &amp;vec, const T &amp;&amp;val){
      std::size_t num = 0;
      for(auto i: vec){
          if(val == i) ++num;
      }
      return num;
  }
  
  //ex16_64
  template&lt;&gt;
  std::size_t VecCount(const std::vector&lt;const char*&gt; &amp;vec, const char* const &amp;&amp;val){
      std::size_t num = 0;
      for(auto i: vec){
          if(val == i)++num;
      }
      return num;
  }
  
  int main()
  {
      // ex16_63
      std::vector&lt;int&gt; nVec = {1, 2, 3};
      std::vector&lt;double&gt; dVec = {3.14, 2.24, 3.14};
      std::vector&lt;std::string&gt; sVec = {"hello", "python", "python"};
      std::cout &lt;&lt; VecCount(nVec, 1) &lt;&lt; ' '
                &lt;&lt; VecCount(dVec, 3.14) &lt;&lt; ' '
                &lt;&lt; VecCount(sVec, std::string("python")) &lt;&lt; std::endl;
  
      // ex16_64
      std::vector&lt;const char*&gt; cVec = {"world", "turing", "turing"};
      const char *p = "turing";
      std::cout &lt;&lt; VecCount(cVec, p) &lt;&lt; std::endl; // wrong
      //std::cout &lt;&lt; VecCount(cVec, std::move(p)) &lt;&lt; std::endl; // correct
      return 0;
  }
  </code></pre>
  
  <p>There's an error while compiling <code>ex16_64</code>:</p>
  
  <pre><code>error: cannot bind ‘const char*’ lvalue to ‘const char* const&amp;&amp;’ std::cout &lt;&lt; VecCount(cVec, p) &lt;&lt; std::endl;
  </code></pre>
  
  <p>I don't understand that my code about <code>ex16_64</code> is wrong without <code>std::move</code>, while my code about <code>ex16_63</code> is correct.</p>