Subject: Re: [boost] Heads up - string_ref landing
From: Rob Stewart (robertstewart_at_[hidden])
Date: 2012-12-13 05:33:50
On Dec 12, 2012, at 3:58 PM, Sergey Cheban <s.cheban_at_[hidden]> wrote:
> 12.12.2012 20:02, Rob Stewart Ð¿Ð¸ÑÐµÑ:
>>>>>>>> - 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.
>>> If the basic_substring<T> was convertible to bool, it would be used to compare basic_substring<char> with basic_substring<wchar_t> (with meaningless results).
>> It would not be meaningless. Though certainly not the likely intent. Still, all that's needed are equality
> > operators between the types to poison the flawed comparison.
> Ok. What about boost::lexical_cast? There is no lexical_cast<unsigned>(const string_ref &) yet but there already is lexical_cast<unsigned>(bool). So, lexical_cast<unsigned>( string_ref("5") ) will return 1.
This is a safe-bool operator we're discussing. In C++11, it's an explicit bool conversion operator.
>>>>>>> And again, I propose "substring" instead of "string_ref".
>>>>>> I also have [const_]substring classes which have a different interface, so I disagree. (There is, of course, some overlap.)
>>>>> 1. Are these classes in the Boost library and/or namespace?
>>>> No. They are my own classes which I've not proposed to Boost.
>>> I respect your needs but I don't think that it is a good idea for the Boost library to avoid using convenient names just because these names are used by somebody who uses the boost namespace implicitly.
>> I don't understand how your comment applies.
> You said that the Boost library should not use the "substring" name for the class that represents (but does not own) a part of the existing string because you already use this name for the class with the same meaning in your private code.
Ah, I see the confusion now. I meant that I see substrings as being different, so "string_ref" is more appropriate for the current purpose.
>>>>> 2. Do these classes do a different job, or they just have a different interface?
>>>> They reference a std::string and operate on a subset of the string's characters. The have special constructors and replicate most of string's interface.
>>> It seems that you may just switch to the boost::substring and get rid of your substring implementation some day.
>> Of course, but there isn't one and this discussion is about string_ref.
> For me, "substring" is just an alternative name of string_ref. The string_ref looks worse for me because:
> 1. It is not a kind of C++ reference.
> 2. It is not related to the std::string.
> So, both parts of the name "string_ref" are misleading.
We use "string" in reference to char *'s, too. string_ref extends that to any sequence of characters, not necessarily null terminated.
string_ref refers to memory owned elsewhere, so it is a reference to that memory. It is the broader English meaning of "reference" we're using, not the C++ meaning.
Notice also my description of my substring class as operating on a std::string. It doesn't operate on any other sequence of characters, hence my distinguishing their names.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk