WPILibC++  2019.1.1-beta-2-49-g7d7af28
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
PriorityQueue.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef WPIUTIL_WPI_PRIORITYQUEUE_H_
9 #define WPIUTIL_WPI_PRIORITYQUEUE_H_
10 
11 #include <algorithm>
12 #include <functional>
13 #include <queue>
14 #include <vector>
15 
16 namespace wpi {
17 
22 template <class T, class Container = std::vector<T>,
23  class Compare = std::less<typename Container::value_type>>
24 class PriorityQueue : public std::priority_queue<T, Container, Compare> {
25  public:
26  bool remove(const T& value) {
27  auto it = std::find(this->c.begin(), this->c.end(), value);
28  if (it != this->c.end()) {
29  this->c.erase(it);
30  std::make_heap(this->c.begin(), this->c.end(), this->comp);
31  return true;
32  } else {
33  return false;
34  }
35  }
36 };
37 
38 } // namespace wpi
39 
40 #endif // WPIUTIL_WPI_PRIORITYQUEUE_H_
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
This class adds a method for removing all elements from the priority queue matching the given value...
Definition: PriorityQueue.h:24