title: What drawbacks would exist if std::string::substr returned std::string_view?
body: <p>Look at this example (taken from <a href="http://foonathan.net/blog/2017/03/22/string_view-temporary.html" rel="noreferrer">here</a>):</p>
  
  <pre><code>class foo {
      std::string my_str_;
  
  public:
      std::string_view get_str() const {
          return my_str_.substr(1u);
      }
  };
  </code></pre>
  
  <p>This code is bad, because <code>substr</code> returns a temporary <code>std::string</code>, so the returned <code>std::string_view</code> refers to an already-destroyed object. But, if <code>substr</code> returned <code>std::string_view</code>, this problem would not exist.</p>
  
  <p>Besides, it seems logical to me if <code>substr</code> returned <code>std::string_view</code> instead of <code>std::string</code>, because the returned string is a view of the string, and it is more performant, because no copy is made.</p>
  
  <p>Would there be any drawbacks if <code>substr</code> returned <code>std::string_view</code> (besides the obvious drawback: losing some compatibility with C++14 - I'm not underrating the importance of this, I'd just like know whether other drawbacks exists)?</p>
  
  <p>Related question: <a href="https://stackoverflow.com/questions/46032307/how-to-efficiently-get-a-string-view-for-a-substring-of-stdstring">How to efficiently get a `string_view` for a substring of `std::string`</a></p>