Tomás wrote:
[color=blue]
> 1) The "statement" object is default constructed, and the an assignment
> is performed. This is inefficent -- it should have just been a
> construction:
>
> string statement("bla bla");[/color]
The compiler is required to directly call the constructor, even if = is
used.
[color=blue]
> 2) There's no point in creating that nameless temporary in the "return"
> statement. It could simply be:
>
> return statement;[/color]
I do know that Return Value Optimization could make one of the strings
inside the function become an alias for the final string outside the
function. But I don't know how aggressive that rule is. Suppose the copy
constructor for std::string had a side effect that you could count. RVO will
make one of those side effects go away. (That's why it's a permitted
optimization and defined as "lossy"; so programmers will know better than to
depend on the number of side-effects from such constructors.)
Will RVO make all of this go away?
return string(string(string(string(string(string(statemen t))))));
[color=blue]
> 3) A proficient programmer would probably write:
>
> string PublishedProductsRepo :: CreateStatement() const
> {
> return
> "SELECT DISTINCT "
> "* "
> "FROM "
> "map";
> }[/color]
And the next level of proficiency avoids this AntiPattern:
http://c2.com/cgi/wiki?PerniciousIngrownSql
--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!