Re: Question on move constructor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 28 January 2013 14:35, Graziano Servizi wrote:
>
> WHEN are they called?

This is not the right list for answering that, as it's not a question about GCC.

They're called when constructing from an rvalue.

> I got an example on Internet (attached) and the output they claim to be
> obtained (also attached) is NOT reproduced on my system (it is attached as
> well).
>
> I also tried some checks of my own and I was unable to call a move
> constructor that I wrote in my classes (I presume in a correct way, since
> the compiler didn't complain). It seems to me that, anytime the standard
> 2011 claims that a move constructor should be called, the "classical" copy
> constructor is called instead, unless one explicitly use a call to the
> std::move function. Is this correct or wrong?

I can't comment on your own tests, but in the sample_code.C program
you attached the std::vector operations do not move the elements
because your move constructor and move assignment operator can throw
exceptions.  The std::vector implementation in libstdc++ will only
move elements if doing so is guaranteed not to throw exceptions,
otherwise there could be data loss and the vector contents could be
left in an inconsistent state.

To ensure your class gets moved, make your move operations "noexcept"


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux