small refactor

remove unnecessary curly braces and the clearing of vector
This commit is contained in:
AustrianToast 2024-02-15 00:30:40 +01:00
parent c292632545
commit a44e53ee6a
No known key found for this signature in database
GPG Key ID: 5CD422268E489EB4
2 changed files with 8 additions and 16 deletions

View File

@ -10,12 +10,9 @@
std::vector<fs::path> find_all_files(fs::path path) { std::vector<fs::path> find_all_files(fs::path path) {
std::vector<fs::path> files = {}; std::vector<fs::path> files = {};
for (const fs::directory_entry & entry : fs::directory_iterator(path)) { for (const fs::directory_entry & entry : fs::directory_iterator(path))
if (entry.is_directory()) { if (!entry.is_directory())
continue; files.insert(files.begin()+files.size(), entry.path());
}
files.insert(files.begin()+files.size(), entry.path());
}
files.shrink_to_fit(); files.shrink_to_fit();
return files; return files;
@ -24,11 +21,9 @@ std::vector<fs::path> find_all_files(fs::path path) {
std::vector<fs::path> find_all_folders(fs::path path) { std::vector<fs::path> find_all_folders(fs::path path) {
std::vector<fs::path> folders = {}; std::vector<fs::path> folders = {};
for (const fs::directory_entry & entry : fs::directory_iterator(path)) { for (const fs::directory_entry & entry : fs::directory_iterator(path))
if (entry.is_directory()) { if (entry.is_directory())
folders.insert(folders.begin()+folders.size(), entry.path()); folders.insert(folders.begin()+folders.size(), entry.path());
}
}
folders.shrink_to_fit(); folders.shrink_to_fit();
return folders; return folders;
@ -37,9 +32,8 @@ std::vector<fs::path> find_all_folders(fs::path path) {
std::vector<fs::path> find_all_files_and_folders(fs::path path) { std::vector<fs::path> find_all_files_and_folders(fs::path path) {
std::vector<fs::path> files_and_folders = {}; std::vector<fs::path> 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.insert(files_and_folders.begin()+files_and_folders.size(), entry.path());
}
files_and_folders.shrink_to_fit(); files_and_folders.shrink_to_fit();
return files_and_folders; return files_and_folders;

View File

@ -20,10 +20,8 @@ int main(int argc, char *argv[]) {
std::vector<fs::path> files_and_folders = find_all_files_and_folders(argv[1]); std::vector<fs::path> files_and_folders = find_all_files_and_folders(argv[1]);
for (size_t index = 0; index < files_and_folders.size(); index++) { 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; std::cout << "index " << index << ": " << files_and_folders.at(index) << std::endl;
}
files_and_folders.clear();
return 0; return 0;
} }