Boost logo

Boost :

Subject: Re: [boost] [string] proposal
From: Matus Chochlik (chochlik_at_[hidden])
Date: 2011-01-26 03:09:01


On Mon, Jan 24, 2011 at 12:59 PM, Dean Michael Berris
<mikhailberis_at_[hidden]> wrote:
> On Mon, Jan 24, 2011 at 7:50 PM, Artyom <artyomtnk_at_[hidden]> wrote:
>>> From: Dave Abrahams <dave_at_[hidden]>
>>> On Fri, Jan 21, 2011 at 4:31 PM, Nevin Liber <nevin_at_[hidden]>  wrote:
>>> >
>>> > Eliminating #2 but not  #1 would force c_str() to make a (possibly tracked)
>>> > copy, to avoid #2 on  its internal buffer (due to the trailing '\0' byte).
>>>
>>> Who says we need a  c_str()?
>>>
>>
>> Almost everybody who uses any kind of API that does not has direct uses
>> of this string and this is as almost every API around...
>>
>
> Right, but what's keeping that person from creating an std::string
> from this hypothetical `boost::string` if they really need a c_str()?
>

In the last couple of days I browsed through
some of the code that I wrote or that I have access
to and this is not some marginal use-case.

I don't say that the sources are statistically
representative or anything, but using string
to interact with the OS's APIs is actually one of
the most prevalent use-cases. I don' t think
it is a good idea to focus on getting the basic string
manipulation to be uber-efficient at the expense
of performance of the string in a "real-world" context.

Your program does not always look like:

int main(void)
{
  boost::string your_string;
  do(something(really(cool(and(efficient(with(your_string)))))));
  return 0;
}

many time you do things like:
a) read file, parse its contents, create instances from the data
b) get string from a socket, manipulate it, display it in the GUI
c) get a string from a GUI, save it into a config file
d) take a string literal, localize/translate by gettext, show it
etc.

In order for this thing to be widely adopted (which is one
of my goals) it has to be nice to the existing APIs and let's
face it, most of them expect std::string or just plain ol' char*.

BR,

Matus


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