Ignore:
Timestamp:
Sep 7, 2016, 11:40:52 AM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
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.
Message:

Merge branch 'master' into tuples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    re76acbe r4e7f0f1  
    1717#define _UTILITY_H
    1818
     19#include <cctype>
    1920#include <iostream>
     21#include <iterator>
     22#include <list>
     23#include <memory>
    2024#include <sstream>
    21 #include <iterator>
    2225#include <string>
    23 #include <cctype>
    24 #include <list>
    2526
    2627template< typename T >
     
    246247}
    247248
     249template< typename ThisType >
     250class 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
     264template< typename ThisType >
     265std::weak_ptr<ThisType> RefCountSingleton<ThisType>::global_instance;
     266
    248267// RAII object to regulate "save and restore" behaviour, e.g.
    249268// void Foo::bar() {
Note: See TracChangeset for help on using the changeset viewer.