On Wed, Mar 26, 2008 at 07:54:03PM -0400, rgheck wrote: >> Andre sayeth: >> >> On Wed, Mar 26, 2008 at 05:29:22PM -0400, rgheck wrote: >> > [...] >> > Comments welcome. And see the long FIXME about remaining issues. >> >> > + >> > + docstring embed(getParam("embed")); >> >> We use >> >> docstring embed = getParam("embed"); >> >> [Several occurences] > If you say so, OK. But there's a difference here, right? And isn't the > former more efficient? > > I ask seriously. That's what I had thought. And you know better than me.
The interesting case is actually std::string("hello") vs std::string s = "hello"; Conceptionally the former is direct construction whereas the latter is formally construction of a temporary followed by copy-construction. So you are right that the latter has the potential of being less efficient. However, the compiler is free _not_ to perform the copy (even if there were side effects...) - and that's what pretty much every compiler I used during the last ten years does. So even without any optimization formally switched on, both should produce identical code, and given that, I prefer the latter as it is one level less of parantheses. A related benefit is that the latter can't be mistaken as a function declaration whereas the former sometimes can, and the compiler is required by the Standard authors to chose the "wrong" option... Andre'