title: How is Meyers' implementation of a Singleton actually a Singleton
body: <p>I have been reading a lot about Singletons, when they should and shouldn't be used, and how to implement them safely.  I am writing in C++11, and have come across the Meyer's lazy initialized implementation of a singleton, as seen in <a href="https://stackoverflow.com/questions/1661529/is-meyers-implementation-of-singleton-pattern-thread-safe">this question.</a></p>
  
  <p>This implementation is:</p>
  
  <pre><code>static Singleton&amp; instance()
  {
       static Singleton s;
       return s;
  }
  </code></pre>
  
  <p>I understand how this is thread safe from other questions here on SO, but what I don't understand is how this is actually a singleton pattern.  I have implemented singletons in other languages, and these always end up something like this example from <a href="http://en.wikipedia.org/wiki/Singleton_pattern" rel="noreferrer">Wikipedia</a>:</p>
  
  <pre><code>public class SingletonDemo {
          private static volatile SingletonDemo instance = null;
  
          private SingletonDemo() {       }
  
          public static SingletonDemo getInstance() {
                  if (instance == null) {
                          synchronized (SingletonDemo .class){
                                  if (instance == null) {
                                          instance = new SingletonDemo ();
                                  }
                        }
                  }
                  return instance;
          }
  }
  </code></pre>
  
  <p>When I look at this second example, it is very intuitive how this is a singleton, since the class holds a reference to one instance of itself, and only ever returns that instance.  However, in the first example, I don't understand how this prevents there ever existing two instances of the object.  So my questions are:</p>
  
  <ol>
  <li>How does the first implementation enforce a singleton pattern?  I assume it has to do with the static keyword, but I am hoping that someone can explain to me in depth what is happening under the hood.</li>
  <li>Between these two implementation styles, is one preferable over the other? What are the pros and cons?</li>
  </ol>
  
  <p>Thanks for any help,</p>