queue.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include "fwd.h"
  3. #include "deque.h"
  4. #include "vector.h"
  5. #include "utility.h"
  6. #include <util/str_stl.h>
  7. #include <queue>
  8. template <class T, class S>
  9. class TQueue: public std::queue<T, S> {
  10. using TBase = std::queue<T, S>;
  11. public:
  12. using TBase::TBase;
  13. inline explicit operator bool() const noexcept {
  14. return !this->empty();
  15. }
  16. inline void clear() {
  17. this->c.clear();
  18. }
  19. inline S& Container() Y_LIFETIME_BOUND {
  20. return this->c;
  21. }
  22. inline const S& Container() const Y_LIFETIME_BOUND {
  23. return this->c;
  24. }
  25. };
  26. template <class T, class S, class C>
  27. class TPriorityQueue: public std::priority_queue<T, S, C> {
  28. using TBase = std::priority_queue<T, S, C>;
  29. public:
  30. using TBase::TBase;
  31. inline explicit operator bool() const noexcept {
  32. return !this->empty();
  33. }
  34. inline void clear() {
  35. this->c.clear();
  36. }
  37. inline T PopValue() {
  38. Y_ASSERT(!this->empty());
  39. auto& container = this->c;
  40. std::pop_heap(container.begin(), container.end(), this->comp);
  41. T value = std::move(container.back());
  42. container.pop_back();
  43. return value;
  44. }
  45. inline S& Container() Y_LIFETIME_BOUND {
  46. return this->c;
  47. }
  48. inline const S& Container() const Y_LIFETIME_BOUND {
  49. return this->c;
  50. }
  51. };