This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Specialize string::replace


Paolo Carlini <pcarlini@unitus.it> writes:

> now that we have branched I'd like to proceed for 3.2 with the
> implementation of the string class improvements outlined
> by Nathan. Below you will find a patch which specializes
> 
> template<class _InputIterator>
>   basic_string&
>   replace(iterator __i1, iterator __i2,
>           _InputIterator __k1, _InputIterator __k2)
> 
> for the common cases of _InputIterator as pointer, const pointer,
> iterator and const_iterator. It is overall quite straightforward
> and indeed I have verified that it enables the optimization of the
> assign, insert and replace members which have the source data
> specified in terms of iterators. My only doubt is about the ugly
> reinterpret_cast: is there any cleaner way to obtain from a _CharT*,
> iterator or const_iterator, the required const _CharT* ?

iterator is __normal_iterator<pointer, basic_string> and has a base()
member function that returns a pointer. pointer is the basic_string's
allocater's pointer type. Is this sufficient? (Even if it is not
sufficient, it is probably necessary before casting.)

Similarly, const_iterator is __normal_iterator<const_pointer, basic_string>
and here the base() member function returns a const_pointer.

Do you really have to cast _CharT* to get const _CharT*? Isn't that a
standard conversion?

-- 
Philip


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]