#pragma once #include #include //----------------------------------------------------------------------------- // ListOfPtr //----------------------------------------------------------------------------- template class ListOfPtr : public std::list > { using inherited = std::list >; public: ListOfPtr () { } ListOfPtr (ListOfPtr && from) : inherited (std::move (from)) { } ListOfPtr (const ListOfPtr & from) = delete; ~ListOfPtr () { __noop; } ListOfPtr & operator = (ListOfPtr && from) { inherited::operator = (std::move (from)); return (*this); } public: void Attach (T * value) { std::unique_ptr ptr (value); inherited::push_back (std::move (ptr)); } T * Detach (T * value) { auto iter = std::find_if (this->begin (), this->end (), [ value] (const auto & to) { return to.get () == value; }); std::unique_ptr rc; if (iter == this->cend ()) return nullptr; auto to = (*iter).release (); this->erase (iter); return to; } void AttachFirst (T * value) { std::unique_ptr ptr (value); push_front (std::move (ptr)); } T * GetFirst () const { return inherited::front ().get (); } void RemoveFirst () { inherited::pop_front (); } T * GetLast () const { return inherited::back ().get (); } void RemoveLast () { inherited::pop_back (); } bool IsEmpty () const { return inherited::empty (); } int GetSize () const { return (int) (inherited::size ()); } void Reset () { inherited::clear (); } };