Added Herb Sutter's pImpl, but it doesn't work yet.
David Blume

David Blume commited on 2016-09-27 16:02:51
Showing 3 changed files, with 35 additions and 0 deletions.

... ...
@@ -111,6 +111,12 @@ int main() {
111 111
 		}
112 112
 	}
113 113
 
114
+    {   // Testing Herb Sutter's pImpl template
115
+        // Fails with static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
116
+        //std::unique_ptr<MyClass> my_class;
117
+        //my_class->f();
118
+    }
119
+
114 120
     // This_function_is_not_defined();
115 121
  
116 122
     cout << "Done." << endl;
... ...
@@ -19,3 +19,16 @@ int main_helper_fn() {
19 19
     return 0;
20 20
 }
21 21
 
22
+
23
+class MyClass::Impl {
24
+public:
25
+    void f() {
26
+        cout << "The function " << __PRETTY_FUNCTION__ << " was called." << endl;
27
+    };
28
+};
29
+
30
+void MyClass::f()
31
+{
32
+    pimpl->f();
33
+}
34
+
... ...
@@ -4,4 +4,20 @@
4 4
 int main_helper_fn();
5 5
 int main_helper_fn2();
6 6
 
7
+// From CppCon 2016: Herb Sutter "Leak-Freedom in C++... By Default"
8
+// https://www.youtube.com/watch?v=JfmTagWcqoE
9
+
10
+template<class T>
11
+using Pimpl = const std::unique_ptr<T>;
12
+
13
+class MyClass {
14
+ 
15
+    class Impl;  // defined in cpp
16
+    Pimpl<Impl> pimpl;
17
+
18
+public:
19
+    void f();
20
+};
21
+
22
+
7 23
 #endif
8 24