DIY 2.0 data-parallel out-of-core C++ library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List

points.hpp
1 #ifndef DIY_POINT_HPP
2 #define DIY_POINT_HPP
3
4 #include <vector>
5
6 namespace diy
7 {
8 template<class T, unsigned D>
9 class Point
10 {
11 private:
12 T data_[D];
13
14 public:
15 Point() {}
16
17 template<class U>
18 Point(const std::vector<U>& x) { for (unsigned i = 0; i < D; ++i) data_[i] = x[i]; }
19
20 T& operator[](unsigned i) { return data_[i]; }
21 const T& operator[](unsigned i) const { return data_[i]; }
22
23 Point& operator+=(const Point& other) { for (unsigned i = 0; i < D; ++i) data_[i] += other.data_[i]; return *this; }
24 friend Point operator+(const Point& x, const Point& y) { Point r = x; r += y; return r; }
25
26 Point& operator-=(const Point& other) { for (unsigned i = 0; i < D; ++i) data_[i] -= other.data_[i]; return *this; }
27 friend Point operator-(const Point& x, const Point& y) { Point r = x; r -= y; return r; }
28
29 T norm2() const { T r = 0; for (unsigned i = 0; i < D; ++i) r += data_[i]*data_[i]; return r; }
30 };
31 }
32
33 #endif
diy
diy::Point
Definition: points.hpp:9