Tatooine
time_stamp_queue.h
Go to the documentation of this file.
1#ifndef TATOOINE_TIME_STAMP_QUEUE_H
2#define TATOOINE_TIME_STAMP_QUEUE_H
3//==============================================================================
4#include <chrono>
5#include <queue>
6//==============================================================================
7namespace tatooine {
8//==============================================================================
9template <typename T, typename Timer>
11 public:
12 auto operator()(std::pair<T, std::chrono::time_point<Timer>> const& lhs,
13 std::pair<T, std::chrono::time_point<Timer>> const& rhs) const
14 -> bool {
15 return lhs.second < rhs.second;
16 }
17};
18//==============================================================================
19template <typename T, typename Timer = std::chrono::high_resolution_clock>
21 : public std::priority_queue<
22 std::pair<T, std::chrono::time_point<Timer>>,
23 std::vector<std::pair<T, std::chrono::time_point<Timer>>>,
24 time_stamp_queue_components_type<T, Timer>> {
25 using parent_t = std::priority_queue<
26 std::pair<T, std::chrono::time_point<Timer>>,
27 std::vector<std::pair<T, std::chrono::time_point<Timer>>>,
29 //============================================================================
30 public:
32 template <typename... Args>
33 //----------------------------------------------------------------------------
34 auto emplace(Args&&... args) {
35 auto t = T{std::forward<Args>(args)...};
36 std::erase_if(this->c, [&](auto const& elem) { return elem.first == t; });
37 parent_t::emplace(std::pair{std::move(t), Timer::now()});
38 }
39 //----------------------------------------------------------------------------
40 auto push(T const& t) {
41 std::erase_if(this->c, [&](auto const& elem) { return elem.first == t; });
42 parent_t::emplace(std::pair{t, Timer::now()});
43 }
44 //----------------------------------------------------------------------------
45 auto push(T&& t) {
46 std::erase_if(this->c, [&](auto const& elem) { return elem.first == t; });
47 parent_t::emplace(std::pair{std::move(t), Timer::now()});
48 }
49};
50//==============================================================================
51} // namespace tatooine
52//==============================================================================
53#endif
auto emplace(const Key &key, Args &&... args)
Definition: cache.h:112
Definition: time_stamp_queue.h:10
auto operator()(std::pair< T, std::chrono::time_point< Timer > > const &lhs, std::pair< T, std::chrono::time_point< Timer > > const &rhs) const -> bool
Definition: time_stamp_queue.h:12
Definition: time_stamp_queue.h:24
std::priority_queue< std::pair< T, std::chrono::time_point< Timer > >, std::vector< std::pair< T, std::chrono::time_point< Timer > > >, time_stamp_queue_components_type< T, Timer > > parent_t
Definition: time_stamp_queue.h:28
auto emplace(Args &&... args)
Definition: time_stamp_queue.h:34
auto push(T const &t)
Definition: time_stamp_queue.h:40
auto push(T &&t)
Definition: time_stamp_queue.h:45
Definition: algorithm.h:6