title: c++ passing an object as function parameter to a function expecting an std::optional
body: <p>I have a function <code>func(std::optional&lt;A&gt;&amp; a)</code> and I want to call it using an instance of <code>A</code> like in this code:</p>
  <pre><code>#include &lt;optional&gt;
  #include &lt;iostream&gt;
  
  class A
  {
  public:
      explicit A(int a) : m_a(a)
      {}
  
      ~A() = default;
  
      int get() { return m_a; }
  
      A(const A&amp;) = delete;
      A(A&amp;&amp;) = delete;
      A&amp; operator=(const A&amp;) = delete;
      A&amp; operator=(A&amp;&amp;) = delete;
  
  private:
      int m_a;
  };
  
  void func(std::optional&lt;A&gt;&amp; a)
  {
      if (a.has_value()) {
          std::cout &lt;&lt; a-&gt;get() &lt;&lt; std::endl;
      } else {
          std::cout &lt;&lt; &quot;no value&quot; &lt;&lt; std::endl;
      }
  }
  
  int main() {
      A a(5);
      func(a);
  }
  </code></pre>
  <p>As you can see, <code>A</code> does not allow for any copy or move operators. When I run this code I get</p>
  <pre><code>&lt;source&gt;:34:10: error: invalid initialization of reference of type 'std::optional&lt;A&gt;&amp;' from 
  expression of type 'A'
  </code></pre>
  <p>My question is how can I pass <code>a</code> to <code>func()</code> and make the <code>std::optional</code> reference my object?</p>
  <p>If that's not possible, I would still like to have a way to pass <code>a</code> to <code>func()</code> not using c-style pointers (<code>func(A* a)</code> for example)</p>