Boost logo

Boost :

Subject: Re: [boost] [string] Realistic API proposal
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-01-29 02:25:26


AMDG

On 1/28/2011 11:04 PM, Artyom wrote:
>> // with a string-aware function
>> socket.read(my_string);
>> if (!is_valid_utf8(my_string.begin(),my_string.end())) ....
>>
>> // with a C interface
>> std::vector<char> vec;
>> vec.resize(MY_BUFSIZE);
>> int len = recv(socket, vec.data(), MY_BUFSIZE, 0);
>> if (len>= 0) {
>> vec.resize(len);
>> if (!is_valid_utf8(vec.begin(), vec.end())) ....
>> }
>>
>> // conversion for Windows API
>> std::vector<wchar_t> vec;
>> vec.resize(count_codepoints<utf8>(mystring.begin(), mystring.end()));
>> convert<utf8,utf16>(mystring.begin(), mystring.end(), vec.begin());
>> HRESULT hr = WriteFile(handle, vec.data(), vec.size(),&dwBytesWritten,
>> NULL);
>> ...
>>
>
> Notice vector is not string and it requires additional copy
>

An additional copy compared to what?
I don't see anything particularly wrong
with using vector here.

In Christ,
Steven Watanabe


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