Boost logo

Boost :

Subject: Re: [boost] Heads up - string_ref landing
From: Daniel James (dnljms_at_[hidden])
Date: 2012-11-27 06:42:08


On 26 November 2012 14:13, Andrey Semashev <andrey.semashev_at_[hidden]> wrote:
> On Mon, Nov 26, 2012 at 5:48 PM, Daniel James <dnljms_at_[hidden]> wrote:
>>
>> A string isn't the same thing as a range of characters.
>
> Why?

Strings are one of the most important types in programming, and
they're usually handled differently from ranges. A string is
essentially a thing, not a sequence of things. Using a range confuses
the string's representation for its type. A range of characters can be
binary data, or a collection of small integers, I don't want them
coming anywhere near string handling code, and in C++ the type system
is the best way to handle that. It should be easy to have distinct
overloads for strings and ranges.

>>> is not implicitly convertible from other string types then it
>>> is useless for use cases I pointed out. The thing is to make
>>> interfaces transparently support any string types.
>>
>> That's why I suggested a customisation mechanism. Something would
>> allow you to indicate that a third party type is a string and, if
>> necessary, how to get a string_ref from it. Perhaps an ADL hook, or a
>> template class that is specialized for strings, or something else
>> entirely.
>
> That would mean that the range is limited to strings only.

Not at all, you could still explicitly convert to a string_ref.


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