title: How to efficiently get a `string_view` for a substring of `std::string`
body: <p>Using <a href="http://en.cppreference.com/w/cpp/string/basic_string_view" rel="noreferrer">http://en.cppreference.com/w/cpp/string/basic_string_view</a> as a reference, I see no way to do this more elegantly:</p>
  
  <pre><code>std::string s = "hello world!";
  std::string_view v = s;
  v = v.substr(6, 5); // "world"
  </code></pre>
  
  <p>Worse, the naive approach is a pitfall and leaves <code>v</code> a dangling reference to a temporary:</p>
  
  <pre><code>std::string s = "hello world!";
  std::string_view v(s.substr(6, 5)); // OOPS!
  </code></pre>
  
  <p>I <em>seem to remember</em> something like there might be an addition to the standard library to return a substring as a view:</p>
  
  <pre><code>auto v(s.substr_view(6, 5));
  </code></pre>
  
  <p>I can think of the following workarounds:</p>
  
  <pre><code>std::string_view(s).substr(6, 5);
  std::string_view(s.data()+6, 5);
  // or even "worse":
  std::string_view(s).remove_prefix(6).remove_suffix(1);
  </code></pre>
  
  <p>Frankly, I don't think any of these are very nice. Right now the best thing I can think of is using aliases to simply make things less verbose.</p>
  
  <pre><code>using sv = std::string_view;
  sv(s).substr(6, 5);
  </code></pre>