diff --git a/hw1/hw1/Data.h b/hw1/hw1/Data.h index 9b75e94ef1a149b9c181cfd57515324ae8c108fa..f2634e1df591726d49419f7a99b3e3a0bffc12ad 100644 --- a/hw1/hw1/Data.h +++ b/hw1/hw1/Data.h @@ -27,13 +27,15 @@ bool createData(const std::string& fileName) { template - //!!! ИСПРАВЛЕНО Передавать нужно тип контейнера, а не его шаблон. - //!!!ИСПРАВЛЕНО Тип хранимых данных можно определить с помощью value_type bool createDataGenerate(const std::string& fileName) { srand(time(nullptr)); - using type = container::value_type; + + using type = container::value_type; //!!! Где typename ? + std::ofstream fout(fileName, std::ios::out | std::ios::trunc); - container values(N); + + container values(N);//!!! container - это инстанцированный тип, а не шаблон. Откуда параметр type взялся? + if (!fout) { throw std::exception("Wrong (file name is not valid)!"); return false; @@ -44,12 +46,13 @@ bool createDataGenerate(const std::string& fileName) { return true; } -template //!!! ИСПРАВЛЕНО Передавать нужно тип контейнера, а не его шаблон. - //!!!ИСПРАВЛЕНО Тип хранимых данных можно определить с помощью value_type +template container& loadData (const std::string& file) { - using type = container::value_type; - container result; + using type = container::value_type; //!!! Где typename ? + + container result;//!!! container - это инстанцированный тип, а не шаблон. Откуда параметр type взялся? + std::ifstream fin(file); if (!fin.is_open()) @@ -65,10 +68,13 @@ template //!!! ИСПРАВЛЕНО Переда return result; }; + template container& loadDataIterator(const std::string& fileName) { - using type = container::value_type; - container result(N); + using type = container::value_type; //!!! Где typename ? + + container result(N); //!!! container - это инстанцированный тип, а не шаблон. Откуда параметр type взялся? + std::ifstream fin(fileName); if (fin) { std::copy(std::istream_iterator(fin), std::istream_iterator(), result.begin()); @@ -80,7 +86,9 @@ bool Modify1(container &cont) { if (cont.size() == 0) { return false; } - using type = container::value_type; + + using type = container::value_type; //!!! Где typename ? + type firstUneven = type(); type sum = type(); for (const auto& i : cont) { @@ -106,7 +114,9 @@ bool Modify2(typename container::iterator beg, typename container::iterator end if (end == beg) { return false; } - using type = container::value_type; + + using type = container::value_type; //!!! Где typename ? + type firstUneven = type(); type sum = type(); for (const auto& iter = beg; iter != end; ++iter) { @@ -128,7 +138,8 @@ bool Modify3(container & cont) { if (cont.end() == cont.begin()) { return false; } - using type = container::value_type; + using type = container::value_type; //!!! Где typename ? + auto firstUneven = std::find_if(cont.begin(), cont.end(), [](type i) { return i % 2 != 0; }); if (!firstUneven) *firstUneven = type(); std::for_each(cont.begin(), cont.end(), [firstUneven](auto& obj) { obj += *firstUneven; }); @@ -138,7 +149,8 @@ bool Modify3(container & cont) { template bool Modify4(const std::string& fileName) { - using type = container::value_type; + using type = container::value_type; //!!! Где typename ? + container buffer(N); std::ifstream fin(fileName); if (!fin) { @@ -175,7 +187,9 @@ bool outputResultCopy(const std::string& fileName, const container& cont) { throw std::exception("Wrong (file name is not valid)!"); return false; } - using type = container::value_type; + + using type = container::value_type; //!!! Где typename ? + std::copy(cont.begin(), cont.end(), std::ostream_iterator(fout, "\n")); fout.close(); return true;