| 1 | #include <boost/math/quaternion.hpp>
|
|---|
| 2 | #include <boost/operators.hpp>
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 | using namespace boost::math;
|
|---|
| 6 |
|
|---|
| 7 | template<class T>
|
|---|
| 8 | class Wrapper
|
|---|
| 9 | : boost::field_operators<Wrapper<T> >
|
|---|
| 10 | {
|
|---|
| 11 | public:
|
|---|
| 12 | Wrapper(const T& w = T())
|
|---|
| 13 | : v_(w)
|
|---|
| 14 | { }
|
|---|
| 15 |
|
|---|
| 16 | Wrapper<T>& operator+=(const Wrapper<T>& w)
|
|---|
| 17 | {
|
|---|
| 18 | v_ += w.v_;
|
|---|
| 19 | return *this;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | Wrapper<T> operator+() const
|
|---|
| 23 | {
|
|---|
| 24 | return Wrapper<T>(+v_);
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | Wrapper<T>& operator-=(const Wrapper<T>& w)
|
|---|
| 28 | {
|
|---|
| 29 | v_ -= w.v_;
|
|---|
| 30 | return *this;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | Wrapper<T> operator-()
|
|---|
| 34 | {
|
|---|
| 35 | return Wrapper<T>(-v_);
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | Wrapper<T>& operator*=(const Wrapper<T>& w)
|
|---|
| 39 | {
|
|---|
| 40 | v_ *= w.v_;
|
|---|
| 41 | return *this;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | Wrapper<T>& operator/=(const Wrapper<T>& w)
|
|---|
| 45 | {
|
|---|
| 46 | v_ /= w.v_;
|
|---|
| 47 | return *this;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | private:
|
|---|
| 51 | T v_;
|
|---|
| 52 | };
|
|---|
| 53 |
|
|---|
| 54 | typedef Wrapper<int> wr;
|
|---|
| 55 | typedef quaternion<wr> quat1;
|
|---|
| 56 |
|
|---|
| 57 | typedef Wrapper<wr> wrr;
|
|---|
| 58 | typedef quaternion<wrr> quat2;
|
|---|
| 59 |
|
|---|
| 60 | int main(int argc, const char *argv[])
|
|---|
| 61 | {
|
|---|
| 62 | // This works
|
|---|
| 63 | quat1 q1(wr(1), wr(2), wr(3), wr(4));
|
|---|
| 64 | pow(q1, 4);
|
|---|
| 65 |
|
|---|
| 66 | // This does not
|
|---|
| 67 | quat2 q2(wrr(3), wrr(4), wrr(5), wrr(6));
|
|---|
| 68 | //pow(q2, 4);
|
|---|
| 69 |
|
|---|
| 70 | return 0;
|
|---|
| 71 | }
|
|---|