[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how can I overload the operator <<= ?

From: Andrea Latina
Subject: Re: how can I overload the operator <<= ?
Date: Tue, 12 Sep 2006 22:56:26 +0200

Thank you very much, John. In the meanwhile, I also got to the same
conclusion and now it works correctly. Before, I was wrong in setting
the return value for the operator << and this was causing the


On 12/09/06, John W. Eaton <address@hidden> wrote:
On 12-Sep-2006, Andrea Latina wrote:

| Hi all,
| I'm trying to overload the operator "<<="  to use it with some new
| TYPE that I've defined for octave, let's say:
| my_object_value : public octave_base_value {};...
| So far, I've managed to overload the operator "<<", using:
| my_object_value::register_type();
| DEFBINOP (lshift, a1, a2 );
| INSTALL_BINOP (op_lshift, my_object_value, my_object_value, lshift);
| but I could not succeed in overloading <<=.
| Which of the octave_base_value class's methods should I define into my
| class in order to have this operator working?

If your A <<= B operator will behave exactly as A = (A << B) then I
think you don't need to define anything.  For example, there is this
code in src/ov.cc that is called when performing assignments:

  const octave_value&
  octave_value::assign (assign_op op, const octave_value& rhs)
    if (op == op_asn_eq)
      operator = (rhs);
        // FIXME -- only do the following stuff if we can't find
        // a specific function to call to handle the op= operation for
        // the types we have.

        binary_op binop = op_eq_to_binary_op (op);

        if (! error_state)
            octave_value t = do_binary_op (binop, *this, rhs);

            if (! error_state)
              operator = (t);

        if (error_state)
          gripe_assign_failed_or_no_method (assign_op_as_string (op),
                                            type_name (), rhs.type_name ());

    return *this;

Also, I think the current implementation doesn't really allow you to
define a special function for this operator, so you are actually
forced to have the A OP= B equivalent to A = (A OP B) semantics.  I
think that's the point of the FIXME comment.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]