title: How do I template overload an operator for a group of related classes without conflicting with standard library operators?
body: <p>This seems like a fairly straight forward idea: I have a group of classes for which I should be able to write an operator, let's say subtraction, using basically the exact same code.</p>
  
  <p>When trying to do this the "obvious" way, i.e:</p>
  
  <pre><code>template &lt;typename T&gt;
  T operator-(T a, const T&amp; b) {
      return a -= b;
  }
  </code></pre>
  
  <p>Then, on certain compilers, this seems to conflict with a subtraction operator for iterators (specifically it breaks on gcc 3.4.6 and Apple LLVM, while seemingly working fine on gcc version 4 or newer), and I get the following error:</p>
  
  <pre><code> error: use of overloaded operator '-' is ambiguous (with operand types 'std::__1::__wrap_iter&lt;const double *&gt;' and 'const_iterator'
        (aka '__wrap_iter&lt;const_pointer&gt;')) 
  </code></pre>
  
  <p>I also considered template overloading for just a base class from which all of the classes in the group would be derived from, but then since the first parameter is passed by value, I think information specific to the subclass would be lost during the copy.</p>
  
  <p>Am I missing something obvious? Is there a way to do this that keeps all these compilers happy?</p>
  
  <p>Edit: the solution should ideally work in C++03.</p>