| 26 | // C++11 guarantees thread safety for static initialization |
| 27 | template<typename T> |
| 28 | class singleton { |
| 29 | public: |
| 30 | static T& get_instance() |
| 31 | { |
| 32 | static T instance; |
| 33 | return instance; |
| 34 | } |
| 35 | }; |
| 36 | #else |
| 37 | // Some compilers don't support thread-safe static initialization, so emulate it |
| 38 | template<typename T> |