Ticket #5369: testpow.cpp

File testpow.cpp, 1.0 KB (added by Eduardo de Mattos Kalinowski <eduardo@…>, 12 years ago)

Test showing multiple levels of indirection

Line 
1#include <boost/math/quaternion.hpp>
2#include <boost/operators.hpp>
3
4
5using namespace boost::math;
6
7template<class T>
8class Wrapper
9 : boost::field_operators<Wrapper<T> >
10{
11public:
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
50private:
51 T v_;
52};
53
54typedef Wrapper<int> wr;
55typedef quaternion<wr> quat1;
56
57typedef Wrapper<wr> wrr;
58typedef quaternion<wrr> quat2;
59
60int 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}