Unit tests for set are only with C++11 std::set and std::unordered_set
authorkhizmax <libcds.dev@gmail.com>
Sun, 2 Nov 2014 14:51:40 +0000 (17:51 +0300)
committerkhizmax <libcds.dev@gmail.com>
Sun, 2 Nov 2014 14:51:40 +0000 (17:51 +0300)
projects/Win/vc12/cds.sln
tests/unit/set2/std_hash_set.h [new file with mode: 0644]
tests/unit/set2/std_hash_set_std.h [deleted file]
tests/unit/set2/std_set.h

index 8789bdbb3fe9578330db68a05f7fa619534edc02..7bead7272847eb8299664a7ac56dd260f143ae7d 100644 (file)
@@ -79,8 +79,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "set", "set", "{A64449B7-90F
                ..\..\..\tests\unit\set2\set_defs.h = ..\..\..\tests\unit\set2\set_defs.h\r
                ..\..\..\tests\unit\set2\set_types.h = ..\..\..\tests\unit\set2\set_types.h\r
                ..\..\..\tests\unit\set2\std_hash_set.h = ..\..\..\tests\unit\set2\std_hash_set.h\r
-               ..\..\..\tests\unit\set2\std_hash_set_std.h = ..\..\..\tests\unit\set2\std_hash_set_std.h\r
-               ..\..\..\tests\unit\set2\std_hash_set_vc9.h = ..\..\..\tests\unit\set2\std_hash_set_vc9.h\r
                ..\..\..\tests\unit\set2\std_set.h = ..\..\..\tests\unit\set2\std_set.h\r
        EndProjectSection\r
 EndProject\r
diff --git a/tests/unit/set2/std_hash_set.h b/tests/unit/set2/std_hash_set.h
new file mode 100644 (file)
index 0000000..dcc6c42
--- /dev/null
@@ -0,0 +1,102 @@
+//$$CDS-header$$
+
+#ifndef __CDSUNIT_STD_HASH_SET_STD_H
+#define __CDSUNIT_STD_HASH_SET_STD_H
+
+#include <unordered_set>
+#include <mutex>    //unique_lock
+
+namespace set2 {
+
+    template <typename Value, typename Hash, typename Less, typename EqualTo, typename Lock,
+        class Alloc = typename CDS_DEFAULT_ALLOCATOR::template rebind<Value>::other
+    >
+    class StdHashSet
+        : public std::unordered_set<
+            Value
+            , Hash
+            , EqualTo
+            , Alloc
+        >
+    {
+    public:
+        Lock m_lock;
+        typedef std::unique_lock<Lock> scoped_lock;
+        typedef std::unordered_set<
+            Value
+            , Hash
+            , EqualTo
+            , Alloc
+        >   base_class;
+    public:
+        typedef typename base_class::value_type value_type;
+
+        StdHashSet( size_t nSetSize, size_t nLoadFactor )
+        {}
+
+        template <typename Key>
+        bool find( const Key& key )
+        {
+            scoped_lock al( m_lock );
+            return base_class::find( value_type(key) ) != base_class::end();
+        }
+
+        template <typename Key>
+        bool insert( Key const& key )
+        {
+            scoped_lock al( m_lock );
+            std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
+            return pRet.second;
+        }
+
+        template <typename Key, typename Func>
+        bool insert( Key const& key, Func func )
+        {
+            scoped_lock al( m_lock );
+            std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
+            if ( pRet.second ) {
+                func( *pRet.first );
+                return true;
+            }
+            return false;
+        }
+
+        template <typename T, typename Func>
+        std::pair<bool, bool> ensure( const T& key, Func func )
+        {
+            scoped_lock al( m_lock );
+            std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
+            if ( pRet.second ) {
+                func( true, *pRet.first, key );
+                return std::make_pair( true, true );
+            }
+            else {
+                func( false, *pRet.first, key );
+                return std::make_pair( true, false );
+            }
+        }
+
+        template <typename Key>
+        bool erase( const Key& key )
+        {
+            scoped_lock al( m_lock );
+            return base_class::erase( value_type(key) ) != 0;
+        }
+
+        template <typename T, typename Func>
+        bool erase( const T& key, Func func )
+        {
+            scoped_lock al( m_lock );
+            typename base_class::iterator it = base_class::find( value_type(key) );
+            if ( it != base_class::end() ) {
+                func( *it );
+                return base_class::erase( it ) != base_class::end();
+            }
+            return false;
+        }
+
+        std::ostream& dump( std::ostream& stm ) { return stm; }
+    };
+}   // namespace set2
+
+#endif  // #ifndef __CDSUNIT_STD_HASH_SET_STD_H
diff --git a/tests/unit/set2/std_hash_set_std.h b/tests/unit/set2/std_hash_set_std.h
deleted file mode 100644 (file)
index 611e76b..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-//$$CDS-header$$
-
-#ifndef __CDSUNIT_STD_HASH_SET_STD_H
-#define __CDSUNIT_STD_HASH_SET_STD_H
-
-#include <unordered_set>
-#include <functional>   // ref
-#include <mutex>    //unique_lock
-
-namespace set2 {
-
-    template <typename Value, typename Hash, typename Less, typename EqualTo, typename Lock,
-        class Alloc = typename CDS_DEFAULT_ALLOCATOR::template rebind<Value>::other
-    >
-    class StdHashSet
-        : public std::unordered_set<
-            Value
-            , Hash
-            , EqualTo
-            , Alloc
-        >
-    {
-    public:
-        Lock m_lock;
-        typedef std::unique_lock<Lock> scoped_lock;
-        typedef std::unordered_set<
-            Value
-            , Hash
-            , EqualTo
-            , Alloc
-        >   base_class;
-    public:
-        typedef typename base_class::value_type value_type;
-
-        StdHashSet( size_t nSetSize, size_t nLoadFactor )
-        {}
-
-        template <typename Key>
-        bool find( const Key& key )
-        {
-            scoped_lock al( m_lock );
-            return base_class::find( value_type(key) ) != base_class::end();
-        }
-
-        template <typename Key>
-        bool insert( Key const& key )
-        {
-            scoped_lock al( m_lock );
-            std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
-            return pRet.second;
-        }
-
-        template <typename Key, typename Func>
-        bool insert( Key const& key, Func func )
-        {
-            scoped_lock al( m_lock );
-            std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
-            if ( pRet.second ) {
-                func( *pRet.first );
-                return true;
-            }
-            return false;
-        }
-
-        template <typename T, typename Func>
-        std::pair<bool, bool> ensure( const T& key, Func func )
-        {
-            scoped_lock al( m_lock );
-            std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
-            if ( pRet.second ) {
-                func( true, *pRet.first, key );
-                return std::make_pair( true, true );
-            }
-            else {
-                func( false, *pRet.first, key );
-                return std::make_pair( true, false );
-            }
-        }
-
-        template <typename Key>
-        bool erase( const Key& key )
-        {
-            scoped_lock al( m_lock );
-            return base_class::erase( value_type(key) ) != 0;
-        }
-
-        template <typename T, typename Func>
-        bool erase( const T& key, Func func )
-        {
-            scoped_lock al( m_lock );
-            typename base_class::iterator it = base_class::find( value_type(key) );
-            if ( it != base_class::end() ) {
-                func( *it );
-                return base_class::erase( it ) != base_class::end();
-            }
-            return false;
-        }
-
-        std::ostream& dump( std::ostream& stm ) { return stm; }
-    };
-}   // namespace set2
-
-#endif  // #ifndef __CDSUNIT_STD_HASH_SET_STD_H
index fa9a270d55b1a8b84a958dc40dea9b215cb110a8..096b121f9eeb5c042e5c6f0454d0e4e0e12d670c 100644 (file)
@@ -4,7 +4,6 @@
 #define __CDSUNIT_STD_SET_VC_H
 
 #include <set>
-#include <functional>   // ref
 #include <mutex>    //unique_lock
 
 namespace set2 {
@@ -14,7 +13,7 @@ namespace set2 {
     class StdSet: public std::set<Value, Less, Alloc>
     {
         Lock m_lock;
-        typedef std::unique_lock<Lock> AutoLock;
+        typedef std::unique_lock<Lock> scoped_lock;
         typedef std::set<Value, Less, Alloc> base_class;
     public:
         typedef typename base_class::key_type value_type;
@@ -26,20 +25,20 @@ namespace set2 {
         bool find( const Key& key )
         {
             value_type v( key );
-            AutoLock al( m_lock );
+            scoped_lock al( m_lock );
             return base_class::find( v ) != base_class::end();
         }
 
         bool insert( value_type const& v )
         {
-            AutoLock al( m_lock );
+            scoped_lock al( m_lock );
             return base_class::insert( v ).second;
         }
 
         template <typename Key, typename Func>
         bool insert( Key const& key, Func func )
         {
-            AutoLock al( m_lock );
+            scoped_lock al( m_lock );
             std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
             if ( pRet.second ) {
                 func( *pRet.first );
@@ -51,7 +50,7 @@ namespace set2 {
         template <typename T, typename Func>
         std::pair<bool, bool> ensure( const T& key, Func func )
         {
-            AutoLock al( m_lock );
+            scoped_lock al( m_lock );
             std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
             if ( pRet.second ) {
                 func( true, *pRet.first, key );
@@ -66,14 +65,14 @@ namespace set2 {
         template <typename Key>
         bool erase( const Key& key )
         {
-            AutoLock al( m_lock );
+            scoped_lock al( m_lock );
             return base_class::erase( value_type(key) ) != 0;
         }
 
         template <typename T, typename Func>
         bool erase( const T& key, Func func )
         {
-            AutoLock al( m_lock );
+            scoped_lock al( m_lock );
             typename base_class::iterator it = base_class::find( value_type(key) );
             if ( it != base_class::end() ) {
                 func( *it );