Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {1.f, 2.f, 3.f} * 2.f = {2.f, 4.f, 6.f}
- {1.f, 0.f} + {0.f, 1.f} = {1.f, 1.f}
- template<class T, size_t N>
- class Vec : public std::array<T, N>
- {
- friend Vec<T, N>& operator*=(Vec<T, N>& a, const Vec<T, N>& b)
- {
- std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::multiplies<>());
- return a;
- }
- template<class S>
- friend Vec<T, N>& operator*=(Vec<T, N>& a, const S& b)
- {
- std::transform(a.begin(), a.end(), a.begin(), [&] (T x) { return x*b; });
- return a;
- }
- template<class S>
- friend Vec<T, N> operator*(Vec<T, N> a, const S& b)
- {
- return a *= b;
- }
- };
- using Vec2 = Vec<float, 2>;
- Vec2 a{1.f, 1.f};
- auto b = a * 0.5f; // b = {.5f, .5f} <- as expected
- auto c = 0.5f * a; // c = {.5f, 0.f} <- what happened here?
Add Comment
Please, Sign In to add comment