title: Understanding the std::search predicate
body: <p>I am trying to understand the s<code>td::search</code> predicate which I read about from <a href="https://stackoverflow.com/questions/3152241/case-insensitive-stdstring-find">here</a>. I have posted it below for convenience. </p>
  
  <pre><code>#include &lt;algorithm&gt;
  #include &lt;string&gt;
  #include &lt;cctype&gt;
  
  // haystack=Hello and needle=World
  /// Try to find in the Haystack the Needle - ignore case
  bool findStringIC(const std::string &amp; strHaystack, const std::string &amp; strNeedle)
  {
    auto it = std::search(
      strHaystack.begin(), strHaystack.end(),
      strNeedle.begin(),   strNeedle.end(),
      [](char ch1, char ch2) { 
  
        std::cout &lt;&lt; ch1 &lt;&lt; "?" &lt;&lt; ch2 &lt;&lt; "\n";
      return std::toupper(ch1) == std::toupper(ch2); 
     }
    );
    return (it != strHaystack.end() );
  }
  </code></pre>
  
  <p>Essentially I am confused by how it(the predicate) works. Suppose the haystack is the word <code>Hello</code> and the needle is the word <code>World</code>. Now from what I have observed is that the first letter of needle will get compared to all the letters of haystack - so <code>W</code> will get compared to <code>H</code> then <code>E</code> then <code>L</code>.... so </p>