Hi Agustín, Agustín K-ballo Bergé wrote:
On 31/07/2014 04:53 a.m., Андрей Давыдов wrote:
Those errors can be caught at compile time if class "basic_string_ref" defintion would contain lines like following:
template<typename Allocator> basic_string_ref(std::basic_string
&&) = delete; I cannot understant does it prevent any correct usage of string_ref?
I don't think this is such a good idea. Unless I'm mistaken, it would break the typical case of calling a function taking a `string_ref` with a temporary.
A `string_ref` does not own the contents it represents, and the only way to use it correctly is by guaranteeing that the lifetime of the contents extends past that of the reference. You wouldn't generally use `string_ref`s as automatic variables or members.
I suppose that would break cases like: std::string getStr(); print(std::string_ref sr) { std::cout << sr << std::endl; } print(getStr()); Causing people to have to write print(getStr().c_str()). There doesn't seem to be a good, compile-time way to catch misuse. Your suggestion on avoiding using string_ref as a class member seems good. Nate