[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;
> a=2;
>
> 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:
class TextFile
{
public:
TextFile( std::string path )
{
m_file.open( path );
// add checks here
}
~TextFile()
{
m_file.close();
}
TextFile& operator=( const TextFile& other )
{
// clear our file's content
m_file.clear();
// copy the content of other's file
m_file.write( other.m_file );
}
private:
FileHandler 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.
Joel Lamotte
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120926/705f0932/attachment.html>
More information about the cfe-dev
mailing list