Skip to content

Instantly share code, notes, and snippets.

@ttchengcheng
Created May 25, 2018 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttchengcheng/34ba8636638dd9bea9405b16d91a10a9 to your computer and use it in GitHub Desktop.
Save ttchengcheng/34ba8636638dd9bea9405b16d91a10a9 to your computer and use it in GitHub Desktop.
Some C++ patterns

C++ patterns

singleton

// http://www.modernescpp.com/index.php/thread-safe-initialization-of-a-singleton
// fast and thread safe

class MySingleton{
public:
  static MySingleton& getInstance(){
    static MySingleton instance;
    return instance;
  }
private:
  MySingleton()= default;
  ~MySingleton()= default;
  MySingleton(const MySingleton&)= delete;
  MySingleton& operator=(const MySingleton&)= delete;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment