I use in general a lot the watch window (Visual Studio 2010) in debug mode to inspect objects. For some reason from today the watch window does not anymore show object methods.
Does anyone know why this issue had happened today?
I am unable to find any reference to this bug or maybe I disabled/filtered by mistake the watch window to show only object attributes without methods.
If anyone encountered this issue, I would greatly appreciate any kind of inputs.
i searched the whole web for an example of practically using move assignment but found none. If I have Animal obj = getAnimal() will the move assignment be used?
There is a jason turner weekly c++ episode on it and the oldest compiler he could find, some ancient borland c++ compiler did the optimization already.
Return value optimization optimizes out the copy. It makes it so that the object that getAnimal will return is directly constructed in the space of Animal obj so that there is nothing to copy or move.
So no need for a move-constructor if you want return value optimization.
Without the std::move it makes a copy, because it is not allowed to change m. With the std::move it rips out the pointer to the data buffer of the map std::string to construct the returned one without any dynamic memory allocation.
The idea is that you can steal resources from temporaries and nobody cares, because it's a temporary that disappears anyways.
For getAnimal() the compiler can see that the Animal that is being returned will disappear soon anyways, so it can automatically steal resources from it.
In the map example the string in the map is not a temporary, it stays around and people can look at it, so you can't simply steal its resources.
But you can manually say "treat this as a temporary" using std::move.
@ratchetfreak Actually I don't think it has to. Small string optimization might prevent it from becoming empty.
Those are completely different. One constructs an object, the other assigns a value. What you probably mean is copy constructor vs move constructor or copy assignment vs move assignment.
Sure. std::vector v = other_vector; uses the copy constructor and std::vector v = std::move(other_vector); uses the move constructor.
You should avoid doing things like moving from other_vector and then looking at the content of other_vector. It happens to be well-defined for std::vector, but in general you should avoid that.
There is a video somewhere with Bjarne explaining it with a phone, a 5 year old and a hammer. It's kinda funny, but hard to find.
I believe the few things you can do on a moved-from object is destroying it, and assigning another object to it, and whatever the object itself guarantees