title: How do I return an optional pointer or reference ( std::optional )?
body: <p>Suppose I have the following template function:</p>
  
  <pre><code>template &lt;typename T&gt;
  std::optional&lt;std::reference_wrapper&lt;const T&gt;&gt; larger(const T data[], size_t count) {
      if(!count) return std::nullopt;
  
      size_t index_max {};
      for(size_t i {1ULL}; i &lt; count; ++i)
          index_max = data[i] &gt; data[index_max] ? i : index_max;
  
      return std::optional&lt; std::reference_wrapper&lt;const T&gt; &gt; {&amp;data[index_max]};
  }
  </code></pre>
  
  <p>What i'm trying to do is to return an optional reference but not succeeding in doing so. I'm not sure how to proceed from here. This is what I came up with, initially what I had was <code>std::optional&lt;const T*&gt;</code> as the return type.</p>