Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-05-03 23:37:05


>From: "Noel Yap" <Noel.Yap_at_[hidden]>

> "Justin M. Lewis" wrote:
> > A little bit of an overly simple example. How about something more like
> >
> > Or, how about,
> > void GetFileName(c_in_out<std::string> path, const std::string &filter)
> > {
> > std::string fname;
> > FindFirstFileWithFilter(out(fname), path, filter);
> > path += "/";
> > path += fname;
> > }
>
> void GetFileName( ref< std::string > path, std::string const& filter )
> {
> .
> .
> .
> }
>
> I believe returning a string may be more optimal than passing in an out
> parameter since:
> - the compiler can optimize away constructor/destructor calls with RVO.
> For example:
>
> std::string cwd( MyGetCWD() );

I'd love to agree with you on this, but in the case of GetFileName(), where
you're passing in a string, and returning the same string modified, it can't
optimise away the returned string with RVO. In this case, an alternative is
to just say no to a function like this. :) For example by returning the
result, instead, as Joel and others have suggested.

Regards,

Terje


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