1

add swap_n to array

This commit is contained in:
2022-07-19 00:01:40 +02:00
parent e9b24d06be
commit 348611df26

View File

@ -20,10 +20,6 @@ public:
constexpr Iterator begin() const { return this->begin(); }
constexpr Iterator end() const { return this->end(); }
constexpr unsigned int size() const {
return N;
}
T& operator[](std::size_t i) {
return this->buf[i];
}
@ -37,6 +33,19 @@ public:
std::swap(this->buf[i], other[i]);
}
}
// Array& other has to have size n:
// arr1.swap_n<5>(arr2) => arr2 has size 5, arr1 has size >= 5
template<std::size_t n>
void swap_n(Array<Type, n>& other) {
for (std::size_t i = 0; i < n; ++i) {
std::swap(this->buf[i], other[i]);
}
}
constexpr std::size_t size() const {
return N;
}
};
#endif