
Robert Ramey <ramey <at> rrsd.com> writes:
template<class T> struct my_type : boost::numeric::operators<T> { T & operator+=(T & rhs); // automatically generate operator+, etc // ... };
so that one can use my_type<int> x, y, z; z = x + y; // etc..
I'm not familiar with boost::numeric::operators<T> but I have used Boost.Operators to do similar. In this case I'd write: template<typename T> struct my_type : boost::addable<my_type<T> > { my_type& operator+=(my_type<T> const& rhs); ... };
There is a simple example like this in the documentation. So far so good.
Now given:
int & operator+=(int & lhs, my_type<int>);
I want to use operators<T, U> to generate
int operator+(int & lhs, my_type<int>);
If you want that exact return value ("int" not "my_type<int>") then I suppose you've defined the proper operator+= overload for it and just need that visible and to modify my_type as follows: template<typename T> struct my_type : boost::addable<my_type<T>, boost::addable<int, my_type<T> > > { ... }; HTH, -Ryan