[cfe-dev] Proposed C++ optimization with big speed gains with big objects
Klaim - Joël Lamotte
mjklaim at gmail.com
Wed Sep 26 06:07:57 PDT 2012
On Tue, Sep 25, 2012 at 6:26 PM, Ladislav Nevery <neuralll at gmail.com> wrote:
> int a=1;
> The moment I agreed to assign new value I agreed to old value being lost.
> This is normal and expected behavior.
For the value yes, but not for the destructor call.
If my understanding is correct, if I have this kind of code:
TextFile( std::string path )
m_file.open( path );
// add checks here
TextFile& operator=( const TextFile& other )
// clear our file's content
// copy the content of other's file
m_file.write( other.m_file );
Then the standard guarantee me that the destructor will be called only if
the instance goes out of scope, not on copy or move.
If I understand correctly what you propose, this code wouldn't do what I
assume it would. It would call the destructor and then change the semantic
of the type.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev