title: Return a unique_ptr by reference
body: <p>So I've solved this problem, but I need your opinion if what I did is best practice.</p>
  
  <p>A simple class holds a vector of <code>unique_ptrs</code> to order objects. I will explain the member variable <code>null_unique</code> below. </p>
  
  <pre><code>class order_collection {
      typedef std::unique_ptr&lt;order&gt; ord_ptr;
      typedef std::vector&lt;ord_ptr&gt; ord_ptr_vec;
      ord_ptr_vec orders;
      ord_ptr null_unique;
  public:
      ...
      const ord_ptr &amp; find_order(std::string);
      ....
  </code></pre>
  
  <p>So I need the users of this class to get access to the order <code>unique_ptr</code> if found. However I'm not going to move the object out of the vector so I'm returning the <code>unique_ptr</code> as const ref. My implementation of the <code>find_order</code> method: </p>
  
  <pre><code>const order_collection::ord_ptr &amp; order_collection::find_order(std::string id) {
      auto it = std::find_if(orders.begin(),orders.end(),
                             [&amp;](const order_collection::ord_ptr &amp; sptr) {
                                 return sptr-&gt;getId() == id;
                             });
  
      if (it == orders.end())
          return null_unique; // can't return nullptr here
      return *it;
  }
  </code></pre>
  
  <p>Since I'm returning by reference I can't return a nullptr. If I try to do so, I get <code>warning : returning reference to a temporary</code>. And if nothing is found the program crashes. So I added a <code>unique_ptr&lt;order&gt;</code> member variable called <code>null_unique</code> and I return it when find doesn't find an order. This solves the problem and warning is gone and doesn't crash when no order is found. </p>
  
  <p>However I'm doubting my solution as it make my class ugly. Is this the best practice for handling this situation? </p>