Boost logo

Boost Users :

From: Scott, Steven (Steven.Scott_at_[hidden])
Date: 2007-06-21 11:39:10


I'm sure the answer to this is out there somewhere, but I'm
having trouble finding it. (wearing flame-retardant clothes...)

I want to use boost::operators::field_operators to generate all
the mathematical operators to allow Vector/scalar arithmetic.
Everything works fine except for dividing scalars by vectors.

Class Vector looks like this:

    class Vector
      : public std::vector<double>,
      boost::field_operators<Vector,
                             boost::field_operators<Vector, double> >
    {
      // required operator+=, -=, *=, /= defined here.
     };

Now if I write:

   double x(3.0);
   Vector v(5), w;
   v[0] = 1; v[1] = 2; v[2] = 3; v[3] = 4; v[4]=5;

    w = 3+v; // works fine
    w = v+3; // works fine
     ... // subtract and multiply work on both sides
    w = v/x; // works fine
    w = x/v; // fails...

I think the failure happens because of the way operator/
defined for mixed types something like this:

T operator/(U u,T t)
{
   T ans(u);
   ans/=t;
   return ans;
}

which is not what I need. Is there a way I can change the way
operator/(double,Vector) works in this one case, but keep the really
convenient
definitions generated by field_operators otherwise?

The information contained in this e-mail is confidential and/or proprietary

to Capital One and/or its affiliates. The information transmitted herewith

is intended only for use by the individual or entity to which it is

addressed. If the reader of this message is not the intended recipient,

you are hereby notified that any review, retransmission, dissemination,

distribution, copying or other use of, or taking of any action in reliance

upon this information is strictly prohibited. If you have received this

communication in error, please contact the sender and delete the material

from your computer.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net