Skip to content
Welcome to the new CppUtils documentation!

Diagnostic utility for tracking and validating object lifecycles in unit tests.

Monitors construction, copy, move, and destruction events via a callback logger, while tracking copy, move, and shared active instance counts.

LifetimeChecker::LifetimeChecker(std::function<void(std::string_view)> callback, std::string name, std::size_t indentationLevel = 0);

Constructs a LifetimeChecker and logs object creation.

ParameterDescription
callbackLogging callback receiving string views of lifecycle events.
nameDiagnostic identifier of the monitored object.
indentationLevelTab indentation level for hierarchical visual logging.
[[nodiscard]] auto LifetimeChecker::getCopyCount() const -> std::size_t;

Returns the total number of copy constructions and copy assignments performed.

Returns: Cumulative copy operation count.

[[nodiscard]] auto LifetimeChecker::getMoveCount() const -> std::size_t;

Returns the total number of move constructions and move assignments performed.

Returns: Cumulative move operation count.

[[nodiscard]] auto LifetimeChecker::getInstanceCount() const noexcept -> std::size_t;

Returns the current number of active instances sharing this tracked object.

Returns: Active instance count (0 if moved-from).

virtual LifetimeChecker::~LifetimeChecker();

Destroys the LifetimeChecker and logs the destruction event.

LifetimeChecker::LifetimeChecker(const LifetimeChecker& other);
LifetimeChecker::LifetimeChecker(LifetimeChecker&& other) noexcept;
auto LifetimeChecker::operator=(const LifetimeChecker& rhs) -> LifetimeChecker&;
auto LifetimeChecker::operator=(LifetimeChecker&& rhs) noexcept -> LifetimeChecker&;