From 3e9d361f8969b89fce0eca7d377452b11a19584c Mon Sep 17 00:00:00 2001 From: Davis King Date: Tue, 20 Nov 2018 15:36:07 -0500 Subject: [PATCH] Minor changes to avoid bugs in some compilers. --- tools/python/src/decision_functions.cpp | 2 +- tools/python/src/face_recognition.cpp | 10 +++++----- tools/python/src/global_optimization.cpp | 14 +++++++------- tools/python/src/gui.cpp | 2 +- tools/python/src/image2.cpp | 4 ++-- tools/python/src/image4.cpp | 2 +- tools/python/src/image_dataset_metadata.cpp | 8 ++++---- tools/python/src/numpy_returns.cpp | 4 ++-- tools/python/src/shape_predictor.cpp | 2 +- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tools/python/src/decision_functions.cpp b/tools/python/src/decision_functions.cpp index b14cf1b61..341c68cc0 100644 --- a/tools/python/src/decision_functions.cpp +++ b/tools/python/src/decision_functions.cpp @@ -122,7 +122,7 @@ std::vector normalized_predict_vec ( { std::vector out; out.reserve(samps.size()); - for (auto& x : samps) + for (const auto& x : samps) out.push_back(normalized_predict(df,x)); return out; } diff --git a/tools/python/src/face_recognition.cpp b/tools/python/src/face_recognition.cpp index 977915a41..de8bfe945 100644 --- a/tools/python/src/face_recognition.cpp +++ b/tools/python/src/face_recognition.cpp @@ -64,10 +64,10 @@ public: throw dlib::error("The array of images and the array of array of locations must be of the same size"); int total_chips = 0; - for (auto& faces : batch_faces) + for (const auto& faces : batch_faces) { total_chips += faces.size(); - for (auto& f : faces) + for (const auto& f : faces) { if (f.num_parts() != 68 && f.num_parts() != 5) throw dlib::error("The full_object_detection must use the iBUG 300W 68 point face landmark style or dlib's 5 point style."); @@ -82,7 +82,7 @@ public: auto& img = batch_imgs[i]; std::vector dets; - for (auto& f : faces) + for (const auto& f : faces) dets.push_back(get_face_chip_details(f, 150, 0.25)); dlib::array> this_img_face_chips; extract_image_chips(img, dets, this_img_face_chips); @@ -214,12 +214,12 @@ void save_face_chips ( int num_faces = faces.size(); std::vector dets; - for (auto& f : faces) + for (const auto& f : faces) dets.push_back(get_face_chip_details(f, size, padding)); dlib::array> face_chips; extract_image_chips(numpy_image(img), dets, face_chips); int i=0; - for (auto& chip : face_chips) + for (const auto& chip : face_chips) { i++; if(num_faces > 1) diff --git a/tools/python/src/global_optimization.cpp b/tools/python/src/global_optimization.cpp index 53b8cfd05..9dad21c80 100644 --- a/tools/python/src/global_optimization.cpp +++ b/tools/python/src/global_optimization.cpp @@ -203,7 +203,7 @@ std::shared_ptr py_global_function_search1 ( ) { std::vector tmp; - for (auto i : functions) + for (const auto& i : functions) tmp.emplace_back(i.cast()); return std::make_shared(tmp); @@ -216,14 +216,14 @@ std::shared_ptr py_global_function_search2 ( ) { std::vector specs; - for (auto i : functions) + for (const auto& i : functions) specs.emplace_back(i.cast()); std::vector> func_evals; - for (auto i : initial_function_evals) + for (const auto& i : initial_function_evals) { std::vector evals; - for (auto j : i) + for (const auto& j : i) { evals.emplace_back(j.cast()); } @@ -410,12 +410,12 @@ simply a struct that records x and the scalar value F(x). )RAW") std::vector> function_evals; self.get_function_evaluations(specs,function_evals); py::list py_specs, py_func_evals; - for (auto& s : specs) + for (const auto& s : specs) py_specs.append(s); - for (auto& i : function_evals) + for (const auto& i : function_evals) { py::list tmp; - for (auto& j : i) + for (const auto& j : i) tmp.append(j); py_func_evals.append(tmp); } diff --git a/tools/python/src/gui.cpp b/tools/python/src/gui.cpp index e03bee5bc..99ebe84a0 100644 --- a/tools/python/src/gui.cpp +++ b/tools/python/src/gui.cpp @@ -97,7 +97,7 @@ void add_overlay_pylist ( ) { std::vector rects; - for (auto& obj : objs) + for (const auto& obj : objs) { try { rects.push_back(obj.cast()); continue; } catch(py::cast_error&) { } try { rects.push_back(obj.cast()); continue; } catch(py::cast_error&) { } diff --git a/tools/python/src/image2.cpp b/tools/python/src/image2.cpp index 22c366d05..0fd70c47d 100644 --- a/tools/python/src/image2.cpp +++ b/tools/python/src/image2.cpp @@ -65,7 +65,7 @@ std::vector py_remove_incoherent_edge_pixels ( DLIB_CASSERT(num_rows(horz_gradient) == num_rows(vert_gradient)); DLIB_CASSERT(num_columns(horz_gradient) == num_columns(vert_gradient)); DLIB_CASSERT(angle_threshold >= 0); - for (auto& p : line) + for (const auto& p : line) DLIB_CASSERT(get_rect(horz_gradient).contains(p), "All line points must be inside the given images."); return remove_incoherent_edge_pixels(line, horz_gradient, vert_gradient, angle_threshold); @@ -152,7 +152,7 @@ py::list py_extract_image_chips ( dlib::array> out; extract_image_chips(img, python_list_to_vector(chip_locations), out); py::list ret; - for (auto& i : out) + for (const auto& i : out) ret.append(i); return ret; } diff --git a/tools/python/src/image4.cpp b/tools/python/src/image4.cpp index f91030982..65d29c535 100644 --- a/tools/python/src/image4.cpp +++ b/tools/python/src/image4.cpp @@ -511,7 +511,7 @@ py::list py_extract_image_chips ( dlib::array> out; extract_image_chips(img, python_list_to_vector(chip_locations), out); py::list ret; - for (auto& i : out) + for (const auto& i : out) ret.append(i); return ret; } diff --git a/tools/python/src/image_dataset_metadata.cpp b/tools/python/src/image_dataset_metadata.cpp index 1c64c4d49..040801185 100644 --- a/tools/python/src/image_dataset_metadata.cpp +++ b/tools/python/src/image_dataset_metadata.cpp @@ -97,7 +97,7 @@ dataset py_load_image_dataset_metadata( std::shared_ptr> map_from_object(py::dict obj) { auto ret = std::make_shared>(); - for (auto& v : obj) + for (const auto& v : obj) { (*ret)[v.first.cast()] = v.second.cast(); } @@ -121,7 +121,7 @@ image_dataset_metadata::dataset py_make_bounding_box_regression_training_data ( // otherwise, detections should be a list of std::vectors. py::list dets(detections); std::vector> temp; - for (auto& d : dets) + for (const auto& d : dets) temp.emplace_back(d.cast&>()); return make_bounding_box_regression_training_data(truth, temp); } @@ -174,7 +174,7 @@ void bind_image_dataset_metadata(py::module &m_) auto partsstr = [](const std::map& item) { std::ostringstream sout; sout << "{"; - for (auto& v : item) + for (const auto& v : item) sout << "'" << v.first << "': " << v.second << ", "; sout << "}"; return sout.str(); @@ -182,7 +182,7 @@ void bind_image_dataset_metadata(py::module &m_) auto partsrepr = [](const std::map& item) { std::ostringstream sout; sout << "dlib.image_dataset_metadata.parts({\n"; - for (auto& v : item) + for (const auto& v : item) sout << "'" << v.first << "': dlib.point" << v.second << ",\n"; sout << "})"; return sout.str(); diff --git a/tools/python/src/numpy_returns.cpp b/tools/python/src/numpy_returns.cpp index 768602cac..776131fd7 100644 --- a/tools/python/src/numpy_returns.cpp +++ b/tools/python/src/numpy_returns.cpp @@ -97,12 +97,12 @@ py::list get_face_chips ( py::list chips_list; std::vector dets; - for (auto& f : faces) + for (const auto& f : faces) dets.push_back(get_face_chip_details(f, size, padding)); dlib::array> face_chips; extract_image_chips(img, dets, face_chips); - for (auto& chip : face_chips) + for (const auto& chip : face_chips) { // Append image to chips list chips_list.append(chip); diff --git a/tools/python/src/shape_predictor.cpp b/tools/python/src/shape_predictor.cpp index 3e8a1820b..5c2920ee9 100644 --- a/tools/python/src/shape_predictor.cpp +++ b/tools/python/src/shape_predictor.cpp @@ -72,7 +72,7 @@ std::shared_ptr full_obj_det_init(const rectangle& rect, { const unsigned long num_parts = py::len(pyparts); std::vector parts; - for (auto& item : pyparts) + for (const auto& item : pyparts) parts.push_back(item.cast()); return std::make_shared(rect, parts);