6#ifndef MIMICPP_OBJECT_WATCHER_HPP
7#define MIMICPP_OBJECT_WATCHER_HPP
66 if (
const auto destruction = std::exchange(
152 if (std::exchange(m_HasDestructExpectation,
true))
154 throw std::logic_error{
155 "LifetimeWatcher: A destruct expectation can not be created more than once for a single instance."};
158 return m_DestructionMock->expect_call()
163 bool m_HasDestructExpectation{};
164 std::unique_ptr<Mock<void()>> m_DestructionMock{
165 std::make_unique<Mock<void()>>()};
236 m_RelocationMock =
Mock<void()>{};
249 *
this = std::move(other);
259 other.m_RelocationMock();
260 m_RelocationMock = std::move(other).m_RelocationMock;
275 return m_RelocationMock.expect_call();
279 Mock<void()> m_RelocationMock{};
282 template <
typename T>
284 && std::is_copy_constructible_v<T>
285 && std::is_copy_assignable_v<T>
286 && std::is_move_constructible_v<T>
287 && std::is_move_assignable_v<T>
288 && std::is_destructible_v<T>;
292 template <
typename Base,
typename... Watchers>
293 class CombinedWatchers
297 ~CombinedWatchers()
noexcept(std::is_nothrow_destructible_v<Base>) =
default;
299 CombinedWatchers() =
default;
301 CombinedWatchers(
const CombinedWatchers&) =
default;
302 CombinedWatchers& operator=(
const CombinedWatchers&) =
default;
304 CombinedWatchers(CombinedWatchers&& other)
noexcept(std::is_nothrow_move_constructible_v<Base>) =
default;
305 CombinedWatchers& operator=(CombinedWatchers&& other)
noexcept(std::is_nothrow_move_assignable_v<Base>) =
default;
308 template <
typename Base,
typename... Watchers>
310 :
public CombinedWatchers<Base, Watchers...>,
314 ~BasicWatched() =
default;
318 BasicWatched(
const BasicWatched&) =
default;
319 BasicWatched& operator=(
const BasicWatched&) =
default;
320 BasicWatched(BasicWatched&&) =
default;
321 BasicWatched& operator=(BasicWatched&&) =
default;
324 template <satisfies<std::has_virtual_destructor> Base,
typename... Watchers>
325 class BasicWatched<Base, Watchers...>
326 :
public CombinedWatchers<Base, Watchers...>,
330 ~BasicWatched()
override =
default;
334 BasicWatched(
const BasicWatched&) =
default;
335 BasicWatched& operator=(
const BasicWatched&) =
default;
336 BasicWatched(BasicWatched&&) =
default;
337 BasicWatched& operator=(BasicWatched&&) =
default;
395 requires std::same_as<Base, std::remove_cvref_t<Base>>
397 :
public detail::BasicWatched<Base, Watchers...>
399 using SuperT = detail::BasicWatched<Base, Watchers...>;
404 using SuperT::SuperT;
A watcher type, which reports it's destructor calls.
Definition ObjectWatcher.hpp:57
LifetimeWatcher()=default
Defaulted default constructor.
~LifetimeWatcher() noexcept(false)
Destructor, which reports the call.
Definition ObjectWatcher.hpp:64
LifetimeWatcher & operator=(LifetimeWatcher &&)=default
Defaulted move-assignment-operator.
LifetimeWatcher(const LifetimeWatcher &other)
Copy-constructor.
Definition ObjectWatcher.hpp:91
LifetimeWatcher & operator=(const LifetimeWatcher &other)
Copy-assignment-operator.
Definition ObjectWatcher.hpp:111
LifetimeWatcher(LifetimeWatcher &&)=default
Defaulted move-constructor.
auto expect_destruct()
Begins a destruction-expectation construction.
Definition ObjectWatcher.hpp:150
A Mock type, which fully supports overload sets.
Definition Mock.hpp:390
A watcher type, which reports it's move-constructor and -assignment calls.
Definition ObjectWatcher.hpp:199
auto expect_relocate()
Begins a relocation-expectation construction.
Definition ObjectWatcher.hpp:273
RelocationWatcher(RelocationWatcher &&other) noexcept(false)
Move-constructor, which reports a relocation.
Definition ObjectWatcher.hpp:247
~RelocationWatcher()=default
Defaulted destructor.
RelocationWatcher(const RelocationWatcher &other)
Copy-constructor.
Definition ObjectWatcher.hpp:220
RelocationWatcher()=default
Defaulted default constructor.
RelocationWatcher & operator=(const RelocationWatcher &other)
Copy-assignment-operator.
Definition ObjectWatcher.hpp:232
RelocationWatcher & operator=(RelocationWatcher &&other) noexcept(false)
Move-assignment-operator, which reports a relocation.
Definition ObjectWatcher.hpp:257
CRTP-type, inheriting first from all Watchers and then Base, thus effectively couple them all togethe...
Definition ObjectWatcher.hpp:398
Watched(const Watched &)=default
Watched & operator=(const Watched &)=default
Watched(Watched &&)=default
Watched & operator=(Watched &&)=default
Definition ObjectWatcher.hpp:283
consteval auto once() noexcept
Specifies a times policy with both limits set to 1.
Definition ControlPolicy.hpp:340
Definition BoostTest.hpp:20