| 98 | |
| 99 | template<typename QuaternionType> |
| 100 | void check_stdvector_quaternion(const QuaternionType&) |
| 101 | { |
| 102 | typedef typename QuaternionType::Coefficients Coefficients; |
| 103 | QuaternionType x(Coefficients::Random()), y(Coefficients::Random()); |
| 104 | std::vector<QuaternionType> v(10), w(20, y); |
| 105 | v[5] = x; |
| 106 | w[6] = v[5]; |
| 107 | VERIFY_IS_APPROX(w[6], v[5]); |
| 108 | v = w; |
| 109 | for(int i = 0; i < 20; i++) |
| 110 | { |
| 111 | VERIFY_IS_APPROX(w[i], v[i]); |
| 112 | } |
| 113 | |
| 114 | v.resize(21); |
| 115 | v[20] = x; |
| 116 | VERIFY_IS_APPROX(v[20], x); |
| 117 | v.resize(22,y); |
| 118 | VERIFY_IS_APPROX(v[21], y); |
| 119 | v.push_back(x); |
| 120 | VERIFY_IS_APPROX(v[22], x); |
| 121 | VERIFY((internal::UIntPtr)&(v[22]) == (internal::UIntPtr)&(v[21]) + sizeof(QuaternionType)); |
| 122 | |
| 123 | // do a lot of push_back such that the vector gets internally resized |
| 124 | // (with memory reallocation) |
| 125 | QuaternionType* ref = &w[0]; |
| 126 | for(int i=0; i<30 || ((ref==&w[0]) && i<300); ++i) |
| 127 | v.push_back(w[i%w.size()]); |
| 128 | for(unsigned int i=23; i<v.size(); ++i) |
| 129 | { |
| 130 | VERIFY(v[i].coeffs()==w[(i-23)%w.size()].coeffs()); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | void test_stdvector_overload() |
| 135 | { |