volatile_set.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <unordered_set>
4 #include <deque>
5 #include <functional>
6 
7 namespace iv
8 {
9 
15 template< class Key, class Hash = std::hash<Key>, class Pred = std::equal_to<Key> >
17 {
18 public:
19  using iterator = typename std::unordered_set< Key, Hash, Pred >::iterator;
20 
21  void insert( Key const & val );
22  void erase( Key const & val );
23 
24  int count( Key const & val );
25 
26  void foreach( std::function< void( Key const & ) > const & fun );
27 
29  iterator & lock_begin();
30  iterator & lock_find( Key const & val );
31  void unlock();
32  iterator end();
33 
34  size_t size();
35  bool empty();
36 
37 private:
38  std::unordered_set< Key, Hash, Pred > items;
39  std::unordered_set< Key, Hash, Pred > toinsert;
40  std::deque< typename decltype( items )::iterator > iterators;
41 };
42 
43 }
44 
45 #include "volatile_set.inl"