From 3e6a6dbdc00c2153bf3f256ce1c87466b88ec921 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 2 May 2022 08:10:15 +0300 Subject: Autocommit at 02.05.2022 @ 08:10 --- src/List/List.cpp | 18 ++++++++++++++++++ src/List/List.h | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/List/List.cpp b/src/List/List.cpp index bdb9b4a..a0d0849 100644 --- a/src/List/List.cpp +++ b/src/List/List.cpp @@ -61,6 +61,24 @@ const T& List::operator[](unsigned index) const { return elements[index]; } +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++) + istr >> elements[i]; + + return istr; +} + +template +std::ostream& List::write(std::ostream& ostr) const { + return ostr; +} + template unsigned List::get_length() const { return length; diff --git a/src/List/List.h b/src/List/List.h index 0e7722c..377cbf0 100644 --- a/src/List/List.h +++ b/src/List/List.h @@ -21,8 +21,8 @@ public: T& operator[](unsigned index); const T& operator[](unsigned index) const; - std::istream read(std::istream& istr); - std::ostream write(std::istream& ostr); + std::istream& read(std::istream& istr); + std::ostream& write(std::ostream& ostr) const; unsigned get_length() const; unsigned get_count() const; -- cgit v1.3.1-26-gb76a