Skip to content

Commit

Permalink
feat: make Watched work with interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
DNKpp committed Oct 7, 2024
1 parent 4352977 commit d2674d6
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions include/mimic++/LifetimeWatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,48 @@ namespace mimicpp
&& std::is_move_assignable_v<T>
&& std::is_destructible_v<T>;

template <typename Base, object_watcher... Watchers>
requires std::same_as<Base, std::remove_cvref_t<Base>>
&& (... && std::same_as<Watchers, std::remove_cvref_t<Watchers>>)
class Watched
: public Base,
public Watchers...
namespace detail
{
public:
~Watched() noexcept(std::is_nothrow_destructible_v<Base>)
template <typename Base, typename... Watchers>
class BasicWatched
: public Base,
public Watchers...
{
}
public:
~BasicWatched() = default;

using Base::Base;

BasicWatched(const BasicWatched&) = default;
BasicWatched& operator =(const BasicWatched&) = default;
BasicWatched(BasicWatched&&) = default;
BasicWatched& operator =(BasicWatched&&) = default;
};

template <satisfies<std::has_virtual_destructor> Base, typename... Watchers>
class BasicWatched<Base, Watchers...>
: public Base,
public Watchers...
{
public:
~BasicWatched() noexcept(std::is_nothrow_destructible_v<Base>) override
{
}

using Base::Base;
using Base::Base;

BasicWatched(const BasicWatched&) = default;
BasicWatched& operator =(const BasicWatched&) = default;
BasicWatched(BasicWatched&&) = default;
BasicWatched& operator =(BasicWatched&&) = default;
};
}

Watched(const Watched&) = default;
Watched& operator =(const Watched&) = default;
Watched(Watched&&) = default;
Watched& operator =(Watched&&) = default;
template <typename Base, object_watcher... Watchers>
requires std::same_as<Base, std::remove_cvref_t<Base>>
class Watched
: public detail::BasicWatched<Base, Watchers...>
{
};
}

Expand Down

0 comments on commit d2674d6

Please sign in to comment.