|
Boost Users : |
Subject: [Boost-users] help with boost/numeric/operators.hpp
From: Robert Ramey (ramey_at_[hidden])
Date: 2012-01-03 14:03:20
I'm haveing some problems figuring out how to use boost/numeric/operators
library.
OK - I understand how to use
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..
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>);
// etc.
After studying the documenation, examples and code, the best I can come up
with is:
template<class T, class U>
class helper : public boost::operators<T, U>{
};
T operator+(T & lhs, U & rhs){
helper<T, U>::operator+(lhs, rhs); // automatically generated + operator
}
// other non member operators forwarding to helper
Am I doing this corrrectly? How did the authors of operators.hpp intend the
two argument versions to be used?
Robert Ramey
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