From e3883be7106e667322d51e35aa124ee7298125cb Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 7 May 2022 16:08:36 +0300 Subject: Autocommit at 07.05.2022 @ 16:08 --- src/Generic/List/List.hpp | 60 +++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'src/Generic') diff --git a/src/Generic/List/List.hpp b/src/Generic/List/List.hpp index 2569380..7bbc835 100644 --- a/src/Generic/List/List.hpp +++ b/src/Generic/List/List.hpp @@ -27,9 +27,6 @@ public: List& operator+=(const List other); - std::istream& read(std::istream& istr); - std::ostream& write(std::ostream& ostr) const; - unsigned get_length() const; unsigned get_count() const; @@ -42,6 +39,11 @@ public: List& operator=(List&& other); }; +template +std::istream& operator>>(std::istream& istr, List& obj); +template +std::ostream& operator<<(std::ostream& ostr, const List& obj); + /* Private */ template @@ -141,31 +143,6 @@ List& List::operator+=(const List other) { return *this; } -template -std::istream& List::read(std::istream& istr) { - istr.read((char*)&length, sizeof(length)); - istr.read((char*)&count, sizeof(count)); - - delete[] elements; - elements = new T[length]; - - for (int i = 0; i < count; i++) - elements[i].read(istr); // disgusting - - return istr; -} - -template -std::ostream& List::write(std::ostream& ostr) const { - ostr.write((const char*)&length, sizeof(length)); - ostr.write((const char*)&count, sizeof(count)); - - for (int i = 0; i < count; i++) - elements[i].write(ostr); // disgusting - - return ostr; -} - template unsigned List::get_length() const { return length; @@ -222,4 +199,31 @@ List& List::operator=(List&& other) { return *this; } +/* Other */ + +template +std::istream& operator>>(std::istream& istr, List& obj) { + istr.read((char*)&length, sizeof(length)); + istr.read((char*)&count, sizeof(count)); + + delete[] elements; + elements = new T[length]; + + for (int i = 0; i < count; i++) + elements[i].read(istr); // disgusting + + return istr; +} + +template +std::ostream& operator<<(std::ostream& ostr, const List& obj) { + ostr.write((const char*)&length, sizeof(length)); + ostr.write((const char*)&count, sizeof(count)); + + for (int i = 0; i < count; i++) + elements[i].write(ostr); // disgusting + + return ostr; +} + #endif -- cgit v1.3.1-26-gb76a