3 #ifndef __CDSUNIT_STD_SET_VC_H
4 #define __CDSUNIT_STD_SET_VC_H
7 #include <functional> // ref
8 #include <mutex> //unique_lock
11 template <typename Value, typename Less, typename Lock,
12 class Alloc = typename CDS_DEFAULT_ALLOCATOR::template rebind<Value>::other
14 class StdSet: public std::set<Value, Less, Alloc>
17 typedef std::unique_lock<Lock> AutoLock;
18 typedef std::set<Value, Less, Alloc> base_class;
20 typedef typename base_class::key_type value_type;
22 StdSet( size_t nMapSize, size_t nLoadFactor )
25 template <typename Key>
26 bool find( const Key& key )
29 AutoLock al( m_lock );
30 return base_class::find( v ) != base_class::end();
33 bool insert( value_type const& v )
35 AutoLock al( m_lock );
36 return base_class::insert( v ).second;
39 template <typename Key, typename Func>
40 bool insert( Key const& key, Func func )
42 AutoLock al( m_lock );
43 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
51 template <typename T, typename Func>
52 std::pair<bool, bool> ensure( const T& key, Func func )
54 AutoLock al( m_lock );
55 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
57 func( true, *pRet.first, key );
58 return std::make_pair( true, true );
61 func( false, *pRet.first, key );
62 return std::make_pair( true, false );
66 template <typename Key>
67 bool erase( const Key& key )
69 AutoLock al( m_lock );
70 return base_class::erase( value_type(key) ) != 0;
73 template <typename T, typename Func>
74 bool erase( const T& key, Func func )
76 AutoLock al( m_lock );
77 typename base_class::iterator it = base_class::find( value_type(key) );
78 if ( it != base_class::end() ) {
81 base_class::erase( it );
87 std::ostream& dump( std::ostream& stm ) { return stm; }
91 #endif // #ifndef __CDSUNIT_STD_MAP_VC_H