|
Boost : |
Subject: Re: [boost] [lexical_cast] Fast conversion from boost::iterator_range<std::string::iterator>?
From: Michel Morin (mimomorin_at_[hidden])
Date: 2012-01-26 12:58:16
Olaf van der Spek wrote:
> On Thu, Jan 26, 2012 at 6:14 PM, Michel Morin <mimomorin_at_[hidden]> wrote:
>> IIUC, the main concern to implement optimized code is that
>> how to obtain begin and end pointer to CharT from `iter_rng` safely.
>> With C++11-conforming standard library, it is safe to implement
>>
>> bool operator<<(::boost::iterator_range<std::string::iterator> const& str)
>> {
>> if (!str.empty()) {
>> start = const_cast<CharT*>(&str.front());
>> finish = start + str.size();
>> }
>> else {
>> start = 0;
>> finish = 0;
>> }
>> return true;
>> }
>>
>> because `&*(s.begin() + n) == &*s.begin() + n` (`s` is an object of
>> std::basic_string<
>)
>> is guaranteed.
>>
>> But, in C++03, the above code is not safe; the standard does not guarantee that
>> std::basic_string<
> is stored contiguously (though many standard library
>> implementations store it contiguously).
>
> What about using c_str() instead of begin()? It does provide that
> guarantee in C++03.
We cannot use c_str() because we only have iterators.
P.S.
Antony, I created a trac ticket but could not change the owner to you.
Could you take a look at it?
https://svn.boost.org/trac/boost/ticket/6453
Regards,
Michel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk