title: boost::operators mixed arithmetic
body: <p>based on the example here <a href="http://www.boost.org/doc/libs/release/libs/utility/operators.htm#example" rel="nofollow">http://www.boost.org/doc/libs/release/libs/utility/operators.htm#example</a>, I have implemented the following derived class of <code>boost::numeric::ublas::vector</code>:</p>
  
  <pre><code>namespace Chebyshev
  {
    template&lt;typename T&gt;
    class function_data : public boost::numeric::ublas::vector&lt;T&gt;,
                                 boost::addable&lt;function_data&lt;T&gt; &gt;,
                                 boost::subtractable&lt;function_data&lt;T&gt; &gt;,
                                 boost::multipliable2&lt;function_data&lt;T&gt;, T&gt;,
                                 boost::dividable2&lt;function_data&lt;T&gt;, T&gt;
    {
      public:
        char dataflag;
        function_data() : boost::numeric::ublas::vector&lt;T&gt;() {dataflag=0;} ///&lt; The default empty constructor
        function_data(const boost::numeric::ublas::vector&lt;T&gt;&amp; vec) : boost::numeric::ublas::vector&lt;T&gt;(vec) {dataflag=0;} ///&lt; The copy constructor without a flag.
        function_data(const boost::numeric::ublas::vector&lt;T&gt;&amp; vec, char flag) : boost::numeric::ublas::vector&lt;T&gt;(vec), dataflag(flag) {} ///&lt; The copy constructor with a flag.
        ~function_data() {} ///&lt; The destructor.
        function_data&lt;T&gt;&amp; operator= (const boost::numeric::ublas::vector&lt;T&gt;&amp; in) {boost::numeric::ublas::vector&lt;T&gt;::operator=(in); return *this;} ///&lt; The assignment operator from a boost::numeric::ublas::vector&lt;T&gt;.
        function_data&lt;T&gt;&amp; operator= (const function_data&lt;T&gt;&amp; in) {boost::numeric::ublas::vector&lt;T&gt;::operator=(in); dataflag=in.dataflag; return *this;} ///&lt; The assignment operator.
        function_data&lt;T&gt;&amp; operator+= (const function_data&lt;T&gt;&amp; in) {this-&gt;boost::numeric::ublas::vector&lt;T&gt;::operator+=(in); this-&gt;dataflag=this-&gt;dataflag; return *this;}
        function_data&lt;T&gt;&amp; operator-= (const function_data&lt;T&gt;&amp; in) {this-&gt;boost::numeric::ublas::vector&lt;T&gt;::operator-=(in); this-&gt;dataflag=this-&gt;dataflag; return *this;}
        function_data&lt;T&gt;&amp; operator*= (T in) {this-&gt;boost::numeric::ublas::vector&lt;T&gt;::operator*=(in); this-&gt;dataflag=this-&gt;dataflag; return *this;}
        function_data&lt;T&gt;&amp; operator/= (T in) {this-&gt;boost::numeric::ublas::vector&lt;T&gt;::operator/=(in); this-&gt;dataflag=this-&gt;dataflag; return *this;}
        friend std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const function_data&lt;T&gt;&amp; fd) {os &lt;&lt; "[type " &lt;&lt; fd.dataflag &lt;&lt; "] " &lt;&lt; static_cast&lt;boost::numeric::ublas::vector&lt;T&gt; &gt;(fd); return os;} ///&lt; The &lt;&lt; operator.
    };
  }
  </code></pre>
  
  <p>However, compiling the following snippet of code</p>
  
  <pre><code>int main( int argc, char ** argv)
  {
    Chebyshev::function_data&lt;std::complex&lt;double&gt; &gt; u;
    /* some stuff putting values in u */
    std::cout &lt;&lt; u*2 &lt;&lt; std::endl;
    return 0;
  }
  </code></pre>
  
  <p>gives a "ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second" warning and proceeds to give the ublas vector_expression version (with <code>u</code> cast as some kind of vector_expression) and my version (with <code>2</code> cast as a <code>const std::complex&lt;double&gt;&amp;</code>).</p>
  
  <p>I would like to be able to use mixed arithmetic in my class as in the above snippet of code, but the explanation on the boost::operators website isn't clear to me. What do I have to add or change in my class to allow this?</p>
  
  <p>Also, in the example, the inheritance list has each class inside the last <code>&gt;</code> of the previous class. I don't see any difference in the output of the compiler whether I write it that way or the way I have above. Which is the proper way to write it?</p>
  
  <p>Best regards, Brett.</p>