mimic++ v4
|
A watcher type, which reports it's destructor calls. More...
#include <ObjectWatcher.hpp>
Public Member Functions | |
~LifetimeWatcher () noexcept(false) | |
Destructor, which reports the call. | |
LifetimeWatcher ()=default | |
Defaulted default constructor. | |
LifetimeWatcher (const LifetimeWatcher &other) | |
Copy-constructor. | |
LifetimeWatcher & | operator= (const LifetimeWatcher &other) |
Copy-assignment-operator. | |
LifetimeWatcher (LifetimeWatcher &&)=default | |
Defaulted move-constructor. | |
LifetimeWatcher & | operator= (LifetimeWatcher &&)=default |
Defaulted move-assignment-operator. | |
auto | expect_destruct () |
Begins a destruction-expectation construction. | |
A watcher type, which reports it's destructor calls.
This watcher is designed to track, whether the destructor has been called. During its destructor call, it reports the destruction to the framework, which can be tracked by a previously created destruction-expectation.
This watcher can be freely moved around.
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.
B
is not a copy of A
, then A == B
has to yield false!This won't be the case for LifetimeWatcher
s, as active destruction-expectations won't be copied over to the target. In general, if a LifetimeWatcher is used, we want to be very precise with our object-lifetime, thus an implicit expectation copy would be against the purpose of this helper. Due to this, each LifetimeWatcher
will be created as a fresh instance, when copy-construction is used. The same logic also applies to copy-assignment.
|
inline |
Destructor, which reports the call.
|
nodiscarddefault |
Defaulted default constructor.
|
inlinenodiscard |
Copy-constructor.
other | The other object. |
This copy-constructor's purpose is to provide syntactically correct copy operations, but semantically this does not copy anything. In fact, it simply default-constructs the new instance, without even touching the other
.
|
nodiscarddefault |
Defaulted move-constructor.
This move-constructor simply transfers everything from the source to the destination object. As source is then a "moved-from"-object, it doesn't require any destruction-expectations.
|
inlinenodiscard |
Begins a destruction-expectation construction.
ScopedExpectation
instance. This can either be done manually or via MIMICPP_SCOPED_EXPECTATION (or the shorthand version SCOPED_EXP). std::logic_error | if a destruction-expectation has already been created for this instance. |
|
inline |
Copy-assignment-operator.
other | The other object. |
This copy-assignment-operator's purpose is to provide syntactically correct copy operations, but semantically this does not copy anything. In fact, it simply deletes the previous content of this instance, default-constructs a new instance and move-assigns it to this instance, without even touching the other
.
LifetimeWatcher
, violations will be reported, if the previous instance didn't have a valid destruction-expectation.
|
default |
Defaulted move-assignment-operator.
This move-assignment-operator simply transfers everything from the source to the destination object. As source is then a "moved-from"-object, it doesn't require any destruction-expectations.