sf: support service objects which must themselves be shared pointers

This commit is contained in:
Michael Scire 2020-07-08 15:07:40 -07:00
parent aa2d1e15ab
commit 2d9f5b6942
2 changed files with 42 additions and 1 deletions

View file

@ -50,11 +50,18 @@ namespace ams::sf {
{ T::ShouldMitm(c) } -> std::same_as<bool>;
};
template<typename Interface, typename Impl, typename... Arguments> requires std::constructible_from<Impl, Arguments...>
template<typename Interface, typename Impl, typename... Arguments>
requires std::constructible_from<Impl, Arguments...>
constexpr ALWAYS_INLINE std::shared_ptr<typename Interface::ImplHolder<Impl>> MakeShared(Arguments &&... args) {
return std::make_shared<typename Interface::ImplHolder<Impl>>(std::forward<Arguments>(args)...);
}
template<typename Interface, typename Impl, typename... Arguments>
requires (std::constructible_from<Impl, Arguments...> && std::derived_from<Impl, std::enable_shared_from_this<Impl>>)
constexpr ALWAYS_INLINE std::shared_ptr<typename Interface::ImplSharedPointer<Impl>> MakeShared(Arguments &&... args) {
return std::make_shared<typename Interface::ImplSharedPointer<Impl>>(std::make_shared<Impl>(std::forward<Arguments>(args)...));
}
template<typename Interface, typename Impl>
constexpr ALWAYS_INLINE std::shared_ptr<typename Interface::ImplPointer<Impl>> GetSharedPointerTo(Impl *impl) {
return std::make_shared<typename Interface::ImplPointer<Impl>>(impl);