title: Factories: how to pass temporary smart pointers to functions. C++
body: <p>I have a class Foo </p>
  
  <pre><code>class Foo;
  </code></pre>
  
  <p>a factory returning a pointer to it: </p>
  
  <pre><code>std::unique_ptr&lt;Foo&gt; createFoo(); 
  </code></pre>
  
  <p>and, since I have been told by <a href="https://herbsutter.com/2013/06/05/gotw-91-solution-smart-pointer-parameters/" rel="noreferrer">Herb</a> that a plain function with no special claim on the lifetime of Foo should take plain naked pointers:</p>
  
  <pre><code>void plainf(Foo* f);
  </code></pre>
  
  <p>How is my client supposed to correctly do this? </p>
  
  <pre><code>plainF(createFoo());
  </code></pre>
  
  <p>He would not be happy if he had to write: </p>
  
  <pre><code>auto someName = createFoo();
  plainF(someName.get()); 
  </code></pre>