
26.11.12, 20:54, "Daniel James" <dnljms@gmail.com>":
On 26 November 2012 11:56, Andrey Semashev <andrey.semashev@gmail.com> wrote:
The problem with std::string is the same as with string_ref - it doesn't support implicit construction from an arbitrary range, so my examples with custom string types would still not work.
Shouldn't construction from an arbitrary range be explicit? Arbitrary implicit conversions are problematic. To get implicit construction from third party strings, I'd use some sort of explicit customisation mechanism.
Hi Daniel, I'm fully with you here. The construction of string_ref should be explicit (except maybe literals if we can detect them in compile time) as we're giving away pointers to something that is externally managed. Look at std::string::c_str/data, any smart_ptr::get etc - everything is explicit for a reason. Implicit conversions to pointers are very dangerous here. No containers give away their internals implicitly, and this is Good Thing. 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. Thanks, Maxim