[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What tests are run by patchy?
From: |
Frédéric Bron |
Subject: |
Re: What tests are run by patchy? |
Date: |
Fri, 23 Aug 2013 15:36:59 +0200 |
> Which textbooks would that be?
I think for example at Scott Meyers books (Effective C++, More
effective C++...).
I also read this in the 4th edition (includes C++11) of the C++
programming language (Stroustrup):
"How do we choose among the ways of passing arguments? My rules of thumb are:
[1] Use pass-by-value for small objects.
[2] Use pass-by-const-reference to pass large values that you don’t
need to modify."
is a string a large object???
>> The standard <string> library can implement copy on write but it is
>> not mandatory and we should not rely on that behaviour.
>
> In C++11, rvalue string copies with move semantics are O(1).
How are you sure you always get rvalues? Also the move semantics
cannot be as quick as passing a reference.
and I thought the move to C++11 is not forseen in a near future.
>> Also the compiler may do some optimizations and remove some copies
>> him-self but should we rely on a particular compiler to do our job
>> when it is so "easy" to write efficient code?
>
> You should have rather written "efficient" in quote marks as long as
> there is no evidence that the current code is less efficient under some
> known compilers.
I did not say that but you have the guarantee that with 'const string
&' the code is at worst as efficient as today's code.
> const string & as return type is madness. For one thing, it's
> guaranteed _not_ to be an efficiency gain in C++11. For another, it
> produces _serious_ destructor/lifetime issues.
Of course I am not speaking of new strings created in the function!
That would be stupid. But if you return a member of an object for
example, it is stupid to return a copy of it (I do not know if this
happens, however).
Frédéric
- Re: What tests are run by patchy?, (continued)
- Re: What tests are run by patchy?, David Kastrup, 2013/08/23
- Re: What tests are run by patchy?, Frédéric Bron, 2013/08/23
- Re: What tests are run by patchy?, David Kastrup, 2013/08/23
- Re: What tests are run by patchy?,
Frédéric Bron <=
- Re: What tests are run by patchy?, David Kastrup, 2013/08/23
- Premature Optimization, Dan Eble, 2013/08/24
- Re: Premature Optimization, Frédéric Bron, 2013/08/24