3 #ifndef CDSUNIT_STD_MAP_GCC_H
4 #define CDSUNIT_STD_MAP_GCC_H
7 #include <mutex> //unique_lock
11 template <typename Key, typename Value, typename Lock,
12 class Alloc = typename CDS_DEFAULT_ALLOCATOR::template rebind<std::pair<Key const, Value> >::other
14 class StdMap: public std::map<Key, Value, std::less<Key>, Alloc>
17 typedef std::unique_lock<Lock> scoped_lock;
18 typedef std::map<Key, Value, std::less<Key>, Alloc> base_class;
20 typedef typename base_class::mapped_type value_type;
21 typedef typename base_class::value_type pair_type;
22 typedef size_t item_counter;
27 template <class Config>
28 StdMap( Config const& )
31 bool contains( const Key& key )
33 scoped_lock al( m_lock );
34 return base_class::find( key ) != base_class::end();
37 bool insert( const Key& key, const Value& val )
39 scoped_lock al( m_lock );
40 return base_class::insert( typename base_class::value_type(key, val)).second;
43 template <typename T, typename Func>
44 bool insert( const Key& key, const T& val, Func func )
46 scoped_lock al( m_lock );
47 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( typename base_class::value_type(key, Value() ));
49 func( pRet.first->second, val );
55 template <typename T, typename Func>
56 std::pair<bool, bool> update( const T& key, Func func, bool /*bAllowInsert*/ = true )
58 scoped_lock al( m_lock );
59 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( typename base_class::value_type(key, Value() ));
61 func( true, *pRet.first );
62 return std::make_pair( true, true );
65 func( false, *pRet.first );
66 return std::make_pair( true, false );
70 bool erase( const Key& key )
72 scoped_lock al( m_lock );
73 return base_class::erase( key ) != 0;
76 template <typename T, typename Func>
77 bool erase( const T& key, Func func )
79 scoped_lock al( m_lock );
80 typename base_class::iterator it = base_class::find( key );
81 if ( it != base_class::end() ) {
83 base_class::erase( it );
89 std::ostream& dump( std::ostream& stm ) { return stm; }
93 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
94 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
95 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
99 #endif // #ifndef CDSUNIT_STD_MAP_GCC_H