
On Wed, Jan 30, 2013 at 5:16 AM, Andreas Pokorny <andreas.pokorny@gmail.com>wrote:
Hi, When I made a first glance of the proposal I expected that string_ref is some kind of type erasing non owning holder of a reference to an arbitrary string class. The imperfect silver bullet for the diversity of string types.
Take a project that uses c++ libraries using std::string, Qt GUI and maybe a module that works with chunked strings (string composed out of a list of usually equally sized blocks of memory). At the boundaries of the software modules copies have to occur. Frequently the interface expects some kind of constant references to a certain string type. Most of the time the callee just wants to process the complete string or just a part of the string. So there might not even be the necessity to have random access hence no need for a contiguous copy of the string contents.
Thats why I would prefer a facility that only requires that the source string is a forward range of characters in an arbitrary encoding.
I do not think that it makes sense to only address contiguous sequences of characters.
It's somewhat of a compromise as a string_ref has very little access overhead compared to using a std::string or similar directly (I would think the only overhead, if any, is in the construction of the string_ref). A type-erased reference to a range of characters would have quite a bit of access overhead (everything would rely on dynamic dispatching). That said, there are certainly situations (e.g., module boundaries) where a type-erased string could make sense; for such situations, take a look at any_range within Boost.Range. - Jeff