Boost logo

Boost :

Subject: Re: [boost] Heads up - string_ref landing
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2012-11-15 15:51:15


On Nov 15, 2012, at 12:41 PM, "Phil Endecott" <spam_from_boost_dev_at_[hidden]> wrote:

> Marshall Clow wrote:
>> I'm about to check in some new functionality into the string_algo library; an implementation of string_ref.
>>
>> A string_ref is a non-owning reference to a string. It is implemented as a {pointer, length} pair, and is exceedingly useful
>> when parsing, and manipulating strings in "read-only" ways.

I mistyped:
        A string_ref is a non-owning reference to a contiguous sequence of characters.

>
> I did something like this once. I called mine const_string_facade - I also had a mutable version - and it was a template that took an iterator pair. This lets you adapt something like a vector<char> into a string.
>
> BUT, I think my feeling is that this is actually taking us in the wrong direction: my current coding style tries to avoid the "special" features of std::string and prefers the things that are common to other containers, and std::algorithms.

Yes. And No. ;-)

When you're writing generic code (and many of us do), you want to be as general as possible.
In that case, you want a pair of iterators, or .. a range!.

However, when you are dealing with contiguous runs of characters (a a surprisingly large set of cases), then a specific solution (like string_ref) can give you a significant performance boost. The LLVM experience has been quite enlightening about this, and while I don't have first-hand knowledge of what happened inside of Google, the reports I get from people there say the same thing.

-- Marshall

Marshall Clow Idio Software <mailto:mclow.lists_at_[hidden]>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk