StripedMap: replace ensure() with update(), find(key) with contains(key)
[libcds.git] / cds / container / striped_map / boost_list.h
index 5f9a021926e7cc4d71445b93ada610472c66a94c..92526c2ea654c481f44ef9093fa73ec3c13ec4b1 100644 (file)
@@ -1,18 +1,18 @@
 //$$CDS-header$$
 
-#ifndef __CDS_CONTAINER_STRIPED_MAP_BOOST_LIST_ADAPTER_H
-#define __CDS_CONTAINER_STRIPED_MAP_BOOST_LIST_ADAPTER_H
+#ifndef CDSLIB_CONTAINER_STRIPED_MAP_BOOST_LIST_ADAPTER_H
+#define CDSLIB_CONTAINER_STRIPED_MAP_BOOST_LIST_ADAPTER_H
 
 #include <boost/version.hpp>
 #if BOOST_VERSION < 104800
 #   error "For boost::container::list you must use boost 1.48 or above"
 #endif
 
-#include <cds/container/striped_set/adapter.h>
-#include <cds/ref.h>
-#include <boost/container/list.hpp>
+#include <functional>   // ref
 #include <algorithm>    // std::lower_bound
 #include <utility>      // std::pair
+#include <cds/container/striped_set/adapter.h>
+#include <boost/container/list.hpp>
 
 //@cond
 namespace cds { namespace container {
@@ -67,8 +67,8 @@ namespace cds { namespace container {
 namespace cds { namespace intrusive { namespace striped_set {
 
     /// boost::container::list adapter for hash map bucket
-    template <typename Key, typename T, class Alloc, CDS_SPEC_OPTIONS>
-    class adapt< boost::container::list< std::pair<Key const, T>, Alloc>, CDS_OPTIONS >
+    template <typename Key, typename T, class Alloc, typename... Options>
+    class adapt< boost::container::list< std::pair<Key const, T>, Alloc>, Options... >
     {
     public:
         typedef boost::container::list< std::pair<Key const, T>, Alloc>     container_type          ;   ///< underlying container type
@@ -89,13 +89,13 @@ namespace cds { namespace intrusive { namespace striped_set {
 
         private:
             //@cond
-            typedef typename cds::opt::details::make_comparator_from_option_list< value_type, CDS_OPTIONS >::type key_comparator;
+            typedef typename cds::opt::details::make_comparator_from_option_list< value_type, Options... >::type key_comparator;
 
             typedef typename cds::opt::select<
                 typename cds::opt::value<
                     typename cds::opt::find_option<
                         cds::opt::copy_policy< cds::container::striped_set::move_item >
-                        , CDS_OPTIONS
+                        , Options...
                     >::type
                 >::copy_policy
                 , cds::container::striped_set::copy_item, cds::container::striped_set::copy_item_policy<container_type>
@@ -140,7 +140,7 @@ namespace cds { namespace intrusive { namespace striped_set {
                 if ( it == m_List.end() || key_comparator()( key, it->first ) != 0 ) {
                     //value_type newItem( key );
                     it = m_List.insert( it, value_type( key, mapped_type()) );
-                    cds::unref( f )( *it );
+                    f( *it );
 
                     return true;
                 }
@@ -161,20 +161,23 @@ namespace cds { namespace intrusive { namespace striped_set {
             }
 
             template <typename Q, typename Func>
-            std::pair<bool, bool> ensure( const Q& key, Func func )
+            std::pair<bool, bool> update( const Q& key, Func func, bool bAllowInsert )
             {
                 iterator it = std::lower_bound( m_List.begin(), m_List.end(), key, find_predicate() );
                 if ( it == m_List.end() || key_comparator()( key, it->first ) != 0 ) {
                     // insert new
+                    if ( !bAllowInsert )
+                        return std::make_pair( false, false );
+
                     value_type newItem( key, mapped_type() );
                     it = m_List.insert( it, newItem );
-                    cds::unref( func )( true, *it );
+                    func( true, *it );
 
                     return std::make_pair( true, true );
                 }
                 else {
                     // already exists
-                    cds::unref( func )( false, *it );
+                    func( false, *it );
                     return std::make_pair( true, false );
                 }
             }
@@ -187,7 +190,7 @@ namespace cds { namespace intrusive { namespace striped_set {
                     return false;
 
                 // key exists
-                cds::unref( f )( *it );
+                f( *it );
                 m_List.erase( it );
 
                 return true;
@@ -201,7 +204,7 @@ namespace cds { namespace intrusive { namespace striped_set {
                     return false;
 
                 // key exists
-                cds::unref( f )( *it );
+                f( *it );
                 m_List.erase( it );
 
                 return true;
@@ -215,7 +218,7 @@ namespace cds { namespace intrusive { namespace striped_set {
                     return false;
 
                 // key exists
-                cds::unref( f )( *it, val );
+                f( *it, val );
                 return true;
             }
 
@@ -227,7 +230,7 @@ namespace cds { namespace intrusive { namespace striped_set {
                     return false;
 
                 // key exists
-                cds::unref( f )( *it, val );
+                f( *it, val );
                 return true;
             }
 
@@ -264,4 +267,4 @@ namespace cds { namespace intrusive { namespace striped_set {
 }}} // namespace cds::intrusive::striped_set
 //@endcond
 
-#endif // #ifndef __CDS_CONTAINER_STRIPED_MAP_BOOST_LIST_ADAPTER_H
+#endif // #ifndef CDSLIB_CONTAINER_STRIPED_MAP_BOOST_LIST_ADAPTER_H