From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2003-10-20 08:18:47
"Bronek Kozicki" <Brok_at_[hidden]> wrote in message
> We might have two overloaded versions of mutating algorithms:
> inplace_proxy<std::string&> trim(inplace_proxy<std::string&>);
> std::string trim(const std::string &);
> which will make both variants very easy to distinguish. Additional bonus
> is that you can nest calls to both variants in very natural manner:
> ucase(trim(in_place(str1))); // in place
> std::string str3 = ucase(trim(str2)); // using temporary copies
I'd vote for this over the "_copy" / "_inplace" approach
> There is a problem, though: proxy class (or template, as proposed above)
> will add small overhead, which is problem for "in-place algorithms" as
> these might be expected to be significaly faster than "copying
> algorithms", thus carrying as small overhead as possible.
Then isn't this a good application for using namespaces rather than adding
using namespace boost::string_algo;
trim(to_upper("SomeStuff") ); // error - not defined in this namespace
using namespace in_place; // I'm an in_place kind of guy
::FunctionOperatingOnAString( trim(to_upper("SomeStuff") ) )
std::string str1(" hello world! ");
std::string str2 = copy::ireplace_first( str1, "hello", "goodbye" );
1) Puts defaulting into the hands of the user, without playing favorites.
2) Makes explicit the default and non-default usage.
3) Uses a common C++ facility in it's intended fashion.
4) Reduces complexity of both usage and implementation.
5) Makes structure of code and documentation more consistent.
-- Jeff Flinn Applied Dynamics, International
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk