Boost logo

Boost Users :

From: Peter (p.schregle_at_[hidden])
Date: 2008-04-25 16:12:25


Ovanes,

sorry, I made an error when writing the sample. It should have been:

template <typename T>
struct point : boost::additive<point<T>, T>
{
    T x_;
    T y_;

    explicit point(T x=0, T y=0) : x_(x), y_(y)
    { }

    point & operator += (T offset)
    {
        x_ += offset;
        y_ += offset;
        return *this;
    }

    point & operator -= (T offset)
    {
        x_ -= offset;
        y_ -= offset;
        return *this;
    }
}

This part is working as it should.

My problem comes as soon as I make member templates out of the operators, for example like so

...
    template <typename U>
    point & operator += (U offset)
    {
        x_ += offset;
        y_ += offset;
        return *this;
    }
...

How do I write the boost::additive stuff so that it works with the operator template with all the types U that are instantiated?
Is that at all possible?

Peter

  "Ovanes Markarian" <om_boost_at_[hidden]> schrieb im Newsbeitrag news:a83c1a380804250223i4e3cbcdfu17871dfb0a585600_at_mail.gmail.com...
  Peter,

  AFAIK operator += or operator -= signature must contain a return value. In your case it can probably be void.

  template<class U>
  void operator+=(U offset)
  {
  ...
  }

  ...

  Best Regards,
  Ovanes

  On Fri, Apr 25, 2008 at 10:41 AM, Peter <p.schregle_at_[hidden]> wrote:

    Assuming I have a class like the following:

    template <typename T>
    struct point : boost::additive<point<T>, T>
    {
       T x_;
       T y_;

       explicit point(T x=0, T y=0) : x_(x), y_(y)
       { }

       operator += (T offset)
       {
           x_ += offset;
           y_ += offset;
       }

       operator -= (T offset)
       {
           x_ -= offset;
           y_ -= offset;
       }
    }

    Now I want to change the addition and subtraction operators to allow for
    different types using the following template

    class point ...

       template <typename U>
       operator += (U offset)
       {
           x_ += offset;
           y_ += offset;
       }

       template <typename U>
       operator -= (T offset)
       {
           x_ -= offset;
           y_ -= offset;
       }

    ...

    I cannot figure out how to write the proper syntax for the boost::additive
    class, so that it generates the proper additional operators for all type
    combinations. Is that possible, at all?

    Thanks, Peter

    _______________________________________________
    Boost-users mailing list
    Boost-users_at_[hidden]
    http://lists.boost.org/mailman/listinfo.cgi/boost-users

------------------------------------------------------------------------------

  _______________________________________________
  Boost-users mailing list
  Boost-users_at_[hidden]
  http://lists.boost.org/mailman/listinfo.cgi/boost-users



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