Skip to content

Commit

Permalink
Using algorithm instead of loops
Browse files Browse the repository at this point in the history
  • Loading branch information
kunaltyagi committed Jan 10, 2020
1 parent cca384e commit 8a7457c
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions io/src/ply/ply_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8a7457c

Please sign in to comment.