Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4538)

Unified Diff: base/memory/singleton.h

Issue 2741493002: Improve singleton example by assuming implementation is outside base/ (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/singleton.h
diff --git a/base/memory/singleton.h b/base/memory/singleton.h
index cfdff7831f9f7b5a4ad1be5aa955f33d73112641..5c58d5fe2944cd332980fb39f5dc5e815a48c0d4 100644
--- a/base/memory/singleton.h
+++ b/base/memory/singleton.h
@@ -153,14 +153,17 @@ subtle::Atomic32 StaticMemorySingletonTraits<Type>::dead_ = 0;
// Example usage:
//
// In your header:
-// template <typename T> struct DefaultSingletonTraits;
+// namespace base {
+// template <typename T>
danakj 2017/03/09 21:18:22 nit: keep this as one line
Patrick Monette 2017/03/09 23:02:13 That's how "git cl format" does it. IMO this examp
danakj 2017/03/09 23:04:18 Ah, fair enough.
+// struct DefaultSingletonTraits;
+// }
// class FooClass {
// public:
// static FooClass* GetInstance(); <-- See comment below on this.
// void Bar() { ... }
// private:
// FooClass() { ... }
-// friend struct DefaultSingletonTraits<FooClass>;
+// friend struct base::DefaultSingletonTraits<FooClass>;
//
// DISALLOW_COPY_AND_ASSIGN(FooClass);
// };
@@ -168,7 +171,14 @@ subtle::Atomic32 StaticMemorySingletonTraits<Type>::dead_ = 0;
// In your source file:
// #include "base/memory/singleton.h"
// FooClass* FooClass::GetInstance() {
-// return Singleton<FooClass>::get();
+// return base::Singleton<FooClass>::get();
+// }
+//
+// Or for leaky singletons:
+// #include "base/memory/singleton.h"
+// FooClass* FooClass::GetInstance() {
+// return base::Singleton<
+// FooClass, base::LeakySingletonTraits<FooClass>>::get();
// }
//
// And to call methods on FooClass:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698