Tweak scoped_set_adder
David Blume

David Blume commited on 2017-06-18 14:45:21
Showing 3 changed files, with 11 additions and 9 deletions.

... ...
@@ -93,7 +93,8 @@ int main() {
93 93
 
94 94
 	{
95 95
 		std::unique_ptr<int> up( new int() );
96
-		scoped_set_adder set_adder("testing unique_ptr");
96
+		scoped_set_adder set_adder("a set_adder object");
97
+		scoped_set_adder another_set_adder("and another set_adder");
97 98
 		if (up) {
98 99
 		    cout << "unique_ptr passes if." << endl;
99 100
 		} else {
... ...
@@ -101,15 +102,16 @@ int main() {
101 102
 		}
102 103
 		up.release();
103 104
 		if (up) {
104
-		    cout << "unique_ptr 2 passes if." << endl;
105
+		    cout << "unique_ptr after release passes if." << endl;
105 106
 		} else {
106
-		    cout << "unique_ptr 2 fails if." << endl;
107
+		    cout << "unique_ptr after release fails if." << endl;
107 108
 		}
108 109
 		if (up.get()) {
109
-		    cout << "unique_ptr 3 passes if." << endl;
110
+		    cout << "unique_ptr.get() after release passes if." << endl;
110 111
 		} else {
111
-		    cout << "unique_ptr 3 fails if." << endl;
112
+		    cout << "unique_ptr.get() after release fails if." << endl;
112 113
 		}
114
+        scoped_set_adder::dump();
113 115
 	}
114 116
 
115 117
     {   // Testing Herb Sutter's pImpl template
... ...
@@ -117,7 +119,7 @@ int main() {
117 119
         my_class->f();
118 120
     }
119 121
 
120
-    deadlock();
122
+    // cout << "deadlock() returned " << deadlock() << endl;
121 123
 
122 124
     // This_function_is_not_defined();
123 125
  
... ...
@@ -19,9 +19,9 @@ scoped_set_adder::~scoped_set_adder() {
19 19
     g_items.erase(this);
20 20
 }
21 21
  
22
-bool scoped_set_adder::dump() const {
22
+bool scoped_set_adder::dump() {
23 23
     std::lock_guard<std::mutex> lock(g_mutex);
24 24
     bool ret = (g_items.size() > 0);
25
-    std::cout << "suppressed " << ret << " count " << g_items.size() << std::endl;
25
+    std::cout << "Scoped sets exist: " << ret << ", count: " << g_items.size() << std::endl;
26 26
     return ret;
27 27
 }
... ...
@@ -9,7 +9,7 @@ public:
9 9
     scoped_set_adder(const scoped_set_adder&) = delete;
10 10
     scoped_set_adder& operator=(const scoped_set_adder&) = delete;
11 11
 
12
-	bool dump() const;
12
+	static bool dump();
13 13
  
14 14
 private:
15 15
     std::string name_;
16 16