From 906de2474b29255b7d81ccc16b06cb3154e39932 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 7 May 2022 17:29:06 +0300 Subject: Autocommit at 07.05.2022 @ 17:29 --- src/Generic/List/List.hpp | 49 ++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'src/Generic') diff --git a/src/Generic/List/List.hpp b/src/Generic/List/List.hpp index cb49da4..d4385e2 100644 --- a/src/Generic/List/List.hpp +++ b/src/Generic/List/List.hpp @@ -4,7 +4,7 @@ #include #include -template +template class List { protected: T* elements; @@ -45,9 +45,14 @@ public: friend std::ostream& operator<<(std::ostream& ostr, const List& obj); }; +template +std::istream& operator>>(std::istream& istr, List& obj); +template +std::ostream& operator<<(std::ostream& ostr, const List& obj); + /* Private */ -template +template void List::resize() { length = (length == 0) ? 8 : length << 1; T* temp = new T[length]; @@ -57,12 +62,12 @@ void List::resize() { elements = temp; } -template +template void List::free() { delete[] elements; } -template +template void List::copyFrom(const List& other) { elements = new T[other.length]; for (int i = 0; i < other.count; i++) @@ -73,7 +78,7 @@ void List::copyFrom(const List& other) { /* Public */ -template +template List::List(const T* elements, unsigned elementsCount) { length = 8; count = elementsCount; @@ -82,14 +87,14 @@ List::List(const T* elements, unsigned elementsCount) { this->elements[i] = elements[i]; } -template +template void List::add(T element) { if (length == count) resize(); elements[count++] = element; } -template +template void List::insertAt(T element, unsigned index) { if (index >= count) { add(element); @@ -104,7 +109,7 @@ void List::insertAt(T element, unsigned index) { count++; } -template +template bool List::removeAt(unsigned index) { if (index >= count) return false; @@ -114,7 +119,7 @@ bool List::removeAt(unsigned index) { return true; } -template +template unsigned List::findIndex(const T& element) const { unsigned ind = 0; while (ind < count && elements[ind].compare(element) != 0) @@ -122,17 +127,17 @@ unsigned List::findIndex(const T& element) const { return ind; } -template +template bool List::contain(const T& element) const { return findIndex(element) < count; } -template +template T& List::operator[](unsigned index) { return elements[index]; } -template +template const T& List::operator[](unsigned index) const { return elements[index]; } @@ -144,7 +149,7 @@ List& List::operator+=(const List other) { return *this; } -template +template std::istream& List::read(std::istream& istr) { istr.read((char*)&length, sizeof(length)); istr.read((char*)&count, sizeof(count)); @@ -158,7 +163,7 @@ std::istream& List::read(std::istream& istr) { return istr; } -template +template std::ostream& List::write(std::ostream& ostr) const { ostr.write((const char*)&length, sizeof(length)); ostr.write((const char*)&count, sizeof(count)); @@ -169,22 +174,22 @@ std::ostream& List::write(std::ostream& ostr) const { return ostr; } -template +template unsigned List::get_length() const { return length; } -template +template unsigned List::get_count() const { return count; } // Rule of 4 -template +template List::List() : List(nullptr, 0) {} -template +template List& List::operator=(const List& other) { if (this != &other) { free(); @@ -193,19 +198,19 @@ List& List::operator=(const List& other) { return *this; } -template +template List::List(const List& other) { copyFrom(other); } -template +template List::~List() { free(); } // Move semantics -template +template List::List(List&& other) { length = other.length; count = other.count; @@ -213,7 +218,7 @@ List::List(List&& other) { other.elements = nullptr; } -template +template List& List::operator=(List&& other) { if (this != &other) { free(); -- cgit v1.3.1-26-gb76a