Boost logo

Boost :

Subject: Re: [boost] Heads up - string_ref landing
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2012-11-16 08:33:24

On 16/11/12 14:04, Olaf van der Spek wrote:
> On Fri, Nov 16, 2012 at 2:00 PM, Mathias Gaunard
> <mathias.gaunard_at_[hidden]> wrote:
>> On 16/11/12 06:30, Jeffrey Lee Hellrung, Jr. wrote:
>>> How is this different from (say) contiguous_range< char > /
>>> contiguous_range< char const > ? I can imagine a contiguous_range<T> that
>>> wraps a pair of T*s, which would seem to be a simple generalization of
>>> your
>>> proposed string_ref.
>> It isn't.
>> The only difference is that string_ref provides an interface for substring
>> operations, similar to std::string but without returning copies of the data,
>> hence the string in the name.
> That'd be better as a non-member function, wouldn't it?

It arguably would, but that wouldn't mimic std::string's interface.

I'm talking of stuff like

string_ref a = "foobar";
string_ref b = a.substr(2, 4);
assert( b == "obar" );

This is somewhat equivalent to the same code without the "_ref", except
the above doesn't actually copy anything (modifying b will modify a).

See the paper for more info.

Boost list run by bdawes at, gregod at, cpdaniel at, john at