A watcher type, which reports it's move-constructor and -assignment calls.
This watcher is designed to track, whether a move has been performed. During a move, it reports the relocation to the framework, which can be tracked by a previously created relocation-expectation.
watched{};
int relocationCounter{};
and then::invoke([&] { ++relocationCounter; })
and expect::at_least(1);
std::optional wrapped{std::move(watched)};
std::optional other{std::move(wrapped)};
wrapped.reset();
other.reset();
REQUIRE(2 == relocationCounter);
Moving
This watcher can be freely moved around, but any relocation events must match with a previously created relocation-expectation.
Copying
This watcher is copyable, but with very special behaviour.
As this watcher is generally designed to be part of a bigger object, it would be very limiting not supporting copy-operations at all. The question is, how should a copy look like?
In general a copy should be a logical duplicate of its source and the general expectation is: if B
is a copy of A
, then A == B
should yield true.
- Note
- This doesn't say, that if
B
is not a copy of A
, then A == B
has to yield false!
This won't be the case for RelocationWatcher
s, as active relocation-expectations won't be copied over to the target. In general, if a RelocationWatcher
is used, we want to be very precise with our move, thus an implicit expectation copy would be against the purpose of this helper. Due to this, each RelocationWatcher
will be created as a fresh instance, when copy-construction is used. The same logic also applies to copy-assignment.