Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-10-19 16:48:26


"Gennadiy Rozental" <gennadiy.rozental_at_[hidden]> writes:

>> I looked at the library and I think it should be accepted. I have one
>> big concern, though, which IMHO must be addressed:
>
>> * The default should be copying algorithms, not modifying algorithms!
>
>> When I write to_upper( str ), a copy of str should be returned. This is
>> important as most users IMHO expect this. Maybe some other syntax for
>> the modifying version can be found. Some ideas:
>>
>> to_upper_inplace( str ); // easy
>>
>> or
>>
>> apply( to_upper, str );
>
> May we define trim so that:
>
> std::string res = trim( orig );
>
> generate copying algorithm, while
>
> trim( orig ) generate in place modifying one?

Not reasonably, at least for most algorithms. The problem is that in
trim(orig), with no assignment would only be able to detect the lack
of assignment in the destructor of the result of trim(orig).
Destructors are a dangerous place to do mutating operations on other
objects, especially if they can throw exceptions ;->

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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