3 #ifndef CDSUNIT_STD_SET_H
4 #define CDSUNIT_STD_SET_H
7 #include <mutex> //unique_lock
10 template <typename Value, typename Less, typename Lock,
11 class Alloc = typename CDS_DEFAULT_ALLOCATOR::template rebind<Value>::other
13 class StdSet: public std::set<Value, Less, Alloc>
16 typedef std::unique_lock<Lock> scoped_lock;
17 typedef std::set<Value, Less, Alloc> base_class;
19 typedef typename base_class::key_type value_type;
21 StdSet( size_t /*nMapSize*/, size_t /*nLoadFactor*/ )
24 template <typename Key>
25 bool find( const Key& key )
28 scoped_lock al( m_lock );
29 return base_class::find( v ) != base_class::end();
32 bool insert( value_type const& v )
34 scoped_lock al( m_lock );
35 return base_class::insert( v ).second;
38 template <typename Key, typename Func>
39 bool insert( Key const& key, Func func )
41 scoped_lock al( m_lock );
42 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
50 template <typename T, typename Func>
51 std::pair<bool, bool> ensure( const T& key, Func func )
53 scoped_lock al( m_lock );
54 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
56 func( true, *pRet.first, key );
57 return std::make_pair( true, true );
60 func( false, *pRet.first, key );
61 return std::make_pair( true, false );
65 template <typename Key>
66 bool erase( const Key& key )
68 scoped_lock al( m_lock );
69 return base_class::erase( value_type(key) ) != 0;
72 template <typename T, typename Func>
73 bool erase( const T& key, Func func )
75 scoped_lock al( m_lock );
76 typename base_class::iterator it = base_class::find( value_type(key) );
77 if ( it != base_class::end() ) {
80 base_class::erase( it );
86 std::ostream& dump( std::ostream& stm ) { return stm; }
90 #endif // #ifndef CDSUNIT_STD_MAP_H