diff --git a/object.hpp b/object.hpp index 9a6248a..d86d462 100644 --- a/object.hpp +++ b/object.hpp @@ -158,15 +158,45 @@ namespace cruft::vk { }; - private: - template - static - id_t make (OwnerT &owner, Args &&...args) - { - id_t id; - life_traits::get (owner.id (), std::forward (args)..., &id); - return id; - } + template + auto + make_owned (OwnerT &owner, Args &&...args) + { + class destroyer { + public: + destroyer (SelfT &&_self, OwnerT &_owner): + m_self (std::move (_self)), + m_owner (_owner) + { ; } + + destroyer (destroyer &&rhs): + m_self (std::move (rhs.m_self)), + m_owner (rhs.m_owner) + { ; } + + ~destroyer () + { + m_self.destroy (m_owner); + } + + // it's unclear whether we want to work around reseating m_owner, + // or if this operation just isn't sufficiently prevalent to + // justify the work. + destroyer& operator= (destroyer &&rhs) = delete; + + SelfT* + operator-> ()& + { return &m_self; } + + private: + SelfT m_self; + OwnerT &m_owner; + }; + + return destroyer { + SelfT { owner, std::forward (args)... }, + owner + }; }; };