title: Avoiding pointers in std::list
body: <p>I try to avoid having pointers, and instead of doing</p>
  
  <pre><code>std::list&lt;std::pair&lt;int,int&gt;* &gt; myList;
  void addElement(int a, int b) {
      myList.push_back(new std::pair&lt;int,int&gt;(a,b));
  }
  </code></pre>
  
  <p>I figured i could do something like</p>
  
  <pre><code>std::list&lt;std::pair&lt;int,int&gt; &gt; myList;
  void addElement(int a, int b) { 
      std::pair&lt;int,int&gt; p(a,b);
      myList.push_back(p);
  }
  </code></pre>
  
  <p>If i understand the behaviour correctly, this should store a copy of the pair, and automatically delete it when doing <code>myList.clear()</code> (as opposed to the pointers).</p>
  
  <p>Is this the best way to do it?
  Can i expect the compiler to optimize away the unnecessary object <code>p</code>?</p>