
On Tue, Nov 27, 2012 at 9:48 AM, Jeffrey Lee Hellrung, Jr. <jeffrey.hellrung@gmail.com> wrote:
On Mon, Nov 26, 2012 at 7:03 PM, Yanchenko Maxim <maximyanchenko@yandex.ru>wrote:
Consider a vector of pointers, for example. You don't want to implicitly put a pointer managed by a smart pointer there, you want it to be explicit so it's visible and you don't forget putting reset/release near a push_back. Same applies to a vector of string_ref - you want to be sure that the string referred by it lives as long a needed, and there is no other way except explicit construction.
I was under the impression that string_ref's proposed purpose was to provide a generic concrete (i.e., non-template) interface for string algorithms (both as parameters and results), and for this purpose, the above arguments seem irrelevant. The lifetime concerns are no worse than for a std::string const &.
+1, string_ref by definition doesn't own the referred characters. Its presence is enough indication that the storage of the characters has to be managed elsewhere. And from the user's perspective it should be as transparent as possible.