Docfix, minor changes
[libcds.git] / cds / container / striped_map / std_list.h
index 4e7bdc180aaaeaeebe6ceb9af4bdc991d9c9fc9f..cc19f06d0d8ef0402e8be4ff33499935bddef39f 100644 (file)
@@ -1,4 +1,32 @@
-//$$CDS-header$$
+/*
+    This file is a part of libcds - Concurrent Data Structures library
+
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+
+    Source code repo: http://github.com/khizmax/libcds/
+    Download: http://sourceforge.net/projects/libcds/files/
+    
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this
+      list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
+*/
 
 #ifndef CDSLIB_CONTAINER_STRIPED_MAP_STD_LIST_ADAPTER_H
 #define CDSLIB_CONTAINER_STRIPED_MAP_STD_LIST_ADAPTER_H
@@ -149,8 +177,7 @@ namespace cds { namespace intrusive { namespace striped_set {
             {
                 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 ) {
-                    //value_type newItem( key );
-                    it = m_List.insert( it, value_type( key, mapped_type()) );
+                    it = m_List.insert( it, value_type( key_type( key ), mapped_type()) );
                     f( *it );
 
 #           if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM)
@@ -166,10 +193,10 @@ namespace cds { namespace intrusive { namespace striped_set {
             template <typename K, typename... Args>
             bool emplace( K&& key, Args&&... args )
             {
-                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 ) {
-                    //value_type newItem( key );
-                    it = m_List.emplace( it, value_type( std::forward<K>(key), std::move( mapped_type( std::forward<Args>(args)...) )) );
+                value_type val( key_type( std::forward<K>( key )), mapped_type( std::forward<Args>( args )... ));
+                iterator it = std::lower_bound( m_List.begin(), m_List.end(), val.first, find_predicate() );
+                if ( it == m_List.end() || key_comparator()( val.first, it->first ) != 0 ) {
+                    it = m_List.emplace( it, std::move( val ));
 
 #           if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM)
                     ++m_nSize;
@@ -180,13 +207,15 @@ 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
-                    value_type newItem( key, mapped_type() );
-                    it = m_List.insert( it, newItem );
+                    if ( !bAllowInsert )
+                        return std::make_pair( false, false );
+
+                    it = m_List.insert( it, value_type( key_type( key ), mapped_type() ));
                     func( true, *it );
 #           if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM)
                     ++m_nSize;