fork download
  1. #include <iostream>
  2. #include <queue>
  3. #include <tuple>
  4. #include <boost/ptr_container/ptr_vector.hpp>
  5.  
  6. struct point
  7. {
  8. int x;
  9. int y;
  10. };
  11.  
  12. bool operator<(const point& lhs, const point& rhs)
  13. {
  14. return std::tie(lhs.x, lhs.y) < std::tie(rhs.x, rhs.y);
  15. }
  16.  
  17. std::ostream& operator<<(std::ostream& out, const point& p)
  18. {
  19. return out << p.x << ' ' << p.y;
  20. }
  21.  
  22. namespace detail
  23. {
  24. template<typename>
  25. struct ptr_less;
  26.  
  27. template<typename T>
  28. struct ptr_less<T*>
  29. {
  30. bool operator()(const T& lhs, const T& rhs)
  31. {
  32. return lhs < rhs;
  33. }
  34. };
  35. }
  36.  
  37. template<typename T>
  38. using ptr_priority_queue = std::priority_queue<T*, boost::ptr_vector<T>, detail::ptr_less<T*>>;
  39.  
  40. int main()
  41. {
  42. // std::priority_queue<point*, boost::ptr_vector<point>, detail::ptr_less<point*>> points;
  43. ptr_priority_queue<point> points;
  44.  
  45. points.push(new point{4, 1});
  46. points.push(new point{3, 2});
  47. points.push(new point{1, 6});
  48. points.push(new point{3, 4});
  49.  
  50. while (!points.empty())
  51. {
  52. std::cout << points.top() << std::endl;
  53. points.pop();
  54. }
  55.  
  56. return 0;
  57. }
  58.  
  59. // Sample output:
  60. // 4 1
  61. // 3 4
  62. // 3 2
  63. // 1 6
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:46: fatal error: boost/ptr_container/ptr_vector.hpp: No such file or directory
compilation terminated.
stdout
Standard output is empty