title: Templated operator overload does not compile if OpenCV headers are included
body: <p>I'm trying to overload the left shift operator <code>&lt;&lt;</code> for a custom class, using a template and <code>std::enable_if</code> to use a single overload declaration &amp; definition for both console / print output and file writing:</p>
  <p><code>Foo.hpp</code>:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;type_traits&gt;
  // #include &lt;opencv2/opencv.hpp&gt;
  
  namespace cv {
  class Foo {
   public:
      
      Foo() { }
  
  
      ~Foo() { }
      const int mb = 78;
  
      static bool toFile(const Foo&amp; instance);
  };
  }
  
  template &lt; typename OSTR_T,
                      typename = typename std::enable_if&lt; std::is_base_of&lt; std::ostream, OSTR_T &gt;::value &gt; &gt;
  OSTR_T&amp; operator&lt;&lt;(OSTR_T&amp; os, const cv::Foo&amp; foo);
  </code></pre>
  <p>and <code>Foo.cpp</code>:</p>
  <pre><code>#include &quot;Foo.hpp&quot;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  namespace cv {
  
  bool Foo::toFile(const Foo&amp; instance) {
      std::ofstream file(&quot;debug.txt&quot;, std::ios::app);
      file &lt;&lt; instance;
      file.close();
      return true;
  }
  }  // namespace cv
  
  template &lt; typename OSTR_T, typename &gt;
  OSTR_T&amp; operator&lt;&lt;(OSTR_T&amp; os, const cv::Foo&amp; foo) {
      os &lt;&lt; foo.mb &lt;&lt; &quot;\n&quot;;
      return os;
  }
  
  template std::ofstream&amp; operator&lt;&lt; &lt; std::ofstream &gt; (std::ofstream&amp;, const cv::Foo&amp;);
  template std::ostream&amp;  operator&lt;&lt; &lt; std::ostream &gt;  (std::ostream&amp;, const cv::Foo&amp;);
  </code></pre>
  <p>This approach compiles and works fine, however I need to use several tools provided by OpenCV to extend <code>Foo</code>, namely declaring some <code>cv::Point</code> and <code>cv::Mat</code> members.</p>
  <p>Strangely, I've found that <strong>simply including OpenCV's header</strong> <code>opencv2/opencv.hpp</code> on <code>Foo.hpp</code> is enough for the code not to compile anymore, with the compiler for some reason becoming enable to find the <code>&lt;&lt;</code> overload:</p>
  <pre><code>error: no match for ‘operator&lt;&lt;’ (operand types are ‘std::ofstream’ {aka ‘std::basic_ofstream&lt;char&gt;’} and ‘const cv::Foo’)
  9 |         file &lt;&lt; instance;
    |         ~~~~ ^~ ~~~~~~~~
    |         |       |
    |         |       const cv::Foo
    |         std::ofstream {aka std::basic_ofstream&lt;char&gt;}
  </code></pre>
  <p>I've also noticed that this only happens <strong>if I declare Foo within the cv:: namespace</strong>. What exactly is happening here, how can including a header create such conflict?</p>