title: operator << (stream output) for nullptr
body: <p>Consider a piece of generic C++ code which outputs to a stream the values of its arguments in case they are not equal:</p>
  
  <pre><code>#define LOG_IF_NE(a, b) if(a != b) { \
      std::cerr &lt;&lt; "Failed because (" &lt;&lt; ##a &lt;&lt; "=" &lt;&lt; (a) &lt;&lt; \
          ") != (" &lt;&lt; ##b &lt;&lt; "=" &lt;&lt; (b) &lt;&lt; ")"; \
  }
  </code></pre>
  
  <p>This is just an example, the real code throws an exception after writing message to a string stream.
  This works fine for 2 integers, 2 pointers, etc. for what stream <code>operator &lt;&lt;</code> is defined.</p>
  
  <pre><code>int g_b;
  int f(int a)
  {
      LOG_IF_NE(a, g_b);
      // implementation follows
  }
  </code></pre>
  
  <p>A problem happens when one of the arguments to <code>LOG_IF_NE</code> is <code>nullptr</code>: MSVC++2013 compiler gives <code>error C2593: 'operator &lt;&lt;' is ambiguous</code>. </p>
  
  <pre><code>int *pA;
  int g()
  {
      LOG_IF_NE(pA, nullptr);
  }
  </code></pre>
  
  <p>The problem happens because <code>nullptr</code> has a special type and <code>operator &lt;&lt;</code> is not defined in the STL for that type. An answer at <a href="https://stackoverflow.com/a/21772973/1915854">https://stackoverflow.com/a/21772973/1915854</a> suggests to define <code>operator &lt;&lt;</code> for <code>std::nullptr_t</code></p>
  
  <pre><code>//cerr is of type std::ostream, and nullptr is of type std::nullptr_t
  std::ostream&amp; operator &lt;&lt; (std::ostream&amp; os, std::nullptr_t)
  {
      return os &lt;&lt; "nullptr"; //whatever you want nullptr to show up as in the console
  }
  </code></pre>
  
  <p>Is it the right way to solve the problem? Isn't it a bug in C++11/STL that <code>operator&lt;&lt;</code> is not defined for <code>nullptr_t</code>? Is a fix expected in C++14/17? Or was it done on purpose (therefore one's private definition of <code>operator&lt;&lt;</code> could have a pitfall)?</p>