Changeset 4e7f0f1 for src/Common/utility.h
- Timestamp:
- Sep 7, 2016, 11:40:52 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, 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:
- 3b58d91
- Parents:
- e76acbe (diff), 02cea2d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
re76acbe r4e7f0f1 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 264 template< typename ThisType > 265 std::weak_ptr<ThisType> RefCountSingleton<ThisType>::global_instance; 266 248 267 // RAII object to regulate "save and restore" behaviour, e.g. 249 268 // void Foo::bar() {
Note: See TracChangeset
for help on using the changeset viewer.