« first day (928 days earlier)      last day (2149 days later) » 

08:29
Hello
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.
Thanks!
 
6 hours later…
14:04
@LXSoft I'm sorry you have to use such an old version. This will hamper us being able to respond as many of us don't have access to that version.
 
1 hour later…
15:19
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?
@AfonsoMatos not in c++17
move would be used when you want to grab the innards
so it would be more something like setAnimal(std::move(cat));
where you don't use cat again in that context
what will used in c++17 in case of the Animal obj = getAnimal()
and what used to be used prior to c++17?
I think I'm using c++11
I saw only examples of using std::move but no examples with "plain syntax"
nwp
nwp
Compilers have always optimized out the unnecessary copy in Animal obj = getAnimal();.
that falls under return value optimization I believe
or copy elision
nwp
nwp
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.
15:34
So you only use move assignment when you explicitly use std::move?
The return value optimization, from what I understand, has to do with move constructor
nwp
nwp
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.
move assignment is also used when obj = getAnimal();where obj is an existing animal and getAnimal returns by value
nwp
nwp
For an example where you do need it is something like std::map<int, std::string> m; return std::move(m[42]);.
@nwp wouldn't that result in m[42] becoming the empty string?
nwp
nwp
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.
@ratchetfreak It would.
15:39
I'm trying to wrap my mind around move constructor/assignment.
nwp
nwp
Hence it's an observable effect, so the compiler needs the ok from the programmer.
So move assignment is used with std::move and with obj = getAnimal() ?
nwp
nwp
You can think of it as handling temporaries.
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.
I get it.
So what would be the difference between a move constructor and assignment practically speaking?
nwp
nwp
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.
15:47
assignment overwrites an existing object, construct creates a new object
nwp
nwp
A copy constructor makes a copy. Usually if the class has a pointer to data it has to dynamically allocate memory and copy the data.
A move constructor also makes a copy, but instead of allocating memory and then copying the data it simply steals the pointer from the source object.
Do you have real world examples of using both?
copy duplicates state potentially allocating, move allows it to steal allocated resources and leave the original in a "valid but unspecified state"
nwp
nwp
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
16:22
c++ is hard
but i like it
some people call that stockholm syndrome
that's freaky
when using normal arrays like T data[m][n]
is using the C-style cast the recommended way to loop through it in a linear fashion?
T * index = (T *) data
*index++
nwp
nwp
You don't need that cast.
Also C arrays are horrible.
I think if you go past the inner array it's UB. Not sure.
16:41
@AfonsoMatos Please don't use C style casts, it's a great way to shoot yourself in the foot
16:53
my code does not compile without that cast
	int data[5][4];
	int * index = data;
this won't work
	int data[5][4];
	int * index = (int *) data;
this does
is this bad practice?
17:10
C-arrays are bad practice, as are c-style casts
17:42
how do I know when to use move constructors, assignments etc.?
for example I was using C-style arrays and therefore had to do all of that
now I'm using std::array, which supposedly has everything built-in right?
 
1 hour later…
18:59
@AfonsoMatos depends on what you're doing, if you're passing around arrays you're probably doing it wrong

« first day (928 days earlier)      last day (2149 days later) »