Changeset e491159 for src/Common
- Timestamp:
- Aug 31, 2016, 11:20:03 AM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1f75e2d
- Parents:
- bda58ad
- Location:
- src/Common
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
rbda58ad re491159 17 17 #define _UTILITY_H 18 18 19 #include <cctype> 19 20 #include <iostream> 21 #include <iterator> 22 #include <list> 23 #include <memory> 20 24 #include <sstream> 21 #include <iterator>22 25 #include <string> 23 #include <cctype>24 #include <list>25 26 26 27 template< typename T > … … 246 247 } 247 248 249 template< typename ThisType > 250 class RefCountSingleton { 251 public: 252 static std::shared_ptr<ThisType> get() { 253 if( global_instance.expired() ) { 254 std::shared_ptr<ThisType> new_instance = std::make_shared<ThisType>(); 255 global_instance = new_instance; 256 return std::move(new_instance); 257 } 258 return global_instance.lock(); 259 } 260 private: 261 static std::weak_ptr<ThisType> global_instance; 262 }; 263 248 264 #endif // _UTILITY_H 249 265
Note:
See TracChangeset
for help on using the changeset viewer.