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; |
... | ... |
@@ -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 |