Remove old MSVC++ std::map and stdext::hash_map from map tests
[libcds.git] / tests / unit / set2 / std_hash_set_vc9.h
1 //$$CDS-header$$
2
3 #ifndef __CDSUNIT_STD_HASH_SET_VC_H
4 #define __CDSUNIT_STD_HASH_SET_VC_H
5
6 #include <hash_set>
7 #include <mutex>    //unique_lock
8
9 namespace set2 {
10
11     template <typename KeyVal, typename Hash, typename Less>
12     struct hash_less: public stdext::hash_compare< KeyVal, Less >
13     {
14         typedef stdext::hash_compare< KeyVal, Less> base_class;
15         size_t operator()(const KeyVal& kv) const
16         {
17             return Hash()(kv);
18         }
19
20         bool operator()(const KeyVal& kv1, const KeyVal& kv2) const
21         {
22             return base_class::operator()( kv1, kv2 );
23         }
24     };
25
26     template <typename Value, typename Hash, typename Less, typename EqualTo, typename Lock, class Alloc = CDS_DEFAULT_ALLOCATOR>
27     class StdHashSet: public stdext::hash_set<Value, hash_less<Value, Hash, Less >, Alloc>
28     {
29     public:
30         Lock m_lock;
31         typedef std::unique_lock<Lock> AutoLock;
32         typedef stdext::hash_set<Value, hash_less<Value, Hash, Less >, Alloc> base_class;
33
34     public:
35         typedef typename base_class::value_type  pair_type;
36
37         StdHashSet( size_t nSetSize, size_t nLoadFactor )
38         {}
39
40         template <typename Key>
41         bool find( const Key& key )
42         {
43             AutoLock al( m_lock );
44             return base_class::find( value_type(key) ) != base_class::end();
45         }
46
47         template <typename Key>
48         bool insert( Key const& key )
49         {
50             AutoLock al( m_lock );
51             std::pair<base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
52             return pRet.second;
53         }
54
55         template <typename Key, typename Func>
56         bool insert( Key const& key, Func func )
57         {
58             AutoLock al( m_lock );
59             std::pair<base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
60             if ( pRet.second ) {
61                 func( *pRet.first );
62                 return true;
63             }
64             return false;
65         }
66
67         template <typename T, typename Func>
68         std::pair<bool, bool> ensure( const T& key, Func func )
69         {
70             AutoLock al( m_lock );
71             std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
72             if ( pRet.second ) {
73                 func( true, *pRet.first, key );
74                 return std::make_pair( true, true );
75             }
76             else {
77                 func( false, *pRet.first, key );
78                 return std::make_pair( true, false );
79             }
80         }
81
82         template <typename Key>
83         bool erase( const Key& key )
84         {
85             AutoLock al( m_lock );
86             return base_class::erase( value_type(key) ) != 0;
87         }
88
89         template <typename T, typename Func>
90         bool erase( const T& key, Func func )
91         {
92             AutoLock al( m_lock );
93             base_class::iterator it = base_class::find( key );
94             if ( it != base_class::end() ) {
95                 func( *it );
96                 return base_class::erase( it ) != base_class::end();
97             }
98             return false;
99         }
100
101
102         std::ostream& dump( std::ostream& stm ) { return stm; }
103     };
104 }   // namespace set2
105
106 #endif  // #ifndef __CDSUNIT_STD_HASH_SET_VC_H