diff --git a/data_structures/upper_bound.hpp b/data_structures/upper_bound.hpp index d39901e8f..1fc77de38 100644 --- a/data_structures/upper_bound.hpp +++ b/data_structures/upper_bound.hpp @@ -31,20 +31,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include // max pq holds k elements // insert if key is smaller than max // if size > k then remove element // get() always yields a bound to the k smallest element in the stream -template -class upper_bound +template class upper_bound { + private: + using parameter_type = + typename std::conditional::value, key_type, key_type &>::type; + public: upper_bound() = delete; - upper_bound(std::size_t size) : size(size) - { - } + upper_bound(std::size_t size) : size(size) {} key_type get() const { @@ -55,12 +57,12 @@ class upper_bound return queue.top(); } - void insert(const key_type key) + void insert(const parameter_type key) { if (key < get()) { queue.emplace(key); - while (queue.size() > size) + while (queue.size() > size) { queue.pop(); }