summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorROUVREAU Vincent <vincent.rouvreau@inria.fr>2020-09-30 09:18:36 +0200
committerROUVREAU Vincent <vincent.rouvreau@inria.fr>2020-09-30 09:18:36 +0200
commitc1b317640f81fefff7f7a774b239957fb632fa43 (patch)
tree697fbce8e859903d52b8f1067556340d5f35ca42
parentdab93ead76f1435f6b74937ef0377aafb0517439 (diff)
code review: emplace_back versus push_back
-rw-r--r--src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp10
-rw-r--r--src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp10
-rw-r--r--src/Alpha_complex/include/gudhi/Alpha_complex.h6
-rw-r--r--src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp20
-rw-r--r--src/Alpha_complex/utilities/alpha_complex_persistence.cpp2
5 files changed, 24 insertions, 24 deletions
diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp
index a8d00272..09431d6e 100644
--- a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp
+++ b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp
@@ -18,11 +18,11 @@ int main(int argc, char **argv) {
// Init of a list of points and weights from a small molecule
// ----------------------------------------------------------------------------
std::vector<Weighted_point> weighted_points;
- weighted_points.push_back(Weighted_point(Bare_point(1, -1, -1), 4.));
- weighted_points.push_back(Weighted_point(Bare_point(-1, 1, -1), 4.));
- weighted_points.push_back(Weighted_point(Bare_point(-1, -1, 1), 4.));
- weighted_points.push_back(Weighted_point(Bare_point(1, 1, 1), 4.));
- weighted_points.push_back(Weighted_point(Bare_point(2, 2, 2), 1.));
+ weighted_points.emplace_back(Bare_point(1, -1, -1), 4.);
+ weighted_points.emplace_back(Bare_point(-1, 1, -1), 4.);
+ weighted_points.emplace_back(Bare_point(-1, -1, 1), 4.);
+ weighted_points.emplace_back(Bare_point(1, 1, 1), 4.);
+ weighted_points.emplace_back(Bare_point(2, 2, 2), 1.);
// ----------------------------------------------------------------------------
// Init of an alpha complex from the list of points
diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp
index d49d3e93..d1f3e436 100644
--- a/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp
+++ b/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp
@@ -18,11 +18,11 @@ int main() {
// Init of a list of points and weights from a small molecule
// ----------------------------------------------------------------------------
Vector_of_points points;
- points.push_back(Weighted_point(Bare_point(1, -1, -1), 4.));
- points.push_back(Weighted_point(Bare_point(-1, 1, -1), 4.));
- points.push_back(Weighted_point(Bare_point(-1, -1, 1), 4.));
- points.push_back(Weighted_point(Bare_point(1, 1, 1), 4.));
- points.push_back(Weighted_point(Bare_point(2, 2, 2), 1.));
+ points.emplace_back(Bare_point(1, -1, -1), 4.);
+ points.emplace_back(Bare_point(-1, 1, -1), 4.);
+ points.emplace_back(Bare_point(-1, -1, 1), 4.);
+ points.emplace_back(Bare_point(1, 1, 1), 4.);
+ points.emplace_back(Bare_point(2, 2, 2), 1.);
// ----------------------------------------------------------------------------
// Init of an alpha complex from the list of points
diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h
index a692dbc6..4f8e3d54 100644
--- a/src/Alpha_complex/include/gudhi/Alpha_complex.h
+++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h
@@ -310,7 +310,7 @@ class Alpha_complex {
thread_local std::vector<Point_d> v;
v.clear();
for (auto vertex : cplx.simplex_vertex_range(s))
- v.push_back(get_point_(vertex));
+ v.emplace_back(get_point_(vertex));
cache_.emplace_back(kernel_.get_sphere(v.cbegin(), v.cend()));
}
return cache_[k];
@@ -326,7 +326,7 @@ class Alpha_complex {
thread_local std::vector<Point_d> v;
v.clear();
for (auto vertex : cplx.simplex_vertex_range(s))
- v.push_back(get_point_(vertex));
+ v.emplace_back(get_point_(vertex));
return kernel_.get_squared_radius(v.cbegin(), v.cend());
}
@@ -394,7 +394,7 @@ class Alpha_complex {
std::clog << " " << (*vit)->data();
#endif // DEBUG_TRACES
// Vector of vertex construction for simplex_tree structure
- vertexVector.push_back((*vit)->data());
+ vertexVector.emplace_back((*vit)->data());
}
}
#ifdef DEBUG_TRACES
diff --git a/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp b/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp
index 192834b3..6eae103d 100644
--- a/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp
+++ b/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp
@@ -63,11 +63,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_kernel_d_sphere, TestedKernel, list_of_kerne
using Point_d = typename Unweighted_kernel::Point_d;
std::vector<Point_d> unw_pts;
- unw_pts.push_back(Point_d(p0.begin(), p0.end()));
- unw_pts.push_back(Point_d(p1.begin(), p1.end()));
- unw_pts.push_back(Point_d(p2.begin(), p2.end()));
- unw_pts.push_back(Point_d(p3.begin(), p3.end()));
- unw_pts.push_back(Point_d(p4.begin(), p4.end()));
+ unw_pts.emplace_back(p0.begin(), p0.end());
+ unw_pts.emplace_back(p1.begin(), p1.end());
+ unw_pts.emplace_back(p2.begin(), p2.end());
+ unw_pts.emplace_back(p3.begin(), p3.end());
+ unw_pts.emplace_back(p4.begin(), p4.end());
Unweighted_kernel kernel;
auto unw_sphere = kernel.get_sphere(unw_pts.cbegin(), unw_pts.cend());
@@ -79,11 +79,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_kernel_d_sphere, TestedKernel, list_of_kerne
using Weighted_point_d = typename Weighted_kernel::Weighted_point_d;
using Bare_point_d = typename Weighted_kernel::Bare_point_d;
std::vector<Weighted_point_d> w_pts;
- w_pts.push_back(Weighted_point_d(Bare_point_d(p0.begin(), p0.end()), 0.));
- w_pts.push_back(Weighted_point_d(Bare_point_d(p1.begin(), p1.end()), 0.));
- w_pts.push_back(Weighted_point_d(Bare_point_d(p2.begin(), p2.end()), 0.));
- w_pts.push_back(Weighted_point_d(Bare_point_d(p3.begin(), p3.end()), 0.));
- w_pts.push_back(Weighted_point_d(Bare_point_d(p4.begin(), p4.end()), 0.));
+ w_pts.emplace_back(Bare_point_d(p0.begin(), p0.end()), 0.);
+ w_pts.emplace_back(Bare_point_d(p1.begin(), p1.end()), 0.);
+ w_pts.emplace_back(Bare_point_d(p2.begin(), p2.end()), 0.);
+ w_pts.emplace_back(Bare_point_d(p3.begin(), p3.end()), 0.);
+ w_pts.emplace_back(Bare_point_d(p4.begin(), p4.end()), 0.);
Weighted_kernel w_kernel;
auto w_sphere = w_kernel.get_sphere(w_pts.cbegin(), w_pts.cend());
diff --git a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp
index e86b34e2..3ce7b440 100644
--- a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp
+++ b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp
@@ -50,7 +50,7 @@ std::vector<double> read_weight_file(const std::string &weight_file) {
double weight = 0.0;
// Attempt read the weight in a double format, return false if it fails
while (weights_ifstr >> weight) {
- weights.push_back(weight);
+ weights.emplace_back(weight);
}
} else {
std::cerr << "Unable to read weights file " << weight_file << std::endl;