From 3c06670e4080526ab739bb37957cde1f68c20540 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 7 May 2022 16:13:38 +0300 Subject: Autocommit at 07.05.2022 @ 16:13 --- src/Generic/List/List.hpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/Generic') diff --git a/src/Generic/List/List.hpp b/src/Generic/List/List.hpp index 7bbc835..4530083 100644 --- a/src/Generic/List/List.hpp +++ b/src/Generic/List/List.hpp @@ -37,12 +37,10 @@ public: List(List&& other); List& operator=(List&& other); -}; -template -std::istream& operator>>(std::istream& istr, List& obj); -template -std::ostream& operator<<(std::ostream& ostr, const List& obj); + friend std::istream& operator>>(std::istream& istr, List& obj); + friend std::ostream& operator<<(std::ostream& ostr, const List& obj); +}; /* Private */ @@ -199,29 +197,29 @@ List& List::operator=(List&& other) { return *this; } -/* Other */ +/* Friend functions */ template std::istream& operator>>(std::istream& istr, List& obj) { - istr.read((char*)&length, sizeof(length)); - istr.read((char*)&count, sizeof(count)); + istr.read((char*)&obj.length, sizeof(obj.length)); + istr.read((char*)&obj.count, sizeof(obj.count)); - delete[] elements; - elements = new T[length]; + delete[] obj.elements; + obj.elements = new T[obj.length]; - for (int i = 0; i < count; i++) - elements[i].read(istr); // disgusting + for (int i = 0; i < obj.count; i++) + istr >> obj.elements[i]; 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)); + ostr.write((const char*)&obj.length, sizeof(obj.length)); + ostr.write((const char*)&obj.count, sizeof(obj.count)); - for (int i = 0; i < count; i++) - elements[i].write(ostr); // disgusting + for (int i = 0; i < obj.count; i++) + ostr << obj.elements[i]; return ostr; } -- cgit v1.3.1-26-gb76a