VectorOfPtr.tlh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include <vector>
  3. #include <memory>
  4. //#include <Iterator.tlh>
  5. //-----------------------------------------------------------------------------
  6. // VectorOfPtr
  7. //-----------------------------------------------------------------------------
  8. template <typename T>
  9. class VectorOfPtr : public std::vector <std::unique_ptr <T>>
  10. {
  11. typedef std::vector <std::unique_ptr <T>> inherited;
  12. public:
  13. // using inherited::inherited;
  14. VectorOfPtr ()
  15. {
  16. }
  17. VectorOfPtr (VectorOfPtr && from) : inherited (std::move (from))
  18. {
  19. }
  20. VectorOfPtr (const VectorOfPtr & from) = delete;
  21. ~VectorOfPtr ()
  22. {
  23. __noop;
  24. }
  25. public:
  26. inline void Attach (T * value)
  27. {
  28. std::unique_ptr <T> ptr (value);
  29. push_back (std::move (ptr));
  30. }
  31. inline int GetSize () const
  32. {
  33. return (int)size ();
  34. }
  35. inline bool IsEmpty () const
  36. {
  37. return inherited::empty ();
  38. }
  39. inline void Reset ()
  40. {
  41. clear ();
  42. }
  43. inline std::vector <T *> ToVector ()
  44. {
  45. std::vector <T *> to;
  46. for (const auto & Item : *this)
  47. {
  48. to.push_back (Item.get ());
  49. }
  50. return to;
  51. }
  52. // int IndexOf (const T * t) const;
  53. };