libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
priorityqueue.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <cstddef>
14#include <queue>
15#include <vector>
16#include <functional>
17#include <stdexcept>
18#include <promeki/namespace.h>
19
20PROMEKI_NAMESPACE_BEGIN
21
40template <typename T, typename Compare = std::less<T>> class PriorityQueue {
41 public:
43 PriorityQueue() = default;
44
46 PriorityQueue(const PriorityQueue &other) : d(other.d) {}
47
49 PriorityQueue(PriorityQueue &&other) noexcept : d(std::move(other.d)) {}
50
52 ~PriorityQueue() = default;
53
55 PriorityQueue &operator=(const PriorityQueue &other) {
56 d = other.d;
57 return *this;
58 }
59
61 PriorityQueue &operator=(PriorityQueue &&other) noexcept {
62 d = std::move(other.d);
63 return *this;
64 }
65
66 // -- Capacity --
67
69 bool isEmpty() const { return d.empty(); }
70
72 size_t size() const { return d.size(); }
73
74 // -- Access --
75
77 const T &top() const { return d.top(); }
78
79 // -- Modifiers --
80
85 void push(const T &value) {
86 d.push(value);
87 return;
88 }
89
94 void push(T &&value) {
95 d.push(std::move(value));
96 return;
97 }
98
104 T pop() {
105 if (d.empty()) throw std::logic_error("PriorityQueue::pop on empty queue");
106 T val = d.top();
107 d.pop();
108 return val;
109 }
110
115 void swap(PriorityQueue &other) noexcept {
116 d.swap(other.d);
117 return;
118 }
119
120 private:
121 std::priority_queue<T, std::vector<T>, Compare> d;
122};
123
124PROMEKI_NAMESPACE_END
125
126#endif // PROMEKI_ENABLE_CORE