for (int i=0; i<N; ++i) m[i] %= x;
return *this;
}
self operator-() {
self x;
for (int i=n; i<N; ++i) x.m[i] = -m[i];
return x;
}
// дружественные операторы
friend self operator+(self x, const self& y) { return x += у; }
friend self operator-(self x, const self& y) { return x -= y; }
friend self operator+(self x, value_type y) { return x += y; }
friend self operator-(self x, value_type y) { return x -= y; }
friend self operator*(self x, value_type y) { return x *= y; }
friend self operator/(self x, value_type y) { return x /= y; }
friend self operator%(self x, value type y) { return x %= y; }
};
Пример 11.18 показывает, как можно применять шаблон класса kvector.
Пример 11.18. Применение вектора kvector
#include "kvector.hpp"
#include <algorithm>
#include <numeric>
#include <iostream>
using namespace std;
int main() {
kvector<int, 4> v = { 1, 2, 3, 4 };
cout << "sum = " << accumulate(v.begin(), v.end(), 0) << endl;
v *= 3;
cout << "sum = " << accumulated.begin(), v.end(), 0) << endl;
v += 1;