Boost logo

Boost :

Subject: Re: [boost] Heads up - string_ref landing
From: Jeff Flinn (Jeffrey.Flinn_at_[hidden])
Date: 2012-12-12 11:59:38

On 12/12/2012 10:49 AM, Rob Stewart wrote:
> On Dec 12, 2012, at 8:21 AM, Yakov Galka <ybungalobill_at_[hidden]> wrote:
>> On Wed, Dec 12, 2012 at 2:55 PM, Rob Stewart <robertstewart_at_[hidden]>wrote:
>>> On Dec 12, 2012, at 2:38 AM, Yakov Galka <ybungalobill_at_[hidden]> wrote:
>>>> On Tue, Dec 11, 2012 at 11:47 PM, Rob Stewart <robertstewart_at_[hidden]
>>>> wrote:
>>>>> On Dec 10, 2012, at 7:55 AM, Sergey Cheban <s.cheban_at_[hidden]> wrote:
>>>>>> On 09.12.2012 17:13, Rob Stewart wrote:
>>>>>>>>> - safe bool or explicit bool conversion operator
>>>>>>>> I don't think this is a good idea.
>>>>>>> Why not?
>>>>>> This seems to be not intuitive and not so safe.
>>>>> It is quite intuitive to me. true means non-null, and false means null.
>>>> Would it mean !empty() or !!begin()?
>>> The former certainly. string_ref's are never assumed to be null terminated (which is why I provide data() and not c_str()), so the latter is not
>>> sensible.
>> I wrote !!begin(), not !!*begin(). In other works string_ref can *actually be a null pointer*, or at least I haven't seen anyone saying the contrary.
> Of course. I misread your intent. You're assuming that the iterator type is a pointer. Besides, if string_ref holds a null pointer, I'd expect empty() to return true. Thus, the operator, and empty(), always mean a string with no characters.
>>>> The std::string has no such operator.
>>>>> Why does that matter? It's still convenient. It would be a nice addition to std::string.
>>>> std::string does not have a 'null' state.
>>> It's the state represented by empty().
>> I am not sure it is so certainly accepted by all.
> It is the logical interpretation. It indicates whether the string is non-empty. I don't see any other generally useful interpretation, do you?


Code like:

if(string_ref sr = func(...))
    // operate only on non-empty string_refs

IMHO, shouldn't matter whether sr refers to null of size 0, or to some
empty range whose begin() may still refer to a valid location in a
larger range.


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