|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2004-12-22 14:39:14
Fabio Fracassi wrote:
> Hello,
>
> I am trying to use the operators.hpp templates to create the following
> behaviour.
>
> I have a templated class like this.
>
> template <class T>
> class example {}
>
> now I want to do something like this:
>
> example<SomeType> r;
> example<SomeType> a;
> example<AnotherType> b;
>
> r = a * b
>
> To write the multiplication manually I would have to write a function template
>
> template <class T, class OtherT>
> example<T> operator*(const example<T>& op1, const example<OtherT>& op2);
>
> So, now my question is: How can this be done with operators.hpp?
> Obviously ...
>
> template <class T>
> class example : boost::multiplicative2<example<T>, example<OtherT> > {
>
> template <OtherT> example<T>& operator*=(const example<OtherT>& op);
> template <OtherT> example<T>& operator/=(const example<OtherT>& op);
> }
>
> .... won't work, since "OtherT" isn't defined at its first occurrence.
> Is there a way to do what I intended, or do I have to write these operators
> manually?
You have to write them manually.
Of course you could write your own multiplicative2 that defines
templated friend functions, but it hardly seems worth the trouble.
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
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