title: Google Test Framework does not print std::optional
body: <p>I have a data structure which is being notified to a listener. Among its many variables, it has an optional double which represents an angle:</p>
  <pre><code>struct Data
  {
      // ...other data fields
      std::optional&lt;double&gt; angle;
      // ...other data fields
  };
  </code></pre>
  <p>I want to check that the listener is being called with the right <code>angle</code>. I am using the <strong>Google Test Framework</strong>, so I have defined my own matcher here:</p>
  <pre><code>MATCHER_P( HasAngle, angle, &quot;&quot; )
  {
      if ( !arg.angle.has_value( ) )
      {
          return false;
      }
  
      return arg.angle.value( ) == angle;
  }
  </code></pre>
  <p>And checked if my listener is being called with the expected value.</p>
  <pre><code>EXPECT_CALL( listener, on_event( HasAngle( 45.0 ) ) ).Times( AtLeast( 1 ) );
  </code></pre>
  <p>It ended up that the listener is not called with the expected value, but the printouts are really unreadable:</p>
  <pre><code>  Expected arg #0: has angle 45
         Actual: 128-byte object &lt;75-85 4D-52 FB-21 F9-BF 47-D9 48-53 FB-21 09-C0 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 01-17 23-83 FD-7F 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00&gt;
  </code></pre>
  <p>The actual value is unintelligible. I was not expecting the framework to not support C++17 types by default, so I started reading the <strong>Google Test Framework Cookbook</strong> and I tried to add my own <code>PrintTo</code> overload like this:</p>
  <pre><code>void
  PrintTo( const std::optional&lt; double &gt;&amp; opt, std::ostream* os )
  {
      if ( !opt )
      {
          *os &lt;&lt; &quot;std::nullopt&quot;;
      }
      else
      {
          *os &lt;&lt; *opt;
      }
  }
  </code></pre>
  <p>Needless to say, it did not help. What I am pretty much sure is that since the output states <code>128-byte object</code> it is trying to print the sole <code>std::optional&lt;double&gt;</code> and not the entire <code>struct Data</code>, which is much bigger than that, but it is not succeeding despite the overloaded <code>PrintTo</code>.</p>