object: ensure make_owned destroys its object
This commit is contained in:
parent
665a61a98e
commit
05e53b9161
44
object.hpp
44
object.hpp
@ -158,15 +158,45 @@ namespace cruft::vk {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
private:
|
template <typename SelfT, typename OwnerT, typename ...Args>
|
||||||
template <typename ...Args>
|
auto
|
||||||
static
|
make_owned (OwnerT &owner, Args &&...args)
|
||||||
id_t make (OwnerT &owner, Args &&...args)
|
|
||||||
{
|
{
|
||||||
id_t id;
|
class destroyer {
|
||||||
life_traits<SelfT>::get (owner.id (), std::forward<Args> (args)..., &id);
|
public:
|
||||||
return id;
|
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> (args)... },
|
||||||
|
owner
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user