diff --git a/array.h b/array.h index cbda857..0b9ab9d 100644 --- a/array.h +++ b/array.h @@ -33,6 +33,8 @@ class GenericArray : public ReprProxy>, public std::vector { using Base::size; using Base::begin; using Base::end; + using Base::insert; + using Base::clear; template static GenericArray random(size_t size, const Args& ... args); @@ -52,10 +54,6 @@ class GenericArray : public ReprProxy>, public std::vector { GenericArray inverse() const; - // TODO(ifsmirnov): think about naming - GenericArray& add(T value); - GenericArray added(T value) const; - template GenericArray subseq(const std::vector& indices) const; @@ -66,6 +64,12 @@ class GenericArray : public ReprProxy>, public std::vector { const T& choice() const; GenericArray choice(size_t count) const; GenericArray choiceWithRepetition(size_t count) const; + + GenericArray& operator+=(const GenericArray& other); + GenericArray operator+(const GenericArray& other) const; + + GenericArray& operator*=(int k); + GenericArray operator*(int k) const; }; template @@ -197,21 +201,6 @@ GenericArray GenericArray::inverse() const { return result; } -template -GenericArray& GenericArray::add(T value) { - for (T& x: *this) { - x += value; - } - return *this; -} - -template -GenericArray GenericArray::added(T value) const { - auto res = *this; - res.add(value); - return res; -} - template template GenericArray GenericArray::subseq( @@ -257,13 +246,37 @@ GenericArray GenericArray::choice(size_t count) const { return subseq(res); } -// not sure if it would be needed ever -/* template -std::ostream& operator<<(std::ostream& out, const GenericArray& array) { - return out << repr(array); +GenericArray& GenericArray::operator+=(const GenericArray& other) { + insert(end(), other.begin(), other.end()); + return *this; +} + +template +GenericArray GenericArray::operator+(const GenericArray& other) const { + GenericArray copy(*this); + return copy += other; +} + +template +GenericArray& GenericArray::operator*=(int k) { + if (k == 0) { + clear(); + return *this; + } + + size_t size = this->size(); + while (k-- > 1) { + insert(end(), begin(), begin() + size); + } + return *this; +} + +template +GenericArray GenericArray::operator*(int k) const { + GenericArray copy(*this); + return copy *= k; } -*/ } // namespace impl