Skip to content

Commit

Permalink
More raw for loops converted
Browse files Browse the repository at this point in the history
Some ternary operators removed from point_types.hpp
  • Loading branch information
kunaltyagi committed Sep 26, 2019
1 parent 2640388 commit c92ae79
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
9 changes: 4 additions & 5 deletions common/include/pcl/common/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@

#pragma once

#include <numeric>
#include <string>

#include <pcl/pcl_base.h>
#include <pcl/PointIndices.h>
#include <pcl/conversions.h>
Expand Down Expand Up @@ -114,11 +116,8 @@ namespace pcl
inline std::string
getFieldsList (const pcl::PCLPointCloud2 &cloud)
{
std::string result;
for (std::size_t i = 0; i < cloud.fields.size () - 1; ++i)
result += cloud.fields[i].name + " ";
result += cloud.fields[cloud.fields.size () - 1].name;
return (result);
return std::accumulate(std::next (cloud.fields.begin ()), cloud.fields.end (), cloud.fields[0].name,
[](const auto& acc, const auto& field) { return acc + " " + field.name; });
}

/** \brief Obtains the size of a specific field data type in bytes
Expand Down
23 changes: 16 additions & 7 deletions common/include/pcl/impl/point_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@
# pragma GCC system_header
#endif

#include <Eigen/Core>
#include <algorithm>
#include <ostream>

#include <Eigen/Core>

#include <pcl/pcl_macros.h>

// Define all PCL point types
Expand Down Expand Up @@ -1346,14 +1349,14 @@ namespace pcl
{
inline ReferenceFrame (const _ReferenceFrame &p)
{
for (int d = 0; d < 9; ++d)
rf[d] = p.rf[d];
std::copy_n(p.rf, 9, rf);
}

inline ReferenceFrame ()
{
for (int d = 0; d < 3; ++d)
x_axis[d] = y_axis[d] = z_axis[d] = 0;
std::fill_n(x_axis, 3, 0);
std::fill_n(y_axis, 3, 0);
std::fill_n(z_axis, 3, 0);
}

friend std::ostream& operator << (std::ostream& os, const ReferenceFrame& p);
Expand Down Expand Up @@ -1685,8 +1688,14 @@ namespace pcl
template <int N> std::ostream&
operator << (std::ostream& os, const Histogram<N>& p)
{
for (int i = 0; i < N; ++i)
os << (i == 0 ? "(" : "") << p.histogram[i] << (i < N-1 ? ", " : ")");
// make constexpr
if (N > 0)
{
os << "(" << p.histogram[0];
std::for_each(p.histogram + 1, std::end(p.histogram),
[&os](const auto& hist) { os << ", " << hist; });
os << ")";
}
return (os);
}
} // End namespace
Expand Down

0 comments on commit c92ae79

Please sign in to comment.