From 8a7457cd33074e2ad49f8783e82f23c79f940c17 Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Sat, 11 Jan 2020 05:54:10 +0900 Subject: [PATCH] Using algorithm instead of loops --- io/src/ply/ply_parser.cpp | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/io/src/ply/ply_parser.cpp b/io/src/ply/ply_parser.cpp index 505cc0cfa0b..90893da37a7 100644 --- a/io/src/ply/ply_parser.cpp +++ b/io/src/ply/ply_parser.cpp @@ -163,14 +163,9 @@ bool pcl::io::ply::ply_parser::parse (const std::string& filename) error_callback_ (line_number_, "parse error: invalid element statement"); return false; } - auto iterator = elements.cbegin (); - while (iterator != elements.cend ()) - { - if ((*iterator)->name == name) - break; - ++iterator; - } - if (iterator != elements.end ()) + const auto iterator = std::find_if (elements.cbegin (), elements.cend (), + [&name](const auto& ptr) { return ptr->name == name;}); + if (iterator != elements.cend ()) { error_callback_ (line_number_, "parse error: invalid elements"); return false; @@ -208,14 +203,11 @@ bool pcl::io::ply::ply_parser::parse (const std::string& filename) error_callback_ (line_number_, "parse error: invalid variable property statement"); return false; } - auto iterator = current_element_->properties.cbegin (); - while (iterator != current_element_->properties.cend ()) - { - if ((*iterator)->name == name) - break; - ++iterator; - } - if (iterator != current_element_->properties.end ()) + const auto iterator = + std::find_if (current_element_->properties.cbegin (), + current_element_->properties.cend (), + [&name](const auto& ptr) { return ptr->name == name;}); + if (iterator != current_element_->properties.cend ()) { error_callback_ (line_number_, "parse error: duplicate property found"); return false; @@ -273,14 +265,11 @@ bool pcl::io::ply::ply_parser::parse (const std::string& filename) error_callback_ (line_number_, "parse error: invalid list statement"); return false; } - auto iterator = current_element_->properties.cbegin (); - while (iterator != current_element_->properties.cend ()) - { - if ((*iterator)->name == name) - break; - ++iterator; - } - if (iterator != current_element_->properties.end ()) + const auto iterator = + std::find_if (current_element_->properties.cbegin (), + current_element_->properties.cend (), + [&name](const auto& ptr) { return ptr->name == name;}); + if (iterator != current_element_->properties.cend ()) { error_callback_ (line_number_, "parse error: duplicate property found"); return false;