#pragma once #include "io.hpp" #include "errors/io.hpp" #include template requires Container && HasPushBack && std::same_as auto read_file_lines(const std::filesystem::path &path) -> ContainerType { if (!std::filesystem::exists(path)) { throw NoSuchFileOrDirectoryError(path); } const auto file_status = std::filesystem::status(path); const auto file_type = file_status.type(); if (file_type != std::filesystem::file_type::regular) { throw WrongFileTypeError(path, std::filesystem::file_type::regular, file_type); } auto file = std::ifstream(); file.open(path); if (!file.is_open()) { throw FileNotOpenError(path); } auto content_lines = ContainerType(); while (file) { auto line = std::string(); std::getline(file, line); std::erase(line, '\r'); content_lines.push_back(line); } if (!content_lines.empty() && content_lines.back().empty()) { content_lines.pop_back(); } return content_lines; }