Vick
BAN USER// How about a sprinkle of C++11 just for fun
74 typedef chrono::monotonic_clock::time_point timepoint_t;
75 typedef chrono::monotonic_clock::duration duration_t;
76 typedef list<timepoint_t> times_t;
77
78 const timepoint_t delta(chrono::seconds(5)); // 'x'
79 const size_t limit = 10; // 't'
80
81 bool decorator(void)
82 {
83 static size_t count;
84 static times_t times;
85
86 timepoint_t now = chrono::monotonic_clock::now();
87 timepoint_t tail(now - delta);
88
89 // Update globals with this hit
90 times.push_back(now);
91 count++;
92
93 // Trim expired hits
94 for (times_t::iterator i = times.begin(); i != times.end(); )
95 {
96 if (*i > tail) break;
97
98 count--;
99 i = times.erase(i);
100 }
101
102 return (count == limit);
103 }
- Vick May 04, 2012