Boost logo

Boost :

Subject: Re: [boost] [string] Realistic API proposal
From: Anders Dalvander (boost_at_[hidden])
Date: 2011-01-29 05:15:43


On 2011-01-28 23:04, Artyom<artyomtnk_at_[hidden]> wrote:
>> > // 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

If std::string is UTF-8 encoded (as you are suggesting, correct?), then
you also requires additional copy:

    // conversion for Windows API
    std::string u8s = ...;
    std::wstring u16s = convert_to_utf16(u8s);
    HANDLE h = CreateFileW(u16s.c_str(), ...);

Regards,
Anders Dalvander

-- 
WWFSMD?

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