title: C++ Find last ocurrence of a string inside a substring
body: <p>I need a method that helps me to find a string inside another substring, or in other words, find a string inside a subrange of other string. Besides, I need to find it in reverse order because I know that the string I'm looking for is closed to the end of the substring used as "haystack".</p>
  
  <p>Let's suppose the following piece of code, where <code>rfind_in_substr</code> is the method I'm asking for:</p>
  
  <pre><code>std::string sample("An example with the example word example trice");
  
  // substring "ample with the example wo"
  std::size_t substr_beg = 5;
  std::size_t substr_size = 24;
  
  // (1)
  std::size_t pos = rfind_in_substr(sample, substr_beg,
                                    substr_size, "example");
  
  // pos == 20, because its the index of the start of the second
  // "example" word inside the main string. 
  </code></pre>
  
  <p>Of course, the line (1) could be replaced by:</p>
  
  <pre><code>std::size_t pos = substr_beg + sample.substr
              (substr_beg, substr_size).rfind("example");
  </code></pre>
  
  <p>But that implies an unnecesary copy of the substring. Is there any method or C++/boost method that could help me doing that?</p>
  
  <p>I was looking at <code>boost::algorithm::string</code> library but I've found nothing (that I had understood). I know that C++17 has the <code>std::string_view</code> class, that would be perfect, but I'm using C++14.</p>