|
Boost : |
Subject: Re: [boost] [algorithm] to_lower_copy / to_upper_copy with no output param assumes sequence to be same as input
From: Sebastian Karlsson (sairony_at_[hidden])
Date: 2011-06-23 15:47:18
2011/6/23 Sebastian Karlsson <sairony_at_[hidden]>:
> 2011/6/23 Olaf van der Spek <ml_at_[hidden]>:
>> On Thu, Jun 23, 2011 at 1:26 PM, Sebastian Karlsson <sairony_at_[hidden]> wrote:
>>>>> OutputSequenceT Output( ::boost::begin( Input ), ::boost::end( Input ) );
>>>>
>>>> Doesn't this also do an unnecessary copy?
>>>>
>>>> Olaf
>>>
>>> It does, but it uses one less which as stated is a prime candidate for
>>> NRVO. The current approach needs one temporary for the return value as
>>> well as a temporary for argument conversion, which is basically only
>>> there to inform about the return type.
>>
>> OutputSequenceT Output( ::boost::begin( Input ), ::boost::end( Input ) );
>>
>> This one copies input to output. Then the function does case conversion.
>> The original (AFAIK) does the case conversion while copying from input
>> to output.
>>
>> Olaf
>
> That appears to be truth, that's only a flaw in my implementation
> though, I'll see if I can fix it :)
>
> Kind regards,
> Sebastian Karlsson
>
Seems to be easier than I anticipated, just add output type as a param
and slap it in as the return type for transform_range_copy, like so:
template<typename SequenceT, typename OutputT >
inline SequenceT to_lower_copy(
const SequenceT& Input,
const std::locale& Loc=std::locale())
{
return ::boost::algorithm::detail::transform_range_copy< OutputT >(
Input,
::boost::algorithm::detail::to_lowerF<
typename range_value<SequenceT>::type >(Loc));
}
Seems to work with the little testing I've been able to do so far.
Kind regards,
Sebastian Karlsson
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk