From a44e53ee6affdf652bc7eff03877fc8e7f3243b6 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Thu, 15 Feb 2024 00:30:40 +0100 Subject: [PATCH] small refactor remove unnecessary curly braces and the clearing of vector --- src/fs_reader.cpp | 18 ++++++------------ src/main.cpp | 6 ++---- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/fs_reader.cpp b/src/fs_reader.cpp index e00826a..d880c1a 100644 --- a/src/fs_reader.cpp +++ b/src/fs_reader.cpp @@ -10,12 +10,9 @@ std::vector find_all_files(fs::path path) { std::vector files = {}; - for (const fs::directory_entry & entry : fs::directory_iterator(path)) { - if (entry.is_directory()) { - continue; - } - files.insert(files.begin()+files.size(), entry.path()); - } + for (const fs::directory_entry & entry : fs::directory_iterator(path)) + if (!entry.is_directory()) + files.insert(files.begin()+files.size(), entry.path()); files.shrink_to_fit(); return files; @@ -24,11 +21,9 @@ std::vector find_all_files(fs::path path) { std::vector find_all_folders(fs::path path) { std::vector folders = {}; - for (const fs::directory_entry & entry : fs::directory_iterator(path)) { - if (entry.is_directory()) { + for (const fs::directory_entry & entry : fs::directory_iterator(path)) + if (entry.is_directory()) folders.insert(folders.begin()+folders.size(), entry.path()); - } - } folders.shrink_to_fit(); return folders; @@ -37,9 +32,8 @@ std::vector find_all_folders(fs::path path) { std::vector find_all_files_and_folders(fs::path path) { std::vector files_and_folders = {}; - for (const fs::directory_entry &entry : fs::directory_iterator(path)) { + for (const fs::directory_entry &entry : fs::directory_iterator(path)) files_and_folders.insert(files_and_folders.begin()+files_and_folders.size(), entry.path()); - } files_and_folders.shrink_to_fit(); return files_and_folders; diff --git a/src/main.cpp b/src/main.cpp index 6172bd1..c1a9cba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,10 +20,8 @@ int main(int argc, char *argv[]) { std::vector files_and_folders = find_all_files_and_folders(argv[1]); - for (size_t index = 0; index < files_and_folders.size(); index++) { - std::cout << "index " + std::to_string(index) + ": " + files_and_folders.at(index).string() << std::endl; - } + for (size_t index = 0; index < files_and_folders.size(); index++) + std::cout << "index " << index << ": " << files_and_folders.at(index) << std::endl; - files_and_folders.clear(); return 0; } \ No newline at end of file