I’m working on testing whether or not my container wrappers are implementing URefs correctly. The only obvious way that I can think of is to try to figure out a way of detecting if an object has been moved.
Is there a good way of testing to make sure that an object was not copied? Or is there another way to test for what I want? I would prefer a solution that doesn’t require modifying the classes I’m testing. Because there’s a couple dozen of them.
Could you please provide some more info on what you have? Like what is your container, how you use it, can you modify it or not, etc. Maybe you can test this without modification of your container, but rather by using special container element type – which tracks copies and moves.
Several different containers and some standalone templated functions. Mostly, it’s wrappers around STL library types like deque, list, map, set, etc.
You may try following check:
live demo
MSVC2008 outputs:
Note, that in this code I used explicit move from lvalues, so Copy-elision can’t work here.
P.S. another way to do this is to check generated assembler code. For instance /FA compiler option on MSVC or -S on GCC.
You can mark place of interest with special function call:
And place that marker in code:
Asm code may look like: