nondestroying_holder.h 816 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #pragma once
  2. #include <util/generic/ptr.h>
  3. template <typename T>
  4. class TNonDestroyingHolder: public THolder<T> {
  5. public:
  6. TNonDestroyingHolder(T* t = nullptr) noexcept
  7. : THolder<T>(t)
  8. {
  9. }
  10. TNonDestroyingHolder(TAutoPtr<T> t) noexcept
  11. : THolder<T>(t)
  12. {
  13. }
  14. ~TNonDestroyingHolder() {
  15. Y_ABORT_UNLESS(!*this, "stored object must be explicitly released");
  16. }
  17. };
  18. template <class T>
  19. class TNonDestroyingAutoPtr: public TAutoPtr<T> {
  20. public:
  21. inline TNonDestroyingAutoPtr(T* t = 0) noexcept
  22. : TAutoPtr<T>(t)
  23. {
  24. }
  25. inline TNonDestroyingAutoPtr(const TAutoPtr<T>& t) noexcept
  26. : TAutoPtr<T>(t.Release())
  27. {
  28. }
  29. inline ~TNonDestroyingAutoPtr() {
  30. Y_ABORT_UNLESS(!*this, "stored object must be explicitly released");
  31. }
  32. };