From 05ba684e4d418fb323fa75400197cc4c90e7a301 Mon Sep 17 00:00:00 2001 From: Steven Hahn <hahnse@ornl.gov> Date: Fri, 15 Jan 2016 16:21:09 -0500 Subject: [PATCH] Refs #14988. Ran modernize-loop-convert on Geometry, ICat and Kernel. --- .../src/Crystal/CompositeBraggScatterer.cpp | 44 +++-- .../Geometry/src/Crystal/CrystalStructure.cpp | 7 +- Framework/Geometry/src/Crystal/Group.cpp | 21 ++- .../Geometry/src/Crystal/IndexingUtils.cpp | 153 +++++++++--------- .../src/Crystal/PeakTransformSelector.cpp | 8 +- Framework/Geometry/src/Crystal/PointGroup.cpp | 17 +- .../src/Crystal/PointGroupFactory.cpp | 10 +- .../src/Crystal/ProductOfCyclicGroups.cpp | 6 +- .../Geometry/src/Crystal/ScalarUtils.cpp | 44 ++--- Framework/Geometry/src/Crystal/SpaceGroup.cpp | 15 +- .../src/Crystal/SpaceGroupFactory.cpp | 14 +- .../StructureFactorCalculatorSummation.cpp | 4 +- .../src/Crystal/SymmetryElementFactory.cpp | 7 +- .../src/Crystal/SymmetryOperationFactory.cpp | 8 +- .../Crystal/SymmetryOperationSymbolParser.cpp | 6 +- Framework/Geometry/src/Instrument.cpp | 45 +++--- .../Geometry/src/Instrument/CompAssembly.cpp | 10 +- .../Geometry/src/Instrument/Component.cpp | 4 +- .../Geometry/src/Instrument/DetectorGroup.cpp | 4 +- .../Instrument/InstrumentDefinitionParser.cpp | 40 +++-- .../src/Instrument/ObjCompAssembly.cpp | 4 +- .../Geometry/src/Instrument/ParameterMap.cpp | 13 +- .../MDGeometry/CompositeImplicitFunction.cpp | 4 +- .../src/MDGeometry/MDGeometryXMLBuilder.cpp | 4 +- Framework/Geometry/src/Math/Acomp.cpp | 14 +- Framework/Geometry/src/Objects/Object.cpp | 18 +-- .../src/Rendering/GluGeometryRenderer.cpp | 7 +- Framework/ICat/src/CatalogLogout.cpp | 9 +- Framework/ICat/src/ICat3/ICat3Helper.cpp | 8 +- Framework/ICat/src/ICat4/ICat4Catalog.cpp | 16 +- Framework/Kernel/src/Atom.cpp | 8 +- Framework/Kernel/src/CompositeValidator.cpp | 16 +- Framework/Kernel/src/ConfigService.cpp | 22 +-- Framework/Kernel/src/DateAndTime.cpp | 4 +- Framework/Kernel/src/DeltaEMode.cpp | 12 +- Framework/Kernel/src/FacilityInfo.cpp | 27 ++-- Framework/Kernel/src/FileValidator.cpp | 15 +- Framework/Kernel/src/FilterChannel.cpp | 4 +- Framework/Kernel/src/IPropertyManager.cpp | 6 +- Framework/Kernel/src/InternetHelper.cpp | 5 +- Framework/Kernel/src/LibraryManager.cpp | 4 +- Framework/Kernel/src/MDAxisValidator.cpp | 4 +- Framework/Kernel/src/MultiFileNameParser.cpp | 26 ++- Framework/Kernel/src/MultiFileValidator.cpp | 11 +- Framework/Kernel/src/NetworkProxyOSX.cpp | 6 +- Framework/Kernel/src/NexusDescriptor.cpp | 4 +- Framework/Kernel/src/OptionalBool.cpp | 4 +- Framework/Kernel/src/PropertyManager.cpp | 21 ++- Framework/Kernel/src/StartsWithValidator.cpp | 4 +- Framework/Kernel/src/Strings.cpp | 24 +-- Framework/Kernel/src/ThreadPool.cpp | 26 +-- Framework/Kernel/src/TimeSeriesProperty.cpp | 15 +- Framework/Kernel/src/VMD.cpp | 4 +- Framework/Kernel/src/VectorHelper.cpp | 6 +- 54 files changed, 406 insertions(+), 436 deletions(-) diff --git a/Framework/Geometry/src/Crystal/CompositeBraggScatterer.cpp b/Framework/Geometry/src/Crystal/CompositeBraggScatterer.cpp index 0e8c9c5c80d..ff84f31cdbc 100644 --- a/Framework/Geometry/src/Crystal/CompositeBraggScatterer.cpp +++ b/Framework/Geometry/src/Crystal/CompositeBraggScatterer.cpp @@ -59,8 +59,8 @@ void CompositeBraggScatterer::setScatterers( const std::vector<BraggScatterer_sptr> &scatterers) { removeAllScatterers(); - for (auto it = scatterers.begin(); it != scatterers.end(); ++it) { - addScattererImplementation(*it); + for (const auto &scatterer : scatterers) { + addScattererImplementation(scatterer); } redeclareProperties(); @@ -112,8 +112,8 @@ StructureFactor CompositeBraggScatterer::calculateStructureFactor( const Kernel::V3D &hkl) const { StructureFactor sum(0.0, 0.0); - for (auto it = m_scatterers.begin(); it != m_scatterers.end(); ++it) { - sum += (*it)->calculateStructureFactor(hkl); + for (const auto &m_scatterer : m_scatterers) { + sum += m_scatterer->calculateStructureFactor(hkl); } return sum; @@ -132,8 +132,8 @@ void CompositeBraggScatterer::propagateProperty( const std::string &propertyName) { std::string propertyValue = getPropertyValue(propertyName); - for (auto it = m_scatterers.begin(); it != m_scatterers.end(); ++it) { - propagatePropertyToScatterer(*it, propertyName, propertyValue); + for (auto &m_scatterer : m_scatterers) { + propagatePropertyToScatterer(m_scatterer, propertyName, propertyValue); } } @@ -169,35 +169,34 @@ void CompositeBraggScatterer::addScattererImplementation( void CompositeBraggScatterer::redeclareProperties() { std::map<std::string, size_t> propertyUseCount = getPropertyCountMap(); - for (auto it = m_scatterers.begin(); it != m_scatterers.end(); ++it) { + for (auto &m_scatterer : m_scatterers) { // Check if any of the declared properties is in this scatterer (and set // value if that's the case) - for (auto prop = propertyUseCount.begin(); prop != propertyUseCount.end(); - ++prop) { - if ((*it)->existsProperty(prop->first)) { - prop->second += 1; + for (auto &prop : propertyUseCount) { + if (m_scatterer->existsProperty(prop.first)) { + prop.second += 1; - propagatePropertyToScatterer(*it, prop->first, - getPropertyValue(prop->first)); + propagatePropertyToScatterer(m_scatterer, prop.first, + getPropertyValue(prop.first)); } } // Use the properties of this scatterer which have been marked as exposed to // composite std::vector<Property *> properties = - (*it)->getPropertiesInGroup(getPropagatingGroupName()); - for (auto prop = properties.begin(); prop != properties.end(); ++prop) { - std::string propertyName = (*prop)->name(); + m_scatterer->getPropertiesInGroup(getPropagatingGroupName()); + for (auto &propertie : properties) { + std::string propertyName = propertie->name(); if (!existsProperty(propertyName)) { - declareProperty((*prop)->clone()); + declareProperty(propertie->clone()); } } } // Remove unused properties - for (auto it = propertyUseCount.begin(); it != propertyUseCount.end(); ++it) { - if (it->second == 0) { - removeProperty(it->first); + for (auto &it : propertyUseCount) { + if (it.second == 0) { + removeProperty(it.first); } } } @@ -208,9 +207,8 @@ CompositeBraggScatterer::getPropertyCountMap() const { std::map<std::string, size_t> propertyUseCount; std::vector<Property *> compositeProperties = getProperties(); - for (auto it = compositeProperties.begin(); it != compositeProperties.end(); - ++it) { - propertyUseCount.insert(std::make_pair((*it)->name(), 0)); + for (auto &compositePropertie : compositeProperties) { + propertyUseCount.insert(std::make_pair(compositePropertie->name(), 0)); } return propertyUseCount; diff --git a/Framework/Geometry/src/Crystal/CrystalStructure.cpp b/Framework/Geometry/src/Crystal/CrystalStructure.cpp index d40ffe8bf0a..0650074372e 100644 --- a/Framework/Geometry/src/Crystal/CrystalStructure.cpp +++ b/Framework/Geometry/src/Crystal/CrystalStructure.cpp @@ -130,10 +130,9 @@ void CrystalStructure::setReflectionConditionFromSpaceGroup( std::vector<ReflectionCondition_sptr> reflectionConditions = getAllReflectionConditions(); - for (auto it = reflectionConditions.begin(); it != reflectionConditions.end(); - ++it) { - if ((*it)->getSymbol() == centering) { - m_centering = *it; + for (auto &reflectionCondition : reflectionConditions) { + if (reflectionCondition->getSymbol() == centering) { + m_centering = reflectionCondition; break; } } diff --git a/Framework/Geometry/src/Crystal/Group.cpp b/Framework/Geometry/src/Crystal/Group.cpp index e82bc33fe48..80e7eee7d1f 100644 --- a/Framework/Geometry/src/Crystal/Group.cpp +++ b/Framework/Geometry/src/Crystal/Group.cpp @@ -71,11 +71,9 @@ Group Group::operator*(const Group &other) const { std::vector<SymmetryOperation> result; result.reserve(order() * other.order()); - for (auto selfOp = m_allOperations.begin(); selfOp != m_allOperations.end(); - ++selfOp) { - for (auto otherOp = other.m_allOperations.begin(); - otherOp != other.m_allOperations.end(); ++otherOp) { - result.push_back((*selfOp) * (*otherOp)); + for (const auto &m_allOperation : m_allOperations) { + for (const auto &otherOp : other.m_allOperations) { + result.push_back(m_allOperation * otherOp); } } @@ -87,8 +85,8 @@ Group Group::operator*(const Group &other) const { std::vector<Kernel::V3D> Group::operator*(const Kernel::V3D &vector) const { std::vector<Kernel::V3D> result; - for (auto op = m_allOperations.begin(); op != m_allOperations.end(); ++op) { - result.push_back(Geometry::getWrappedVector((*op) * vector)); + for (const auto &m_allOperation : m_allOperations) { + result.push_back(Geometry::getWrappedVector(m_allOperation * vector)); } std::sort(result.begin(), result.end(), FuzzyV3DLessThan()); @@ -159,9 +157,8 @@ void Group::setSymmetryOperations( /// systems have 4 non-zero elements in the matrix, orthogonal have 6. Group::CoordinateSystem Group::getCoordinateSystemFromOperations( const std::vector<SymmetryOperation> &symmetryOperations) const { - for (auto op = symmetryOperations.begin(); op != symmetryOperations.end(); - ++op) { - std::vector<int> matrix = (*op).matrix(); + for (const auto &symmetryOperation : symmetryOperations) { + std::vector<int> matrix = symmetryOperation.matrix(); if (std::count(matrix.begin(), matrix.end(), 0) == 5) { return Group::Hexagonal; } @@ -199,8 +196,8 @@ bool Group::hasIdentity() const { /// Returns true if the inverse of each element is in the group bool Group::eachElementHasInverse() const { // Iterate through all operations, check that the inverse is in the group. - for (auto op = m_allOperations.begin(); op != m_allOperations.end(); ++op) { - if (!containsOperation((*op).inverse())) { + for (const auto &m_allOperation : m_allOperations) { + if (!containsOperation(m_allOperation.inverse())) { return false; } } diff --git a/Framework/Geometry/src/Crystal/IndexingUtils.cpp b/Framework/Geometry/src/Crystal/IndexingUtils.cpp index 67199e052d9..2fbfda6efde 100644 --- a/Framework/Geometry/src/Crystal/IndexingUtils.cpp +++ b/Framework/Geometry/src/Crystal/IndexingUtils.cpp @@ -140,8 +140,8 @@ double IndexingUtils::Find_UB(DblMatrix &UB, const std::vector<V3D> &q_vectors, } } } else { - for (size_t i = 0; i < q_vectors.size(); i++) - sorted_qs.push_back(q_vectors[i]); + for (const auto &q_vector : q_vectors) + sorted_qs.push_back(q_vector); } std::sort(sorted_qs.begin(), sorted_qs.end(), V3D::CompareMagnitude); @@ -330,8 +330,8 @@ double IndexingUtils::Find_UB(DblMatrix &UB, const std::vector<V3D> &q_vectors, } } } else { - for (size_t i = 0; i < q_vectors.size(); i++) - sorted_qs.push_back(q_vectors[i]); + for (const auto &q_vector : q_vectors) + sorted_qs.push_back(q_vector); } std::sort(sorted_qs.begin(), sorted_qs.end(), V3D::CompareMagnitude); @@ -594,9 +594,9 @@ double IndexingUtils::Optimize_UB(DblMatrix &UB, DblMatrix HKLTHKL(3, 3); for (int r = 0; r < 3; r++) for (int c = 0; c < 3; c++) - for (size_t i = 0; i < hkl_vectors.size(); i++) { - HKLTHKL[r][c] += hkl_vectors[i][r] * - hkl_vectors[i][c]; // rounded??? to nearest integer + for (const auto &hkl_vector : hkl_vectors) { + HKLTHKL[r][c] += + hkl_vector[r] * hkl_vector[c]; // rounded??? to nearest integer } HKLTHKL.Invert(); @@ -940,22 +940,22 @@ double IndexingUtils::ScanFor_UB(DblMatrix &UB, std::vector<V3D> selected_b_dirs; std::vector<V3D> selected_c_dirs; - for (size_t a_dir_num = 0; a_dir_num < a_dir_list.size(); a_dir_num++) { - a_dir_temp = a_dir_list[a_dir_num]; + for (auto &a_dir_num : a_dir_list) { + a_dir_temp = a_dir_num; a_dir_temp = V3D(a_dir_temp); a_dir_temp *= a; b_dir_list = MakeCircleDirections(num_b_steps, a_dir_temp, gamma); - for (size_t b_dir_num = 0; b_dir_num < b_dir_list.size(); b_dir_num++) { - b_dir_temp = b_dir_list[b_dir_num]; + for (auto &b_dir_num : b_dir_list) { + b_dir_temp = b_dir_num; b_dir_temp = V3D(b_dir_temp); b_dir_temp *= b; c_dir_temp = Make_c_dir(a_dir_temp, b_dir_temp, c, alpha, beta, gamma); int num_indexed = 0; - for (size_t q_num = 0; q_num < q_vectors.size(); q_num++) { + for (const auto &q_vector : q_vectors) { bool indexes_peak = true; - q_vec = q_vectors[q_num] / (2.0 * M_PI); + q_vec = q_vector / (2.0 * M_PI); dot_prod = a_dir_temp.scalar_prod(q_vec); nearest_int = round(dot_prod); error = fabs(dot_prod - nearest_int); @@ -1003,8 +1003,8 @@ double IndexingUtils::ScanFor_UB(DblMatrix &UB, c_dir_temp = selected_c_dirs[dir_num]; double sum_sq_error = 0; - for (size_t q_num = 0; q_num < q_vectors.size(); q_num++) { - q_vec = q_vectors[q_num] / (2.0 * M_PI); + for (const auto &q_vector : q_vectors) { + q_vec = q_vector / (2.0 * M_PI); dot_prod = a_dir_temp.scalar_prod(q_vec); nearest_int = round(dot_prod); error = dot_prod - nearest_int; @@ -1086,16 +1086,14 @@ size_t IndexingUtils::ScanFor_Directions(std::vector<V3D> &directions, std::vector<V3D> selected_dirs; V3D dir_temp; - for (size_t dir_num = 0; dir_num < full_list.size(); dir_num++) { - V3D current_dir = full_list[dir_num]; - + for (auto current_dir : full_list) { for (int step = 0; step <= n_steps; step++) { dir_temp = current_dir; dir_temp *= (min_d + step * delta_d); // increasing size int num_indexed = 0; - for (size_t q_num = 0; q_num < q_vectors.size(); q_num++) { - q_vec = q_vectors[q_num] / (2.0 * M_PI); + for (const auto &q_vector : q_vectors) { + q_vec = q_vector / (2.0 * M_PI); dot_prod = dir_temp.scalar_prod(q_vec); nearest_int = round(dot_prod); error = fabs(dot_prod - nearest_int); @@ -1124,8 +1122,8 @@ size_t IndexingUtils::ScanFor_Directions(std::vector<V3D> &directions, directions.clear(); V3D current_dir; V3D diff; - for (size_t dir_num = 0; dir_num < selected_dirs.size(); dir_num++) { - current_dir = selected_dirs[dir_num]; + for (auto &selected_dir : selected_dirs) { + current_dir = selected_dir; GetIndexedPeaks_1D(current_dir, q_vectors, required_tolerance, index_vals, indexed_qs, fit_error); @@ -1136,8 +1134,8 @@ size_t IndexingUtils::ScanFor_Directions(std::vector<V3D> &directions, if (length >= min_d && length <= max_d) // only keep if within range { bool duplicate = false; - for (size_t i = 0; i < directions.size(); i++) { - dir_temp = directions[i]; + for (auto &direction : directions) { + dir_temp = direction; diff = current_dir - dir_temp; // discard same direction if (diff.norm() < 0.001) { @@ -1264,8 +1262,8 @@ size_t IndexingUtils::FFTScanFor_Directions(std::vector<V3D> &directions, V3D temp; std::vector<V3D> temp_dirs_2; - for (size_t i = 0; i < temp_dirs.size(); i++) { - GetMagFFT(q_vectors, temp_dirs[i], N_FFT_STEPS, projections, index_factor, + for (auto &temp_dir : temp_dirs) { + GetMagFFT(q_vectors, temp_dir, N_FFT_STEPS, projections, index_factor, magnitude_fft); double position = GetFirstMaxIndex(magnitude_fft, N_FFT_STEPS, threshold); @@ -1273,7 +1271,7 @@ size_t IndexingUtils::FFTScanFor_Directions(std::vector<V3D> &directions, double q_val = max_mag_Q / position; double d_val = 1 / q_val; if (d_val >= 0.8 * min_d && d_val <= 1.2 * max_d) { - temp = temp_dirs[i] * d_val; + temp = temp_dir * d_val; temp_dirs_2.push_back(temp); } } @@ -1283,8 +1281,8 @@ size_t IndexingUtils::FFTScanFor_Directions(std::vector<V3D> &directions, max_indexed = 0; int num_indexed; V3D current_dir; - for (size_t dir_num = 0; dir_num < temp_dirs_2.size(); dir_num++) { - current_dir = temp_dirs_2[dir_num]; + for (auto &dir_num : temp_dirs_2) { + current_dir = dir_num; num_indexed = NumberIndexed_1D(current_dir, q_vectors, required_tolerance); if (num_indexed > max_indexed) max_indexed = num_indexed; @@ -1293,8 +1291,8 @@ size_t IndexingUtils::FFTScanFor_Directions(std::vector<V3D> &directions, // only keep original directions that index // at least 50% of max num indexed temp_dirs.clear(); - for (size_t dir_num = 0; dir_num < temp_dirs_2.size(); dir_num++) { - current_dir = temp_dirs_2[dir_num]; + for (auto &dir_num : temp_dirs_2) { + current_dir = dir_num; num_indexed = NumberIndexed_1D(current_dir, q_vectors, required_tolerance); if (num_indexed >= 0.50 * max_indexed) temp_dirs.push_back(current_dir); @@ -1305,19 +1303,18 @@ size_t IndexingUtils::FFTScanFor_Directions(std::vector<V3D> &directions, max_indexed = 0; std::vector<int> index_vals; std::vector<V3D> indexed_qs; - for (size_t dir_num = 0; dir_num < temp_dirs.size(); dir_num++) { - num_indexed = - GetIndexedPeaks_1D(temp_dirs[dir_num], q_vectors, required_tolerance, - index_vals, indexed_qs, fit_error); + for (auto &temp_dir : temp_dirs) { + num_indexed = GetIndexedPeaks_1D(temp_dir, q_vectors, required_tolerance, + index_vals, indexed_qs, fit_error); try { int count = 0; while (count < 5) // 5 iterations should be enough for { // the optimization to stabilize - Optimize_Direction(temp_dirs[dir_num], index_vals, indexed_qs); + Optimize_Direction(temp_dir, index_vals, indexed_qs); - num_indexed = GetIndexedPeaks_1D(temp_dirs[dir_num], q_vectors, - required_tolerance, index_vals, - indexed_qs, fit_error); + num_indexed = + GetIndexedPeaks_1D(temp_dir, q_vectors, required_tolerance, + index_vals, indexed_qs, fit_error); if (num_indexed > max_indexed) max_indexed = num_indexed; @@ -1329,8 +1326,8 @@ size_t IndexingUtils::FFTScanFor_Directions(std::vector<V3D> &directions, } // discard those with length out of bounds temp_dirs_2.clear(); - for (size_t i = 0; i < temp_dirs.size(); i++) { - current_dir = temp_dirs[i]; + for (auto &temp_dir : temp_dirs) { + current_dir = temp_dir; double length = current_dir.norm(); if (length >= min_d && length <= max_d) temp_dirs_2.push_back(current_dir); @@ -1338,8 +1335,8 @@ size_t IndexingUtils::FFTScanFor_Directions(std::vector<V3D> &directions, // only keep directions that index at // least 75% of the max number of peaks temp_dirs.clear(); - for (size_t dir_num = 0; dir_num < temp_dirs_2.size(); dir_num++) { - current_dir = temp_dirs_2[dir_num]; + for (auto &dir_num : temp_dirs_2) { + current_dir = dir_num; num_indexed = NumberIndexed_1D(current_dir, q_vectors, required_tolerance); if (num_indexed > max_indexed * 0.75) temp_dirs.push_back(current_dir); @@ -1388,8 +1385,8 @@ double IndexingUtils::GetMagFFT(const std::vector<V3D> &q_vectors, } // project onto direction V3D q_vec; - for (size_t q_num = 0; q_num < q_vectors.size(); q_num++) { - q_vec = q_vectors[q_num] / (2.0 * M_PI); + for (const auto &q_vector : q_vectors) { + q_vec = q_vector / (2.0 * M_PI); double dot_prod = current_dir.scalar_prod(q_vec); size_t index = static_cast<size_t>(fabs(index_factor * dot_prod)); if (index < N) @@ -1822,9 +1819,9 @@ void IndexingUtils::DiscardDuplicates(std::vector<V3D> &new_list, */ void IndexingUtils::RoundHKLs(std::vector<V3D> &hkl_list) { - for (size_t entry = 0; entry < hkl_list.size(); entry++) { + for (auto &entry : hkl_list) { for (size_t i = 0; i < 3; i++) { - hkl_list[entry][i] = (double)(round(hkl_list[entry][i])); + entry[i] = (double)(round(entry[i])); } } } @@ -1884,8 +1881,8 @@ int IndexingUtils::NumberOfValidIndexes(const std::vector<V3D> &hkls, double total_error = 0; int count = 0; V3D hkl; - for (size_t i = 0; i < hkls.size(); i++) { - hkl = hkls[i]; + for (const auto &i : hkls) { + hkl = i; if (ValidIndex(hkl, tolerance)) { count++; h_error = fabs(round(hkl[0]) - hkl[0]); @@ -2005,8 +2002,8 @@ int IndexingUtils::NumberIndexed(const DblMatrix &UB, } V3D hkl; - for (size_t i = 0; i < q_vectors.size(); i++) { - hkl = UB_inverse * q_vectors[i] / (2.0 * M_PI); + for (const auto &q_vector : q_vectors) { + hkl = UB_inverse * q_vector / (2.0 * M_PI); if (ValidIndex(hkl, tolerance)) { count++; } @@ -2040,8 +2037,8 @@ int IndexingUtils::NumberIndexed_1D(const V3D &direction, int count = 0; - for (size_t i = 0; i < q_vectors.size(); i++) { - double proj_value = direction.scalar_prod(q_vectors[i]) / (2.0 * M_PI); + for (const auto &q_vector : q_vectors) { + double proj_value = direction.scalar_prod(q_vector) / (2.0 * M_PI); int nearest_int = round(proj_value); double error = fabs(proj_value - nearest_int); if (error <= tolerance) { @@ -2083,10 +2080,10 @@ int IndexingUtils::NumberIndexed_3D(const V3D &a_dir, const V3D &b_dir, V3D hkl_vec; int count = 0; - for (size_t i = 0; i < q_vectors.size(); i++) { - hkl_vec[0] = a_dir.scalar_prod(q_vectors[i]) / (2.0 * M_PI); - hkl_vec[1] = b_dir.scalar_prod(q_vectors[i]) / (2.0 * M_PI); - hkl_vec[2] = c_dir.scalar_prod(q_vectors[i]) / (2.0 * M_PI); + for (const auto &q_vector : q_vectors) { + hkl_vec[0] = a_dir.scalar_prod(q_vector) / (2.0 * M_PI); + hkl_vec[1] = b_dir.scalar_prod(q_vector) / (2.0 * M_PI); + hkl_vec[2] = c_dir.scalar_prod(q_vector) / (2.0 * M_PI); if (ValidIndex(hkl_vec, tolerance)) { count++; } @@ -2138,8 +2135,8 @@ int IndexingUtils::CalculateMillerIndices(const DblMatrix &UB, double h_error, k_error, l_error; ave_error = 0.0; V3D hkl; - for (size_t i = 0; i < q_vectors.size(); i++) { - hkl = UB_inverse * q_vectors[i] / (2.0 * M_PI); + for (const auto &q_vector : q_vectors) { + hkl = UB_inverse * q_vector / (2.0 * M_PI); if (ValidIndex(hkl, tolerance)) { count++; miller_indices.push_back(V3D(hkl)); @@ -2204,13 +2201,13 @@ int IndexingUtils::GetIndexedPeaks_1D(const V3D &direction, return 0; // any peaks, even though dot product // with Q vectors is always an integer! - for (size_t q_num = 0; q_num < q_vectors.size(); q_num++) { - double proj_value = direction.scalar_prod(q_vectors[q_num]) / (2.0 * M_PI); + for (const auto &q_vector : q_vectors) { + double proj_value = direction.scalar_prod(q_vector) / (2.0 * M_PI); int nearest_int = round(proj_value); double error = fabs(proj_value - nearest_int); if (error < required_tolerance) { fit_error += error * error; - indexed_qs.push_back(q_vectors[q_num]); + indexed_qs.push_back(q_vector); index_vals.push_back(nearest_int); num_indexed++; } @@ -2270,13 +2267,10 @@ int IndexingUtils::GetIndexedPeaks_3D( fit_error = 0; - for (size_t q_num = 0; q_num < q_vectors.size(); q_num++) { - double projected_h = - direction_1.scalar_prod(q_vectors[q_num]) / (2.0 * M_PI); - double projected_k = - direction_2.scalar_prod(q_vectors[q_num]) / (2.0 * M_PI); - double projected_l = - direction_3.scalar_prod(q_vectors[q_num]) / (2.0 * M_PI); + for (const auto &q_vector : q_vectors) { + double projected_h = direction_1.scalar_prod(q_vector) / (2.0 * M_PI); + double projected_k = direction_2.scalar_prod(q_vector) / (2.0 * M_PI); + double projected_l = direction_3.scalar_prod(q_vector) / (2.0 * M_PI); hkl(projected_h, projected_k, projected_l); @@ -2291,7 +2285,7 @@ int IndexingUtils::GetIndexedPeaks_3D( fit_error += h_error * h_error + k_error * k_error + l_error * l_error; - indexed_qs.push_back(q_vectors[q_num]); + indexed_qs.push_back(q_vector); V3D miller_ind(h_int, k_int, l_int); miller_indices.push_back(miller_ind); @@ -2353,8 +2347,8 @@ int IndexingUtils::GetIndexedPeaks(const DblMatrix &UB, throw std::runtime_error("The UB in GetIndexedPeaks() is not valid"); } - for (size_t q_num = 0; q_num < q_vectors.size(); q_num++) { - hkl = UB_inverse * q_vectors[q_num] / (2.0 * M_PI); + for (const auto &q_vector : q_vectors) { + hkl = UB_inverse * q_vector / (2.0 * M_PI); if (ValidIndex(hkl, required_tolerance)) { for (int i = 0; i < 3; i++) { @@ -2362,7 +2356,7 @@ int IndexingUtils::GetIndexedPeaks(const DblMatrix &UB, fit_error += error * error; } - indexed_qs.push_back(q_vectors[q_num]); + indexed_qs.push_back(q_vector); V3D miller_ind(round(hkl[0]), round(hkl[1]), round(hkl[2])); miller_indices.push_back(miller_ind); @@ -2548,13 +2542,11 @@ int IndexingUtils::SelectDirection(V3D &best_direction, double error; double min_sum_sq_error = 1.0e100; - for (size_t dir_num = 0; dir_num < direction_list.size(); dir_num++) { + for (auto direction : direction_list) { double sum_sq_error = 0; - V3D direction = direction_list[dir_num]; direction /= plane_spacing; - for (size_t q_num = 0; q_num < q_vectors.size(); q_num++) { - double dot_product = - direction.scalar_prod(q_vectors[q_num]) / (2.0 * M_PI); + for (const auto &q_vector : q_vectors) { + double dot_product = direction.scalar_prod(q_vector) / (2.0 * M_PI); nearest_int = round(dot_product); error = fabs(dot_product - nearest_int); sum_sq_error += error * error; @@ -2567,9 +2559,8 @@ int IndexingUtils::SelectDirection(V3D &best_direction, } int num_indexed = 0; - for (size_t q_num = 0; q_num < q_vectors.size(); q_num++) { - double proj_value = - best_direction.scalar_prod(q_vectors[q_num]) / (2.0 * M_PI); + for (const auto &q_vector : q_vectors) { + double proj_value = best_direction.scalar_prod(q_vector) / (2.0 * M_PI); nearest_int = round(proj_value); error = fabs(proj_value - nearest_int); if (error < required_tolerance) diff --git a/Framework/Geometry/src/Crystal/PeakTransformSelector.cpp b/Framework/Geometry/src/Crystal/PeakTransformSelector.cpp index 1bdc75000ab..3584c8f3e64 100644 --- a/Framework/Geometry/src/Crystal/PeakTransformSelector.cpp +++ b/Framework/Geometry/src/Crystal/PeakTransformSelector.cpp @@ -34,10 +34,8 @@ PeakTransformFactory_sptr PeakTransformSelector::makeDefaultChoice() const { PeakTransformFactory_sptr selected; bool found = false; - for (auto it = m_candidateFactories.begin(); it != m_candidateFactories.end(); - ++it) { + for (auto temp : m_candidateFactories) { try { - PeakTransformFactory_sptr temp = (*it); temp->createDefaultTransform(); selected = temp; found = true; @@ -72,10 +70,8 @@ PeakTransformSelector::makeChoice(const std::string labelX, PeakTransformFactory_sptr selected; bool found = false; - for (auto it = m_candidateFactories.begin(); it != m_candidateFactories.end(); - ++it) { + for (auto temp : m_candidateFactories) { try { - PeakTransformFactory_sptr temp = (*it); temp->createTransform(labelX, labelY); selected = temp; found = true; diff --git a/Framework/Geometry/src/Crystal/PointGroup.cpp b/Framework/Geometry/src/Crystal/PointGroup.cpp index 0483dfd561c..027cd7b2880 100644 --- a/Framework/Geometry/src/Crystal/PointGroup.cpp +++ b/Framework/Geometry/src/Crystal/PointGroup.cpp @@ -105,8 +105,8 @@ std::vector<V3D> PointGroup::getEquivalentSet(const Kernel::V3D &hkl) const { std::vector<V3D> equivalents; equivalents.reserve(m_allOperations.size()); - for (auto op = m_allOperations.begin(); op != m_allOperations.end(); ++op) { - equivalents.push_back((*op).transformHKL(hkl)); + for (const auto &m_allOperation : m_allOperations) { + equivalents.push_back(m_allOperation.transformHKL(hkl)); } std::sort(equivalents.begin(), equivalents.end(), std::greater<V3D>()); @@ -131,10 +131,11 @@ std::vector<V3D> PointGroup::getEquivalentSet(const Kernel::V3D &hkl) const { PointGroup::CrystalSystem PointGroup::getCrystalSystemFromGroup() const { std::map<std::string, std::set<V3D>> symbolMap; - for (auto op = m_allOperations.begin(); op != m_allOperations.end(); ++op) { + for (const auto &m_allOperation : m_allOperations) { SymmetryElementWithAxis_sptr element = boost::dynamic_pointer_cast<SymmetryElementWithAxis>( - SymmetryElementFactory::Instance().createSymElement(*op)); + SymmetryElementFactory::Instance().createSymElement( + m_allOperation)); if (element) { std::string symbol = element->hmSymbol(); @@ -214,8 +215,8 @@ std::vector<PointGroup_sptr> getAllPointGroups() { PointGroupFactory::Instance().getAllPointGroupSymbols(); std::vector<PointGroup_sptr> out; - for (auto it = allSymbols.begin(); it != allSymbols.end(); ++it) { - out.push_back(PointGroupFactory::Instance().createPointGroup(*it)); + for (auto &allSymbol : allSymbols) { + out.push_back(PointGroupFactory::Instance().createPointGroup(allSymbol)); } return out; @@ -226,8 +227,8 @@ PointGroupCrystalSystemMap getPointGroupsByCrystalSystem() { PointGroupCrystalSystemMap map; std::vector<PointGroup_sptr> pointGroups = getAllPointGroups(); - for (size_t i = 0; i < pointGroups.size(); ++i) { - map.insert(std::make_pair(pointGroups[i]->crystalSystem(), pointGroups[i])); + for (auto &pointGroup : pointGroups) { + map.insert(std::make_pair(pointGroup->crystalSystem(), pointGroup)); } return map; diff --git a/Framework/Geometry/src/Crystal/PointGroupFactory.cpp b/Framework/Geometry/src/Crystal/PointGroupFactory.cpp index e04b913c429..68d4202ec23 100644 --- a/Framework/Geometry/src/Crystal/PointGroupFactory.cpp +++ b/Framework/Geometry/src/Crystal/PointGroupFactory.cpp @@ -58,8 +58,8 @@ std::vector<std::string> PointGroupFactoryImpl::getAllPointGroupSymbols() const { std::vector<std::string> pointGroups; - for (auto it = m_generatorMap.begin(); it != m_generatorMap.end(); ++it) { - pointGroups.push_back(it->first); + for (const auto &it : m_generatorMap) { + pointGroups.push_back(it.first); } return pointGroups; @@ -71,11 +71,11 @@ std::vector<std::string> PointGroupFactoryImpl::getPointGroupSymbols( const PointGroup::CrystalSystem &crystalSystem) { std::vector<std::string> pointGroups; - for (auto it = m_generatorMap.begin(); it != m_generatorMap.end(); ++it) { - PointGroup_sptr pointGroup = getPrototype(it->first); + for (auto &it : m_generatorMap) { + PointGroup_sptr pointGroup = getPrototype(it.first); if (pointGroup->crystalSystem() == crystalSystem) { - pointGroups.push_back(it->first); + pointGroups.push_back(it.first); } } diff --git a/Framework/Geometry/src/Crystal/ProductOfCyclicGroups.cpp b/Framework/Geometry/src/Crystal/ProductOfCyclicGroups.cpp index d2c48bac2c2..3aa2a64504e 100644 --- a/Framework/Geometry/src/Crystal/ProductOfCyclicGroups.cpp +++ b/Framework/Geometry/src/Crystal/ProductOfCyclicGroups.cpp @@ -32,9 +32,9 @@ std::vector<Group_const_sptr> ProductOfCyclicGroups::getFactorGroups( const std::vector<SymmetryOperation> &symmetryOperations) const { std::vector<Group_const_sptr> groups; - for (auto it = symmetryOperations.begin(); it != symmetryOperations.end(); - ++it) { - groups.push_back(GroupFactory::create<CyclicGroup>((*it).identifier())); + for (const auto &symmetryOperation : symmetryOperations) { + groups.push_back( + GroupFactory::create<CyclicGroup>(symmetryOperation.identifier())); } return groups; diff --git a/Framework/Geometry/src/Crystal/ScalarUtils.cpp b/Framework/Geometry/src/Crystal/ScalarUtils.cpp index e92b977edef..be2c9215bfa 100644 --- a/Framework/Geometry/src/Crystal/ScalarUtils.cpp +++ b/Framework/Geometry/src/Crystal/ScalarUtils.cpp @@ -95,8 +95,8 @@ std::vector<ConventionalCell> ScalarUtils::GetCells(const DblMatrix &UB, temp.clear(); temp.push_back(info); } - for (size_t k = 0; k < temp.size(); k++) - AddIfBest(result, temp[k]); + for (auto &k : temp) + AddIfBest(result, k); } return result; @@ -143,12 +143,12 @@ ScalarUtils::GetCells(const DblMatrix &UB, const std::string &cell_type, UB_list.push_back(UB); } - for (size_t k = 0; k < UB_list.size(); k++) { + for (auto &k : UB_list) { std::vector<ConventionalCell> temp = - GetCellsUBOnly(UB_list[k], cell_type, centering, allowPermutations); + GetCellsUBOnly(k, cell_type, centering, allowPermutations); - for (size_t i = 0; i < temp.size(); i++) - AddIfBest(result, temp[i]); + for (auto &i : temp) + AddIfBest(result, i); } return result; @@ -234,8 +234,8 @@ ConventionalCell ScalarUtils::GetCellForForm(const DblMatrix &UB, // Get exact form requested and not permutations UB_list.push_back(UB); } - for (size_t i = 0; i < UB_list.size(); i++) { - IndexingUtils::GetLatticeParameters(UB_list[i], l_params); + for (auto &i : UB_list) { + IndexingUtils::GetLatticeParameters(i, l_params); form_0 = ReducedCell(0, l_params[0], l_params[1], l_params[2], l_params[3], l_params[4], l_params[5]); @@ -245,7 +245,7 @@ ConventionalCell ScalarUtils::GetCellForForm(const DblMatrix &UB, double error = form_0.WeightedDistance(form); if (error < min_error) { - info = ConventionalCell(UB_list[i], form_num, allowPermutations); + info = ConventionalCell(i, form_num, allowPermutations); min_error = error; } } @@ -268,13 +268,13 @@ void ScalarUtils::RemoveHighErrorForms(std::vector<ConventionalCell> &list, std::vector<ConventionalCell> new_list; - for (size_t i = 0; i < list.size(); i++) - if (list[i].GetError() <= level) - new_list.push_back(list[i]); + for (auto &i : list) + if (i.GetError() <= level) + new_list.push_back(i); list.clear(); - for (size_t i = 0; i < new_list.size(); i++) - list.push_back(new_list[i]); + for (const auto &i : new_list) + list.push_back(i); } /** @@ -302,12 +302,12 @@ ScalarUtils::GetCellBestError(const std::vector<ConventionalCell> &list, std::string type; bool min_found = false; - for (size_t i = 0; i < list.size(); i++) { - type = list[i].GetCellType(); - double error = list[i].GetError(); + for (const auto &i : list) { + type = i.GetCellType(); + double error = i.GetError(); if ((use_triclinic || type != ReducedCell::TRICLINIC()) && error < min_error) { - info = list[i]; + info = i; min_error = error; min_found = true; } @@ -411,10 +411,10 @@ std::vector<DblMatrix> ScalarUtils::GetRelatedUBs(const DblMatrix &UB, {c_temp, a_temp, b_temp}, {m_c_temp, b_temp, a_temp}}; - for (size_t perm = 0; perm < 6; perm++) { - a = permutations[perm][0]; - b = permutations[perm][1]; - c = permutations[perm][2]; + for (auto &permutation : permutations) { + a = permutation[0]; + b = permutation[1]; + c = permutation[2]; if (a.norm() <= factor * b.norm() && b.norm() <= factor * c.norm()) // could be Niggli within { // experimental error diff --git a/Framework/Geometry/src/Crystal/SpaceGroup.cpp b/Framework/Geometry/src/Crystal/SpaceGroup.cpp index 2a8f15ee24e..f22174f858c 100644 --- a/Framework/Geometry/src/Crystal/SpaceGroup.cpp +++ b/Framework/Geometry/src/Crystal/SpaceGroup.cpp @@ -59,16 +59,17 @@ std::string SpaceGroup::hmSymbol() const { return m_hmSymbol; } * @return :: true if the reflection is allowed, false otherwise. */ bool SpaceGroup::isAllowedReflection(const Kernel::V3D &hkl) const { - for (auto op = m_allOperations.begin(); op != m_allOperations.end(); ++op) { - if ((*op).hasTranslation()) { + for (const auto &m_allOperation : m_allOperations) { + if (m_allOperation.hasTranslation()) { /* Floating point precision problem: * (H . v) % 1.0 is not always exactly 0, so instead: * | [(H . v) + delta] % 1.0 | > 1e-14 is checked * The transformation is only performed if necessary. */ - if ((fabs(fmod(fabs(hkl.scalar_prod((*op).reducedVector())) + 1e-15, + if ((fabs(fmod(fabs(hkl.scalar_prod(m_allOperation.reducedVector())) + + 1e-15, 1.0)) > 1e-14) && - ((*op).transformHKL(hkl) == hkl)) { + (m_allOperation.transformHKL(hkl) == hkl)) { return false; } } @@ -105,10 +106,10 @@ Group_const_sptr SpaceGroup::getSiteSymmetryGroup(const V3D &position) const { std::vector<SymmetryOperation> siteSymmetryOps; - for (auto op = m_allOperations.begin(); op != m_allOperations.end(); ++op) { - if (Geometry::getWrappedVector((*op) * wrappedPosition) == + for (const auto &m_allOperation : m_allOperations) { + if (Geometry::getWrappedVector(m_allOperation * wrappedPosition) == wrappedPosition) { - siteSymmetryOps.push_back(*op); + siteSymmetryOps.push_back(m_allOperation); } } diff --git a/Framework/Geometry/src/Crystal/SpaceGroupFactory.cpp b/Framework/Geometry/src/Crystal/SpaceGroupFactory.cpp index 1d3917cd762..8342b5a9035 100644 --- a/Framework/Geometry/src/Crystal/SpaceGroupFactory.cpp +++ b/Framework/Geometry/src/Crystal/SpaceGroupFactory.cpp @@ -19,9 +19,9 @@ bool isValidGeneratorString(const std::string &generatorString) { std::vector<std::string> generatorStrings; boost::split(generatorStrings, generatorString, boost::is_any_of(";")); - for (auto it = generatorStrings.begin(); it != generatorStrings.end(); ++it) { + for (auto &generatorString : generatorStrings) { try { - SymmetryOperationSymbolParser::parseIdentifier(*it); + SymmetryOperationSymbolParser::parseIdentifier(generatorString); } catch (Kernel::Exception::ParseError) { return false; } @@ -146,8 +146,8 @@ SpaceGroupFactoryImpl::subscribedSpaceGroupSymbols() const { std::vector<std::string> symbols; symbols.reserve(m_generatorMap.size()); - for (auto it = m_generatorMap.begin(); it != m_generatorMap.end(); ++it) { - symbols.push_back(it->first); + for (const auto &it : m_generatorMap) { + symbols.push_back(it.first); } return symbols; @@ -260,11 +260,11 @@ SpaceGroup_const_sptr SpaceGroupFactoryImpl::constructFromPrototype( void SpaceGroupFactoryImpl::fillPointGroupMap() { m_pointGroupMap.clear(); - for (auto it = m_generatorMap.begin(); it != m_generatorMap.end(); ++it) { - SpaceGroup_const_sptr spaceGroup = getPrototype(it->first); + for (auto &it : m_generatorMap) { + SpaceGroup_const_sptr spaceGroup = getPrototype(it.first); m_pointGroupMap.insert( - std::make_pair(spaceGroup->getPointGroup()->getSymbol(), it->first)); + std::make_pair(spaceGroup->getPointGroup()->getSymbol(), it.first)); } } diff --git a/Framework/Geometry/src/Crystal/StructureFactorCalculatorSummation.cpp b/Framework/Geometry/src/Crystal/StructureFactorCalculatorSummation.cpp index eabc22952cb..898ac47b67c 100644 --- a/Framework/Geometry/src/Crystal/StructureFactorCalculatorSummation.cpp +++ b/Framework/Geometry/src/Crystal/StructureFactorCalculatorSummation.cpp @@ -55,9 +55,9 @@ void StructureFactorCalculatorSummation::updateUnitCellScatterers( std::vector<V3D> positions = spaceGroup->getEquivalentPositions(current->getPosition()); - for (auto pos = positions.begin(); pos != positions.end(); ++pos) { + for (auto &position : positions) { BraggScatterer_sptr clone = current->clone(); - clone->setProperty("Position", getV3DasString(*pos)); + clone->setProperty("Position", getV3DasString(position)); braggScatterers.push_back(clone); } diff --git a/Framework/Geometry/src/Crystal/SymmetryElementFactory.cpp b/Framework/Geometry/src/Crystal/SymmetryElementFactory.cpp index 6c98097cca3..56963582773 100644 --- a/Framework/Geometry/src/Crystal/SymmetryElementFactory.cpp +++ b/Framework/Geometry/src/Crystal/SymmetryElementFactory.cpp @@ -378,10 +378,9 @@ SymmetryElement_sptr SymmetryElementFactoryImpl::createFromPrototype( /// invalid pointer if no appropriate generator is found. AbstractSymmetryElementGenerator_sptr SymmetryElementFactoryImpl::getGenerator( const SymmetryOperation &operation) const { - for (auto generator = m_generators.begin(); generator != m_generators.end(); - ++generator) { - if ((*generator)->canProcess(operation)) { - return *generator; + for (const auto &m_generator : m_generators) { + if (m_generator->canProcess(operation)) { + return m_generator; } } diff --git a/Framework/Geometry/src/Crystal/SymmetryOperationFactory.cpp b/Framework/Geometry/src/Crystal/SymmetryOperationFactory.cpp index eb2ce9ebeb1..469ef2bf861 100644 --- a/Framework/Geometry/src/Crystal/SymmetryOperationFactory.cpp +++ b/Framework/Geometry/src/Crystal/SymmetryOperationFactory.cpp @@ -32,8 +32,8 @@ SymmetryOperationFactoryImpl::createSymOps(const std::string &identifiers) { std::vector<SymmetryOperation> SymmetryOperationFactoryImpl::createSymOps( const std::vector<std::string> &identifiers) { std::vector<SymmetryOperation> symOps; - for (auto it = identifiers.begin(); it != identifiers.end(); ++it) { - symOps.push_back(createSymOp(boost::trim_copy(*it))); + for (const auto &identifier : identifiers) { + symOps.push_back(createSymOp(boost::trim_copy(identifier))); } return symOps; @@ -67,8 +67,8 @@ SymmetryOperationFactoryImpl::subscribedSymbols() const { std::vector<std::string> symbols; symbols.reserve(m_prototypes.size()); - for (auto it = m_prototypes.begin(); it != m_prototypes.end(); ++it) { - symbols.push_back(it->first); + for (const auto &m_prototype : m_prototypes) { + symbols.push_back(m_prototype.first); } return symbols; diff --git a/Framework/Geometry/src/Crystal/SymmetryOperationSymbolParser.cpp b/Framework/Geometry/src/Crystal/SymmetryOperationSymbolParser.cpp index 24fedd2e69e..76af736770d 100644 --- a/Framework/Geometry/src/Crystal/SymmetryOperationSymbolParser.cpp +++ b/Framework/Geometry/src/Crystal/SymmetryOperationSymbolParser.cpp @@ -308,10 +308,10 @@ bool SymmetryOperationSymbolParser::isValidMatrixRow( const std::vector<int> &matrixRow) { int nulls = 0; - for (auto it = matrixRow.begin(); it != matrixRow.end(); ++it) { - if (abs(*it) > 1) { + for (int it : matrixRow) { + if (abs(it) > 1) { return false; - } else if (*it == 0) { + } else if (it == 0) { ++nulls; } } diff --git a/Framework/Geometry/src/Instrument.cpp b/Framework/Geometry/src/Instrument.cpp index adecb4b35ad..2e793a54d1a 100644 --- a/Framework/Geometry/src/Instrument.cpp +++ b/Framework/Geometry/src/Instrument.cpp @@ -182,10 +182,10 @@ void Instrument::getDetectors(detid2det_map &out_map) const { const detid2det_map &in_dets = static_cast<const Instrument *>(m_base)->m_detectorCache; // And turn them into parametrized versions - for (auto it = in_dets.cbegin(); it != in_dets.cend(); ++it) { + for (const auto &in_det : in_dets) { out_map.insert(std::pair<detid_t, IDetector_sptr>( - it->first, - ParComponentFactory::createDetector(it->second.get(), m_map))); + in_det.first, + ParComponentFactory::createDetector(in_det.second.get(), m_map))); } } else { // You can just return the detector cache directly. @@ -200,14 +200,14 @@ std::vector<detid_t> Instrument::getDetectorIDs(bool skipMonitors) const { if (m_map) { const detid2det_map &in_dets = static_cast<const Instrument *>(m_base)->m_detectorCache; - for (auto it = in_dets.cbegin(); it != in_dets.cend(); ++it) - if (!skipMonitors || !it->second->isMonitor()) - out.push_back(it->first); + for (const auto &in_det : in_dets) + if (!skipMonitors || !in_det.second->isMonitor()) + out.push_back(in_det.first); } else { const detid2det_map &in_dets = m_detectorCache; - for (auto it = in_dets.cbegin(); it != in_dets.cend(); ++it) - if (!skipMonitors || !it->second->isMonitor()) - out.push_back(it->first); + for (const auto &in_det : in_dets) + if (!skipMonitors || !in_det.second->isMonitor()) + out.push_back(in_det.first); } return out; } @@ -228,13 +228,13 @@ std::size_t Instrument::getNumberDetectors(bool skipMonitors) const { if (m_map) { const detid2det_map &in_dets = static_cast<const Instrument *>(m_base)->m_detectorCache; - for (auto it = in_dets.cbegin(); it != in_dets.cend(); ++it) - if (it->second->isMonitor()) + for (const auto &in_det : in_dets) + if (in_det.second->isMonitor()) monitors += 1; } else { const detid2det_map &in_dets = m_detectorCache; - for (auto it = in_dets.begin(); it != in_dets.end(); ++it) - if (it->second->isMonitor()) + for (const auto &in_det : in_dets) + if (in_det.second->isMonitor()) monitors += 1; } return (numDetIDs - monitors); @@ -504,8 +504,8 @@ bool Instrument::isMonitor(const std::set<detid_t> &detector_ids) const { if (detector_ids.empty()) return false; - for (auto it = detector_ids.cbegin(); it != detector_ids.cend(); ++it) { - if (this->isMonitor(*it)) + for (value_type detector_id : detector_ids) { + if (this->isMonitor(detector_id)) return true; } return false; @@ -551,8 +551,8 @@ bool Instrument::isDetectorMasked(const std::set<detid_t> &detector_ids) const { if (detector_ids.empty()) return false; - for (auto it = detector_ids.cbegin(); it != detector_ids.cend(); ++it) { - if (!this->isDetectorMasked(*it)) + for (value_type detector_id : detector_ids) { + if (!this->isDetectorMasked(detector_id)) return false; } return true; @@ -824,9 +824,8 @@ void Instrument::getBoundingBox(BoundingBox &assemblyBox) const { m_cachedBoundingBox = new BoundingBox(); ComponentID sourceID = getSource()->getComponentID(); // Loop over the children and define a box large enough for all of them - for (auto it = m_children.cbegin(); it != m_children.cend(); ++it) { + for (auto component : m_children) { BoundingBox compBox; - IComponent *component = *it; if (component && component->getComponentID() != sourceID) { component->getBoundingBox(compBox); m_cachedBoundingBox->grow(compBox); @@ -949,15 +948,15 @@ double Instrument::calcConversion( const std::map<detid_t, double> &offsets) { double factor = 0.; double offset; - for (auto iter = detectors.cbegin(); iter != detectors.cend(); ++iter) { - auto off_iter = offsets.find(*iter); + for (int detector : detectors) { + auto off_iter = offsets.find(detector); if (off_iter != offsets.cend()) { - offset = offsets.find(*iter)->second; + offset = offsets.find(detector)->second; } else { offset = 0.; } factor += calcConversion(l1, beamline, beamline_norm, samplePos, - instrument->getDetector(*iter), offset); + instrument->getDetector(detector), offset); } return factor / static_cast<double>(detectors.size()); } diff --git a/Framework/Geometry/src/Instrument/CompAssembly.cpp b/Framework/Geometry/src/Instrument/CompAssembly.cpp index 7c73ef1e6b9..bc0326aa528 100644 --- a/Framework/Geometry/src/Instrument/CompAssembly.cpp +++ b/Framework/Geometry/src/Instrument/CompAssembly.cpp @@ -65,8 +65,8 @@ CompAssembly::~CompAssembly() { if (m_cachedBoundingBox) delete m_cachedBoundingBox; // Iterate over pointers in m_children, deleting them - for (auto it = m_children.begin(); it != m_children.end(); ++it) { - delete *it; + for (auto &it : m_children) { + delete it; } m_children.clear(); } @@ -371,10 +371,10 @@ void CompAssembly::getBoundingBox(BoundingBox &assemblyBox) const { if (!m_cachedBoundingBox) { m_cachedBoundingBox = new BoundingBox(); // Loop over the children and define a box large enough for all of them - for (auto it = m_children.cbegin(); it != m_children.cend(); ++it) { + for (auto it : m_children) { BoundingBox compBox; - if (*it) { - (*it)->getBoundingBox(compBox); + if (it) { + it->getBoundingBox(compBox); m_cachedBoundingBox->grow(compBox); } } diff --git a/Framework/Geometry/src/Instrument/Component.cpp b/Framework/Geometry/src/Instrument/Component.cpp index 72bb0aa8be0..62384840a1c 100644 --- a/Framework/Geometry/src/Instrument/Component.cpp +++ b/Framework/Geometry/src/Instrument/Component.cpp @@ -445,9 +445,9 @@ Component::getParameterNamesByComponent() const { return retVal; std::set<std::string> names = m_map->names(this); - for (auto itNames = names.begin(); itNames != names.end(); ++itNames) { + for (const auto &name : names) { retVal.insert( - std::pair<std::string, ComponentID>(*itNames, this->getComponentID())); + std::pair<std::string, ComponentID>(name, this->getComponentID())); } // Walk up the tree and find the parameters attached to the parent components diff --git a/Framework/Geometry/src/Instrument/DetectorGroup.cpp b/Framework/Geometry/src/Instrument/DetectorGroup.cpp index 8366e8c9153..19bd2c4b1b6 100644 --- a/Framework/Geometry/src/Instrument/DetectorGroup.cpp +++ b/Framework/Geometry/src/Instrument/DetectorGroup.cpp @@ -353,14 +353,14 @@ std::string DetectorGroup::getParameterAsString(const std::string &pname, void DetectorGroup::getBoundingBox(BoundingBox &boundingBox) const { // boundingBox = BoundingBox(); // this change may modify a lot of behaviour // -> verify - for (auto cit = m_detectors.cbegin(); cit != m_detectors.cend(); ++cit) { + for (const auto &m_detector : m_detectors) { BoundingBox memberBox; if (!boundingBox.isAxisAligned()) { // coordinate system const std::vector<V3D> *cs = &(boundingBox.getCoordSystem()); memberBox.realign(cs); } - IComponent_const_sptr det = cit->second; + IComponent_const_sptr det = m_detector.second; det->getBoundingBox(memberBox); boundingBox.grow(memberBox); } diff --git a/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp b/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp index fec0c50da5f..36ce76707d6 100644 --- a/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp +++ b/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp @@ -357,11 +357,10 @@ InstrumentDefinitionParser::parseXML(Kernel::ProgressBase *prog) { if (prog) prog->resetNumSteps(compElems.size(), 0.0, 1.0); - for (size_t i = 0; i < compElems.size(); ++i) { + for (auto pElem : compElems) { if (prog) prog->report("Loading instrument Definition"); - const Element *pElem = compElems[i]; { IdList idList; // structure to possibly be populated with detector IDs @@ -2180,18 +2179,16 @@ void InstrumentDefinitionParser::setComponentLinks( } } - for (size_t i = 0; i < sharedIComp.size(); i++) { + for (auto &i : sharedIComp) { boost::shared_ptr<const Geometry::Component> sharedComp = - boost::dynamic_pointer_cast<const Geometry::Component>( - sharedIComp[i]); + boost::dynamic_pointer_cast<const Geometry::Component>(i); if (sharedComp) { // Not empty Component if (sharedComp->isParametrized()) { setLogfile(sharedComp->base(), curElem, instrument->getLogfileCache()); } else { - setLogfile(sharedIComp[i].get(), curElem, - instrument->getLogfileCache()); + setLogfile(i.get(), curElem, instrument->getLogfileCache()); } } } @@ -2636,10 +2633,10 @@ InstrumentDefinitionParser::convertLocationsElement( std::map<std::string, double> attrValues; // Read all the set attribute values - for (auto it = allAttrs.begin(); it != allAttrs.end(); ++it) { - if (pElem->hasAttribute(*it)) { - attrValues[*it] = - boost::lexical_cast<double>(Strings::strip(pElem->getAttribute(*it))); + for (const auto &allAttr : allAttrs) { + if (pElem->hasAttribute(allAttr)) { + attrValues[allAttr] = boost::lexical_cast<double>( + Strings::strip(pElem->getAttribute(allAttr))); } } @@ -2647,19 +2644,20 @@ InstrumentDefinitionParser::convertLocationsElement( std::map<std::string, double> rangeAttrSteps; // Find *-end for range attributes and calculate steps - for (auto it = rangeAttrs.begin(); it != rangeAttrs.end(); ++it) { - std::string endAttr = *it + "-end"; + for (const auto &rangeAttr : rangeAttrs) { + std::string endAttr = rangeAttr + "-end"; if (pElem->hasAttribute(endAttr)) { - if (attrValues.find(*it) == attrValues.end()) { + if (attrValues.find(rangeAttr) == attrValues.end()) { throw Exception::InstrumentDefinitionError( "*-end attribute without corresponding * attribute."); } - double from = attrValues[*it]; + double from = attrValues[rangeAttr]; double to = boost::lexical_cast<double>( Strings::strip(pElem->getAttribute(endAttr))); - rangeAttrSteps[*it] = (to - from) / (static_cast<double>(nElements) - 1); + rangeAttrSteps[rangeAttr] = + (to - from) / (static_cast<double>(nElements) - 1); } } @@ -2678,13 +2676,13 @@ InstrumentDefinitionParser::convertLocationsElement( } // Copy values of all the attributes set - for (auto it = attrValues.begin(); it != attrValues.end(); ++it) { - pLoc->setAttribute(it->first, - boost::lexical_cast<std::string>(it->second)); + for (auto &attrValue : attrValues) { + pLoc->setAttribute(attrValue.first, + boost::lexical_cast<std::string>(attrValue.second)); // If attribute has a step, increase the value by the step - if (rangeAttrSteps.find(it->first) != rangeAttrSteps.end()) { - it->second += rangeAttrSteps[it->first]; + if (rangeAttrSteps.find(attrValue.first) != rangeAttrSteps.end()) { + attrValue.second += rangeAttrSteps[attrValue.first]; } } diff --git a/Framework/Geometry/src/Instrument/ObjCompAssembly.cpp b/Framework/Geometry/src/Instrument/ObjCompAssembly.cpp index c461064c44b..4ddcd61ab84 100644 --- a/Framework/Geometry/src/Instrument/ObjCompAssembly.cpp +++ b/Framework/Geometry/src/Instrument/ObjCompAssembly.cpp @@ -78,8 +78,8 @@ ObjCompAssembly::ObjCompAssembly(const ObjCompAssembly &ass) ObjCompAssembly::~ObjCompAssembly() { // Iterate over pointers in group, deleting them // std::vector<IComponent*>::iterator it; - for (auto it = group.begin(); it != group.end(); ++it) { - delete *it; + for (auto &it : group) { + delete it; } group.clear(); } diff --git a/Framework/Geometry/src/Instrument/ParameterMap.cpp b/Framework/Geometry/src/Instrument/ParameterMap.cpp index f491db4d599..bceb09acd58 100644 --- a/Framework/Geometry/src/Instrument/ParameterMap.cpp +++ b/Framework/Geometry/src/Instrument/ParameterMap.cpp @@ -939,10 +939,10 @@ std::set<std::string> ParameterMap::names(const IComponent *comp) const { */ std::string ParameterMap::asString() const { std::stringstream out; - for (auto it = m_map.cbegin(); it != m_map.cend(); ++it) { - boost::shared_ptr<Parameter> p = it->second; - if (p && it->first) { - const IComponent *comp = (const IComponent *)(it->first); + for (const auto &it : m_map) { + boost::shared_ptr<Parameter> p = it.second; + if (p && it.first) { + const IComponent *comp = (const IComponent *)(it.first); const IDetector *det = dynamic_cast<const IDetector *>(comp); if (det) { out << "detID:" << det->getID(); @@ -1047,9 +1047,8 @@ void ParameterMap::copyFromParameterMap(const IComponent *oldComp, std::set<std::string> oldParameterNames = oldPMap->names(oldComp); - for (auto it = oldParameterNames.begin(); it != oldParameterNames.end(); - ++it) { - Parameter_sptr thisParameter = oldPMap->get(oldComp, *it); + for (const auto &oldParameterName : oldParameterNames) { + Parameter_sptr thisParameter = oldPMap->get(oldComp, oldParameterName); // Insert the fetched parameter in the m_map m_map.insert(std::make_pair(newComp->getComponentID(), thisParameter)); } diff --git a/Framework/Geometry/src/MDGeometry/CompositeImplicitFunction.cpp b/Framework/Geometry/src/MDGeometry/CompositeImplicitFunction.cpp index a68e26b2c1c..cb993484032 100644 --- a/Framework/Geometry/src/MDGeometry/CompositeImplicitFunction.cpp +++ b/Framework/Geometry/src/MDGeometry/CompositeImplicitFunction.cpp @@ -46,8 +46,8 @@ std::string CompositeImplicitFunction::toXMLString() const { functionElement->appendChild(parameterListElement); std::string functionXML; - for (auto it = m_Functions.begin(); it != m_Functions.end(); ++it) { - functionXML += (*it)->toXMLString(); + for (const auto &m_Function : m_Functions) { + functionXML += m_Function->toXMLString(); } AutoPtr<Text> functionFormatText = pDoc->createTextNode("%s"); functionElement->appendChild(functionFormatText); diff --git a/Framework/Geometry/src/MDGeometry/MDGeometryXMLBuilder.cpp b/Framework/Geometry/src/MDGeometry/MDGeometryXMLBuilder.cpp index ff15b1395b1..96e4a637eaf 100644 --- a/Framework/Geometry/src/MDGeometry/MDGeometryXMLBuilder.cpp +++ b/Framework/Geometry/src/MDGeometry/MDGeometryXMLBuilder.cpp @@ -64,8 +64,8 @@ bool MDGeometryBuilderXML<CheckDimensionPolicy>::addOrdinaryDimension( template <typename CheckDimensionPolicy> void MDGeometryBuilderXML<CheckDimensionPolicy>::addManyOrdinaryDimensions( VecIMDDimension_sptr manyDims) const { - for (auto it = manyDims.begin(); it != manyDims.end(); ++it) { - addOrdinaryDimension(*it); + for (auto &manyDim : manyDims) { + addOrdinaryDimension(manyDim); } } diff --git a/Framework/Geometry/src/Math/Acomp.cpp b/Framework/Geometry/src/Math/Acomp.cpp index 0ea4f61ad13..3e4ba5b3945 100644 --- a/Framework/Geometry/src/Math/Acomp.cpp +++ b/Framework/Geometry/src/Math/Acomp.cpp @@ -475,17 +475,17 @@ Units are sorted after this function is returned. int bextra = 0; // find first Component to add // std::cerr<<"Process Union:"<<Ln<<std::endl; - for (unsigned int iu = 0; iu < Ln.length(); iu++) { + for (char iu : Ln) { if (blevel) // we are in a bracket then... { - if (Ln[iu] == ')') // maybe closing outward.. + if (iu == ')') // maybe closing outward.. blevel--; - else if (Ln[iu] == '(') + else if (iu == '(') blevel++; if (blevel || bextra) - Express += Ln[iu]; + Express += iu; } else { - if (Ln[iu] == '+') { + if (iu == '+') { Acomp AX; try { AX.setString(Express); @@ -495,7 +495,7 @@ Units are sorted after this function is returned. } Express.erase(); // reset string addComp(AX); // add components - } else if (Ln[iu] == '(') { + } else if (iu == '(') { blevel++; if (Express.length()) { Express += '('; @@ -503,7 +503,7 @@ Units are sorted after this function is returned. } else bextra = 0; } else - Express += Ln[iu]; + Express += iu; } } if (Express.size() > 0) { diff --git a/Framework/Geometry/src/Objects/Object.cpp b/Framework/Geometry/src/Objects/Object.cpp index 91420767786..c058fc4ed56 100644 --- a/Framework/Geometry/src/Objects/Object.cpp +++ b/Framework/Geometry/src/Objects/Object.cpp @@ -1091,8 +1091,8 @@ double Object::triangleSolidAngle(const V3D &observer, std::vector<Kernel::V3D> vectors; this->GetObjectGeom(type, vectors, radius, height); if (type == 1) { - for (size_t i = 0; i < vectors.size(); i++) - vectors[i] *= scaleFactor; + for (auto &vector : vectors) + vector *= scaleFactor; return CuboidSolidAngle(observer, vectors); } else if (type == 2) // this is wrong for scaled objects return SphereSolidAngle(observer, vectors, radius); @@ -1626,13 +1626,13 @@ void Object::calcBoundingBoxByGeometry() { maxX = maxY = maxZ = -huge; // Loop over all corner points to find minima and maxima on each axis - for (auto iter = vectors.cbegin(); iter != vectors.cend(); ++iter) { - minX = std::min(minX, iter->X()); - maxX = std::max(maxX, iter->X()); - minY = std::min(minY, iter->Y()); - maxY = std::max(maxY, iter->Y()); - minZ = std::min(minZ, iter->Z()); - maxZ = std::max(maxZ, iter->Z()); + for (const auto &vector : vectors) { + minX = std::min(minX, vector.X()); + maxX = std::max(maxX, vector.X()); + minY = std::min(minY, vector.Y()); + maxY = std::max(maxY, vector.Y()); + minZ = std::min(minZ, vector.Z()); + maxZ = std::max(maxZ, vector.Z()); } } break; diff --git a/Framework/Geometry/src/Rendering/GluGeometryRenderer.cpp b/Framework/Geometry/src/Rendering/GluGeometryRenderer.cpp index b323e0ad994..973b00c70bb 100644 --- a/Framework/Geometry/src/Rendering/GluGeometryRenderer.cpp +++ b/Framework/Geometry/src/Rendering/GluGeometryRenderer.cpp @@ -129,14 +129,13 @@ void GluGeometryRenderer::CreateCube(const V3D &Point1, const V3D &Point2, V3D normal; // first face glBegin(GL_QUADS); - for (int i = 0; i < 6; i++) { + for (auto &i : faceindex) { normal = - (vertex[faceindex[i][0]] - vertex[faceindex[i][1]]) - .cross_prod((vertex[faceindex[i][0]] - vertex[faceindex[i][2]])); + (vertex[i[0]] - vertex[i[1]]).cross_prod((vertex[i[0]] - vertex[i[2]])); normal.normalize(); glNormal3d(normal[0], normal[1], normal[2]); for (int j = 0; j < 4; j++) { - int ij = faceindex[i][j]; + int ij = i[j]; if (ij == 0) glTexCoord2i(0, 0); if (ij == 1) diff --git a/Framework/ICat/src/CatalogLogout.cpp b/Framework/ICat/src/CatalogLogout.cpp index e8dec03f85d..74c0e15f85f 100644 --- a/Framework/ICat/src/CatalogLogout.cpp +++ b/Framework/ICat/src/CatalogLogout.cpp @@ -26,12 +26,11 @@ void CatalogLogout::exec() { auto keepAliveInstances = API::AlgorithmManager::Instance().runningInstancesOf("CatalogKeepAlive"); - for (unsigned i = 0; i < keepAliveInstances.size(); ++i) { - auto keepAliveInstance = API::AlgorithmManager::Instance().getAlgorithm( - keepAliveInstances.at(i)->getAlgorithmID()); + for (auto &i : keepAliveInstances) { + auto keepAliveInstance = + API::AlgorithmManager::Instance().getAlgorithm(i->getAlgorithmID()); - if (logoutSession == - keepAliveInstances.at(i)->getPropertyValue("Session")) { + if (logoutSession == i->getPropertyValue("Session")) { keepAliveInstance->cancel(); API::CatalogManager::Instance().destroyCatalog(logoutSession); break; diff --git a/Framework/ICat/src/ICat3/ICat3Helper.cpp b/Framework/ICat/src/ICat3/ICat3Helper.cpp index d350acbaf1c..031ad055ab5 100644 --- a/Framework/ICat/src/ICat3/ICat3Helper.cpp +++ b/Framework/ICat/src/ICat3/ICat3Helper.cpp @@ -313,8 +313,8 @@ void CICatHelper::listInstruments(std::vector<std::string> &instruments) { int result = icat.listInstruments(&request, &response); if (result == 0) { - for (unsigned i = 0; i < response.return_.size(); ++i) { - instruments.push_back(response.return_[i]); + for (const auto &i : response.return_) { + instruments.push_back(i); } } else { CErrorHandling::throwErrorMessages(icat); @@ -339,8 +339,8 @@ void CICatHelper::listInvestigationTypes( int result = icat.listInvestigationTypes(&request, &response); if (result == 0) { - for (unsigned i = 0; i < response.return_.size(); ++i) { - investTypes.push_back(response.return_[i]); + for (const auto &i : response.return_) { + investTypes.push_back(i); } } else { CErrorHandling::throwErrorMessages(icat); diff --git a/Framework/ICat/src/ICat4/ICat4Catalog.cpp b/Framework/ICat/src/ICat4/ICat4Catalog.cpp index c6ed4b9a885..2a93c56e06c 100644 --- a/Framework/ICat/src/ICat4/ICat4Catalog.cpp +++ b/Framework/ICat/src/ICat4/ICat4Catalog.cpp @@ -439,8 +439,8 @@ void ICat4Catalog::saveDataSets(std::vector<xsd__anyType *> response, } std::string emptyCell = ""; - for (auto iter = response.begin(); iter != response.end(); ++iter) { - ns1__dataset *dataset = dynamic_cast<ns1__dataset *>(*iter); + for (auto &iter : response) { + ns1__dataset *dataset = dynamic_cast<ns1__dataset *>(iter); if (dataset) { API::TableRow table = outputws->appendRow(); @@ -545,8 +545,8 @@ void ICat4Catalog::listInstruments(std::vector<std::string> &instruments) { auto searchResults = performSearch(icat, "Instrument.fullName ORDER BY fullName"); - for (unsigned i = 0; i < searchResults.size(); ++i) { - auto instrument = dynamic_cast<xsd__string *>(searchResults.at(i)); + for (auto &searchResult : searchResults) { + auto instrument = dynamic_cast<xsd__string *>(searchResult); if (instrument) instruments.push_back(instrument->__item); } @@ -564,8 +564,8 @@ void ICat4Catalog::listInvestigationTypes( auto searchResults = performSearch(icat, "InvestigationType.name ORDER BY name"); - for (size_t i = 0; i < searchResults.size(); ++i) { - auto investigationType = dynamic_cast<xsd__string *>(searchResults.at(i)); + for (auto &searchResult : searchResults) { + auto investigationType = dynamic_cast<xsd__string *>(searchResult); if (investigationType) invstTypes.push_back(investigationType->__item); } @@ -798,8 +798,8 @@ int64_t ICat4Catalog::getMantidDatasetId(const std::string &investigationID) { icat, "Dataset <-> Investigation[name = '" + investigationID + "']"); int64_t datasetID = -1; - for (size_t i = 0; i < searchResults.size(); ++i) { - auto dataset = dynamic_cast<ns1__dataset *>(searchResults.at(i)); + for (auto &searchResult : searchResults) { + auto dataset = dynamic_cast<ns1__dataset *>(searchResult); if (dataset && *(dataset->name) == "mantid") datasetID = *(dataset->id); } diff --git a/Framework/Kernel/src/Atom.cpp b/Framework/Kernel/src/Atom.cpp index 43452e3b8d6..5ca1189ab1e 100644 --- a/Framework/Kernel/src/Atom.cpp +++ b/Framework/Kernel/src/Atom.cpp @@ -3227,10 +3227,10 @@ Atom getAtom(const std::string &symbol, const uint16_t a_number) { return H3; // linear search - for (size_t i = 0; i < NUM_ATOMS; ++i) { - if (symbol.compare(ATOMS[i].symbol) == 0) { - if (a_number == ATOMS[i].a_number) { - return ATOMS[i]; + for (auto &i : ATOMS) { + if (symbol.compare(i.symbol) == 0) { + if (a_number == i.a_number) { + return i; } } } diff --git a/Framework/Kernel/src/CompositeValidator.cpp b/Framework/Kernel/src/CompositeValidator.cpp index d0b460a7837..770bbdc0261 100644 --- a/Framework/Kernel/src/CompositeValidator.cpp +++ b/Framework/Kernel/src/CompositeValidator.cpp @@ -20,8 +20,8 @@ std::vector<std::string> CompositeValidator::allowedValues() const { std::multiset<std::string> elem_all; // how many validators return non-empty list of allowed values int n_combinations(0); - for (auto itr = m_children.cbegin(); itr != m_children.cend(); ++itr) { - std::vector<std::string> subs = (*itr)->allowedValues(); + for (const auto &itr : m_children) { + std::vector<std::string> subs = itr->allowedValues(); if (subs.empty()) continue; elem_unique.insert(subs.begin(), subs.end()); @@ -32,13 +32,13 @@ std::vector<std::string> CompositeValidator::allowedValues() const { if (n_combinations < 2) return std::vector<std::string>(elem_unique.begin(), elem_unique.end()); // there is more then one combination and we have to identify its union; - for (auto its = elem_unique.cbegin(); its != elem_unique.cend(); ++its) { - auto im = elem_all.find(*its); + for (const auto &its : elem_unique) { + auto im = elem_all.find(its); elem_all.erase(im); } std::set<std::string> rez; - for (auto im = elem_all.cbegin(); im != elem_all.cend(); ++im) { - rez.insert(*im); + for (const auto &im : elem_all) { + rez.insert(im); } return std::vector<std::string>(rez.begin(), rez.end()); } @@ -50,8 +50,8 @@ std::vector<std::string> CompositeValidator::allowedValues() const { Kernel::IValidator_sptr CompositeValidator::clone() const { boost::shared_ptr<CompositeValidator> copy = boost::make_shared<CompositeValidator>(); - for (auto itr = m_children.cbegin(); itr != m_children.end(); ++itr) { - copy->add((*itr)->clone()); + for (const auto &itr : m_children) { + copy->add(itr->clone()); } return copy; } diff --git a/Framework/Kernel/src/ConfigService.cpp b/Framework/Kernel/src/ConfigService.cpp index 426e5bbafa0..25d948127ef 100644 --- a/Framework/Kernel/src/ConfigService.cpp +++ b/Framework/Kernel/src/ConfigService.cpp @@ -998,12 +998,12 @@ void ConfigServiceImpl::getKeysRecursive( if (rootKeys.empty()) allKeys.push_back(root); - for (auto rkIt = rootKeys.begin(); rkIt != rootKeys.end(); ++rkIt) { + for (auto &rootKey : rootKeys) { std::string searchString; if (root.empty()) { - searchString = *rkIt; + searchString = rootKey; } else { - searchString = root + "." + *rkIt; + searchString = root + "." + rootKey; } getKeysRecursive(searchString, allKeys); @@ -1773,8 +1773,8 @@ void ConfigServiceImpl::updateFacilities(const std::string &fName) { /// Empty the list of facilities, deleting the FacilityInfo objects in the /// process void ConfigServiceImpl::clearFacilities() { - for (auto it = m_facilities.begin(); it != m_facilities.end(); ++it) { - delete *it; + for (auto &m_facilitie : m_facilities) { + delete m_facilitie; } m_facilities.clear(); } @@ -1803,11 +1803,11 @@ ConfigServiceImpl::getInstrument(const std::string &instrumentName) const { } // Now let's look through the other facilities - for (auto it = m_facilities.cbegin(); it != m_facilities.cend(); ++it) { + for (auto m_facilitie : m_facilities) { try { g_log.debug() << "Looking for " << instrumentName << " at " - << (**it).name() << "." << std::endl; - return (**it).instrument(instrumentName); + << (*m_facilitie).name() << "." << std::endl; + return (*m_facilitie).instrument(instrumentName); } catch (Exception::NotFoundError &) { // Well the instName doesn't exist for this facility... // Move along, there's nothing to see here... @@ -1863,9 +1863,9 @@ ConfigServiceImpl::getFacility(const std::string &facilityName) const { if (facilityName.empty()) return this->getFacility(); - for (auto it = m_facilities.begin(); it != m_facilities.end(); ++it) { - if ((**it).name() == facilityName) { - return **it; + for (auto m_facilitie : m_facilities) { + if ((*m_facilitie).name() == facilityName) { + return *m_facilitie; } } diff --git a/Framework/Kernel/src/DateAndTime.cpp b/Framework/Kernel/src/DateAndTime.cpp index 1e3b63eec9a..249e3035bb6 100644 --- a/Framework/Kernel/src/DateAndTime.cpp +++ b/Framework/Kernel/src/DateAndTime.cpp @@ -863,9 +863,9 @@ void DateAndTime::createVector(const DateAndTime start, size_t num = seconds.size(); out.resize(num); size_t i = 0; - for (auto it = seconds.begin(); it != seconds.end(); ++it) { + for (double second : seconds) { out[i]._nanoseconds = - startnano + static_cast<int64_t>((*it) * 1000000000.0); + startnano + static_cast<int64_t>(second * 1000000000.0); i++; } } diff --git a/Framework/Kernel/src/DeltaEMode.cpp b/Framework/Kernel/src/DeltaEMode.cpp index 36fbaaea23f..f655322c5a8 100644 --- a/Framework/Kernel/src/DeltaEMode.cpp +++ b/Framework/Kernel/src/DeltaEMode.cpp @@ -35,10 +35,10 @@ const std::vector<std::string> DeltaEMode::availableTypes() { std::vector<std::string> modes; modes.reserve(lookup.index.size()); size_t index(0); - for (auto iter = lookup.index.begin(); iter != lookup.index.end(); ++iter) { - if (iter->first == DeltaEMode::Undefined) + for (const auto &iter : lookup.index) { + if (iter.first == DeltaEMode::Undefined) continue; - modes.push_back(iter->second); + modes.push_back(iter.second); ++index; } return modes; @@ -68,10 +68,10 @@ std::string DeltaEMode::asString(const Type mode) { */ DeltaEMode::Type DeltaEMode::fromString(const std::string &modeStr) { const ModeIndex &lookup = typeStringLookup(); - for (auto iter = lookup.index.begin(); iter != lookup.index.end(); ++iter) { - if (boost::iequals(modeStr, iter->second)) // case-insensitive + for (const auto &iter : lookup.index) { + if (boost::iequals(modeStr, iter.second)) // case-insensitive { - return iter->first; + return iter.first; } } // Unknown mode diff --git a/Framework/Kernel/src/FacilityInfo.cpp b/Framework/Kernel/src/FacilityInfo.cpp index e652d906647..57f20506318 100644 --- a/Framework/Kernel/src/FacilityInfo.cpp +++ b/Framework/Kernel/src/FacilityInfo.cpp @@ -74,8 +74,8 @@ void FacilityInfo::fillExtensions(const Poco::XML::Element *elem) { typedef Poco::StringTokenizer tokenizer; tokenizer exts(extsStr, ",", tokenizer::TOK_IGNORE_EMPTY | tokenizer::TOK_TRIM); - for (auto it = exts.begin(); it != exts.end(); ++it) { - addExtension(*it); + for (const auto &ext : exts) { + addExtension(ext); } } @@ -190,22 +190,25 @@ const InstrumentInfo &FacilityInfo::instrument(std::string iName) const { } } - for (auto it = m_instruments.cbegin(); it != m_instruments.cend(); ++it) { - if (boost::iequals(it->name(), iName)) // Case-insensitive search + for (const auto &m_instrument : m_instruments) { + if (boost::iequals(m_instrument.name(), iName)) // Case-insensitive search { - g_log.debug() << "Instrument '" << iName << "' found as " << it->name() - << " at " << name() << "." << std::endl; - return *it; + g_log.debug() << "Instrument '" << iName << "' found as " + << m_instrument.name() << " at " << name() << "." + << std::endl; + return m_instrument; } } // if unsuccessful try shortname - for (auto it = m_instruments.begin(); it != m_instruments.end(); ++it) { - if (boost::iequals(it->shortName(), iName)) // Case-insensitive search + for (const auto &m_instrument : m_instruments) { + if (boost::iequals(m_instrument.shortName(), + iName)) // Case-insensitive search { - g_log.debug() << "Instrument '" << iName << "' found as " << it->name() - << " at " << name() << "." << std::endl; - return *it; + g_log.debug() << "Instrument '" << iName << "' found as " + << m_instrument.name() << " at " << name() << "." + << std::endl; + return m_instrument; } } diff --git a/Framework/Kernel/src/FileValidator.cpp b/Framework/Kernel/src/FileValidator.cpp index ed0ed61793d..385615aae32 100644 --- a/Framework/Kernel/src/FileValidator.cpp +++ b/Framework/Kernel/src/FileValidator.cpp @@ -21,8 +21,8 @@ FileValidator::FileValidator(const std::vector<std::string> &extensions, bool testFileExists, bool testCanWrite) : TypedValidator<std::string>(), m_testExist(testFileExists), m_testCanWrite(testCanWrite) { - for (auto it = extensions.begin(); it != extensions.end(); ++it) { - const std::string ext = boost::to_lower_copy(*it); + for (const auto &extension : extensions) { + const std::string ext = boost::to_lower_copy(extension); if (std::find(m_extensions.begin(), m_extensions.end(), ext) == m_extensions.end()) { m_extensions.push_back(ext); @@ -66,9 +66,8 @@ std::string FileValidator::checkValidity(const std::string &value) const { g_log.debug() << "Unrecognised extension in file \"" << value << "\""; if (!this->m_extensions.empty()) { g_log.debug() << " [ "; - for (auto it = this->m_extensions.begin(); - it != this->m_extensions.end(); ++it) - g_log.debug() << *it << " "; + for (const auto &m_extension : this->m_extensions) + g_log.debug() << m_extension << " "; g_log.debug() << "]"; } g_log.debug() << "\"." << std::endl; @@ -166,10 +165,10 @@ bool FileValidator::endswith(const std::string &value) const { tolower); // check for the ending - for (auto it = m_extensions.begin(); it != m_extensions.end(); ++it) { - if (has_ending(value, *it)) // original case + for (const auto &m_extension : m_extensions) { + if (has_ending(value, m_extension)) // original case return true; - if (has_ending(value_copy, *it)) // lower case + if (has_ending(value_copy, m_extension)) // lower case return true; } return false; diff --git a/Framework/Kernel/src/FilterChannel.cpp b/Framework/Kernel/src/FilterChannel.cpp index c6dab197e19..7274a66c9ab 100644 --- a/Framework/Kernel/src/FilterChannel.cpp +++ b/Framework/Kernel/src/FilterChannel.cpp @@ -25,8 +25,8 @@ void FilterChannel::setProperty(const std::string &name, if (name.compare(0, 7, "channel") == 0) { StringTokenizer tokenizer(value, ",;", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); - for (auto it = tokenizer.begin(); it != tokenizer.end(); ++it) { - addChannel(LoggingRegistry::defaultRegistry().channelForName(*it)); + for (const auto &it : tokenizer) { + addChannel(LoggingRegistry::defaultRegistry().channelForName(it)); } } else if (name.compare(0, 5, "level") == 0) { setPriority(value); diff --git a/Framework/Kernel/src/IPropertyManager.cpp b/Framework/Kernel/src/IPropertyManager.cpp index e6458d0d02a..5d2b8ed774e 100644 --- a/Framework/Kernel/src/IPropertyManager.cpp +++ b/Framework/Kernel/src/IPropertyManager.cpp @@ -72,10 +72,10 @@ bool IPropertyManager::existsProperty(const std::string &name) const { */ void IPropertyManager::updatePropertyValues(const IPropertyManager &other) { auto props = this->getProperties(); - for (auto prop = props.begin(); prop != props.end(); ++prop) { - const std::string propName = (**prop).name(); + for (auto &prop : props) { + const std::string propName = (*prop).name(); if (other.existsProperty(propName)) { - (**prop).setValueFromProperty(*other.getPointerToProperty(propName)); + (*prop).setValueFromProperty(*other.getPointerToProperty(propName)); } } } diff --git a/Framework/Kernel/src/InternetHelper.cpp b/Framework/Kernel/src/InternetHelper.cpp index 09cf0b15931..556ea0bd597 100644 --- a/Framework/Kernel/src/InternetHelper.cpp +++ b/Framework/Kernel/src/InternetHelper.cpp @@ -108,9 +108,8 @@ void InternetHelper::createRequest(Poco::URI &uri) { m_request->setContentLength(m_contentLength); } - for (auto itHeaders = m_headers.begin(); itHeaders != m_headers.end(); - ++itHeaders) { - m_request->set(itHeaders->first, itHeaders->second); + for (auto &m_header : m_headers) { + m_request->set(m_header.first, m_header.second); } if (m_method == "POST") { diff --git a/Framework/Kernel/src/LibraryManager.cpp b/Framework/Kernel/src/LibraryManager.cpp index 51ef6c4523f..4a70b0ab72d 100644 --- a/Framework/Kernel/src/LibraryManager.cpp +++ b/Framework/Kernel/src/LibraryManager.cpp @@ -89,8 +89,8 @@ bool LibraryManagerImpl::skip(const std::string &filename) { initialized = true; } bool skipme(false); - for (auto itr = excludes.begin(); itr != excludes.end(); ++itr) { - if (filename.find(*itr) != std::string::npos) { + for (const auto &exclude : excludes) { + if (filename.find(exclude) != std::string::npos) { skipme = true; break; } diff --git a/Framework/Kernel/src/MDAxisValidator.cpp b/Framework/Kernel/src/MDAxisValidator.cpp index eb6de782088..61766b64848 100644 --- a/Framework/Kernel/src/MDAxisValidator.cpp +++ b/Framework/Kernel/src/MDAxisValidator.cpp @@ -13,8 +13,8 @@ MDAxisValidator::MDAxisValidator(const std::vector<int> &axes, const size_t nDimensions, const bool checkIfEmpty) : m_wsDimensions(nDimensions), m_emptyCheck(checkIfEmpty) { - for (auto iter = axes.begin(); iter != axes.end(); iter++) { - m_axes.push_back(*iter); + for (int axe : axes) { + m_axes.push_back(axe); } } diff --git a/Framework/Kernel/src/MultiFileNameParser.cpp b/Framework/Kernel/src/MultiFileNameParser.cpp index 91665c120ff..fc6adf14714 100644 --- a/Framework/Kernel/src/MultiFileNameParser.cpp +++ b/Framework/Kernel/src/MultiFileNameParser.cpp @@ -153,8 +153,8 @@ std::string suggestWorkspaceName(const std::vector<std::string> &fileNames) { // For each file name, parse the run number out of it, and add it to a // RunRangeList. - for (size_t i = 0; i < fileNames.size(); ++i) { - parser.parse(fileNames[i]); + for (const auto &fileName : fileNames) { + parser.parse(fileName); runs.addRun(parser.runs()[0][0]); } @@ -198,15 +198,12 @@ Parser::Parser() ConfigServiceImpl &config = ConfigService::Instance(); auto facilities = config.getFacilities(); - for (auto itFacility = facilities.begin(); itFacility != facilities.end(); - ++itFacility) { - const std::vector<InstrumentInfo> instruments = - (**itFacility).instruments(); - - for (auto instrument = instruments.begin(); instrument != instruments.end(); - ++instrument) { - m_validInstNames.insert(instrument->name()); - m_validInstNames.insert(instrument->shortName()); + for (auto &facilitie : facilities) { + const std::vector<InstrumentInfo> instruments = (*facilitie).instruments(); + + for (const auto &instrument : instruments) { + m_validInstNames.insert(instrument.name()); + m_validInstNames.insert(instrument.shortName()); } } } @@ -300,11 +297,10 @@ void Parser::split() { throw std::runtime_error("There does not appear to be any runs present."); // See if the user has typed in one of the available instrument names. - for (auto instName = m_validInstNames.begin(); - instName != m_validInstNames.end(); ++instName) { + for (const auto &m_validInstName : m_validInstNames) { // USE CASELESS MATCHES HERE. - if (matchesFully(base, *instName + ".*", true)) { - m_instString = getMatchingString("^" + *instName, base, true); + if (matchesFully(base, m_validInstName + ".*", true)) { + m_instString = getMatchingString("^" + m_validInstName, base, true); break; } } diff --git a/Framework/Kernel/src/MultiFileValidator.cpp b/Framework/Kernel/src/MultiFileValidator.cpp index 97e01e88400..cd779904e60 100644 --- a/Framework/Kernel/src/MultiFileValidator.cpp +++ b/Framework/Kernel/src/MultiFileValidator.cpp @@ -56,18 +56,17 @@ std::string MultiFileValidator::checkValidity( std::string accumulatedErrors(""); - for (auto rowIt = values.cbegin(); rowIt != values.cend(); ++rowIt) { - std::vector<std::string> row = (*rowIt); - for (auto valueIt = row.cbegin(); valueIt != row.cend(); ++valueIt) { + for (auto row : values) { + for (const auto &valueIt : row) { // For each filename value, check its validity, and and accumulate any // errors. - std::string error = m_fileValidator.isValid(*valueIt); + std::string error = m_fileValidator.isValid(valueIt); if (!error.empty()) { if (accumulatedErrors.empty()) accumulatedErrors = - "Could not validate the following file(s): " + (*valueIt); + "Could not validate the following file(s): " + valueIt; else - accumulatedErrors = accumulatedErrors + ", " + (*valueIt); + accumulatedErrors = accumulatedErrors + ", " + valueIt; } } } diff --git a/Framework/Kernel/src/NetworkProxyOSX.cpp b/Framework/Kernel/src/NetworkProxyOSX.cpp index 1db21340e15..71328a0e45e 100644 --- a/Framework/Kernel/src/NetworkProxyOSX.cpp +++ b/Framework/Kernel/src/NetworkProxyOSX.cpp @@ -216,11 +216,11 @@ ProxyInfo findHttpProxy(const std::string &targetURLString, ProxyInfoVec info = proxyInformationFromPac(dict, targetURLString, logger); bool foundHttpProxy = false; - for (auto it = info.begin(); it != info.end(); ++it) { - ProxyInfo proxyInfo = *it; + for (auto &it : info) { + ProxyInfo proxyInfo = it; if (proxyInfo.isHttpProxy()) { foundHttpProxy = true; - httpProxy = *it; + httpProxy = it; break; } } diff --git a/Framework/Kernel/src/NexusDescriptor.cpp b/Framework/Kernel/src/NexusDescriptor.cpp index f05232f4cb5..611e8001f9f 100644 --- a/Framework/Kernel/src/NexusDescriptor.cpp +++ b/Framework/Kernel/src/NexusDescriptor.cpp @@ -235,8 +235,8 @@ void NexusDescriptor::walkFile(::NeXus::File &file, const std::string &rootPath, } if (level == 0) { auto attrInfos = file.getAttrInfos(); - for (size_t i = 0; i < attrInfos.size(); ++i) { - m_rootAttrs.insert(attrInfos[i].name); + for (auto &attrInfo : attrInfos) { + m_rootAttrs.insert(attrInfo.name); } } diff --git a/Framework/Kernel/src/OptionalBool.cpp b/Framework/Kernel/src/OptionalBool.cpp index b3bd37ae4e8..43fcd423e1a 100644 --- a/Framework/Kernel/src/OptionalBool.cpp +++ b/Framework/Kernel/src/OptionalBool.cpp @@ -61,8 +61,8 @@ std::map<std::string, OptionalBool::Value> OptionalBool::strToEmumMap() { std::map<OptionalBool::Value, std::string> OptionalBool::enumToStrMap() { std::map<Value, std::string> map; auto opposite = strToEmumMap(); - for (auto it = opposite.begin(); it != opposite.end(); ++it) { - map.insert(std::make_pair(it->second, it->first)); + for (auto &it : opposite) { + map.insert(std::make_pair(it.second, it.first)); } return map; } diff --git a/Framework/Kernel/src/PropertyManager.cpp b/Framework/Kernel/src/PropertyManager.cpp index 5641fe152c7..3048ccd01da 100644 --- a/Framework/Kernel/src/PropertyManager.cpp +++ b/Framework/Kernel/src/PropertyManager.cpp @@ -41,8 +41,8 @@ PropertyManager::PropertyManager(const PropertyManager &other) PropertyManager &PropertyManager::operator=(const PropertyManager &other) { // We need to do a deep copy here if (this != &other) { - for (auto it = m_properties.begin(); it != m_properties.end(); ++it) { - delete it->second; + for (auto &m_propertie : m_properties) { + delete m_propertie.second; } this->m_properties.clear(); this->m_orderedProperties.resize(other.m_orderedProperties.size()); @@ -162,15 +162,14 @@ void PropertyManager::filterByProperty( const Kernel::TimeSeriesProperty<bool> &filter) { const bool transferOwnership( true); // Make the new FilteredProperty own the original time series - for (auto iter = m_orderedProperties.begin(); - iter != m_orderedProperties.end(); ++iter) { - Property *currentProp = *iter; + for (auto &m_orderedPropertie : m_orderedProperties) { + Property *currentProp = m_orderedPropertie; if (auto doubleSeries = dynamic_cast<TimeSeriesProperty<double> *>(currentProp)) { auto filtered = new FilteredTimeSeriesProperty<double>( doubleSeries, filter, transferOwnership); // Replace the property in the ordered properties list - (*iter) = filtered; + m_orderedPropertie = filtered; // Now replace in the map const std::string key = createKey(currentProp->name()); this->m_properties[key] = filtered; @@ -402,12 +401,12 @@ bool PropertyManager::existsProperty(const std::string &name) const { */ bool PropertyManager::validateProperties() const { bool allValid = true; - for (auto it = m_properties.cbegin(); it != m_properties.cend(); ++it) { + for (const auto &m_propertie : m_properties) { // check for errors in each property - std::string error = it->second->isValid(); + std::string error = m_propertie.second->isValid(); //"" means no error if (!error.empty()) { - g_log.error() << "Property \"" << it->first + g_log.error() << "Property \"" << m_propertie.first << "\" is not set to a valid value: \"" << error << "\"." << std::endl; allValid = false; @@ -575,8 +574,8 @@ void PropertyManager::removeProperty(const std::string &name, */ void PropertyManager::clear() { m_orderedProperties.clear(); - for (auto it = m_properties.begin(); it != m_properties.end(); ++it) { - delete it->second; + for (auto &m_propertie : m_properties) { + delete m_propertie.second; } m_properties.clear(); } diff --git a/Framework/Kernel/src/StartsWithValidator.cpp b/Framework/Kernel/src/StartsWithValidator.cpp index bdd4660a4f5..e0bb77dfba8 100644 --- a/Framework/Kernel/src/StartsWithValidator.cpp +++ b/Framework/Kernel/src/StartsWithValidator.cpp @@ -12,8 +12,8 @@ namespace Kernel { * any of the allowed values" */ std::string StartsWithValidator::checkValidity(const std::string &value) const { - for (auto it = m_allowedValues.begin(); it != m_allowedValues.end(); ++it) { - if (value.substr(0, it->size()) == *it) { + for (const auto &m_allowedValue : m_allowedValues) { + if (value.substr(0, m_allowedValue.size()) == m_allowedValue) { return ""; } } diff --git a/Framework/Kernel/src/Strings.cpp b/Framework/Kernel/src/Strings.cpp index 2709e53c535..18bcd33faf0 100644 --- a/Framework/Kernel/src/Strings.cpp +++ b/Framework/Kernel/src/Strings.cpp @@ -266,10 +266,10 @@ int getPartLine(std::istream &fh, std::string &Out, std::string &Excess, std::string removeSpace(const std::string &CLine) { std::string Out; char prev = 'x'; - for (unsigned int i = 0; i < CLine.length(); i++) { - if (!isspace(CLine[i]) || prev == '\\') { - Out += CLine[i]; - prev = CLine[i]; + for (char i : CLine) { + if (!isspace(i) || prev == '\\') { + Out += i; + prev = i; } } return Out; @@ -439,8 +439,8 @@ splitToKeyValues(const std::string &input, const std::string &keyValSep, const int splitOptions = Poco::StringTokenizer::TOK_IGNORE_EMPTY + Poco::StringTokenizer::TOK_TRIM; Poco::StringTokenizer listSplitter(input, listSep); - for (auto iter = listSplitter.begin(); iter != listSplitter.end(); ++iter) { - Poco::StringTokenizer keyValSplitter(*iter, keyValSep, splitOptions); + for (const auto &iter : listSplitter) { + Poco::StringTokenizer keyValSplitter(iter, keyValSep, splitOptions); if (keyValSplitter.count() == 2) { keyValues[keyValSplitter[0]] = keyValSplitter[1]; } @@ -1075,9 +1075,9 @@ std::vector<int> parseRange(const std::string &str, const std::string &elemSep, // Estimation of the resulting number of elements result.reserve(elements->count()); - for (auto it = elements->begin(); it != elements->end(); it++) { + for (const auto &it : *elements) { // See above for the reason space is added - Tokenizer rangeElements(*it + " ", rangeSep, Tokenizer::TOK_TRIM); + Tokenizer rangeElements(it + " ", rangeSep, Tokenizer::TOK_TRIM); size_t noOfRangeElements = rangeElements.count(); @@ -1085,7 +1085,7 @@ std::vector<int> parseRange(const std::string &str, const std::string &elemSep, if (noOfRangeElements == 1) { int element; if (convert(rangeElements[0], element) != 1) - throw std::invalid_argument("Invalid element: " + *it); + throw std::invalid_argument("Invalid element: " + it); result.push_back(element); } // A pair @@ -1094,17 +1094,17 @@ std::vector<int> parseRange(const std::string &str, const std::string &elemSep, if (convert(rangeElements[0], start) != 1 || convert(rangeElements[1], end) != 1) - throw std::invalid_argument("Invalid range: " + *it); + throw std::invalid_argument("Invalid range: " + it); if (start >= end) - throw std::invalid_argument("Range boundaries are reversed: " + *it); + throw std::invalid_argument("Range boundaries are reversed: " + it); for (int i = start; i <= end; i++) result.push_back(i); } // Error - e.g. "--"" else { - throw std::invalid_argument("Multiple range separators: " + *it); + throw std::invalid_argument("Multiple range separators: " + it); } } diff --git a/Framework/Kernel/src/ThreadPool.cpp b/Framework/Kernel/src/ThreadPool.cpp index 43115fc93d7..0fae8b1f7ea 100644 --- a/Framework/Kernel/src/ThreadPool.cpp +++ b/Framework/Kernel/src/ThreadPool.cpp @@ -78,10 +78,10 @@ void ThreadPool::start(double waitSec) { throw std::runtime_error("Threads have already started."); // Delete any old threads (they should NOT be running!) - for (size_t i = 0; i < m_threads.size(); ++i) - delete m_threads[i]; - for (size_t i = 0; i < m_runnables.size(); ++i) - delete m_runnables[i]; + for (auto &m_thread : m_threads) + delete m_thread; + for (auto &m_runnable : m_runnables) + delete m_runnable; // Now, launch that many threads and let them wait for new tasks. m_threads.clear(); @@ -143,8 +143,8 @@ void ThreadPool::joinAll() { if (m_started) { m_started = false; // If any of the threads are running, then YES, it is really started. - for (size_t i = 0; i < m_threads.size(); ++i) - m_started = m_started || m_threads[i]->isRunning(); + for (auto &m_thread : m_threads) + m_started = m_started || m_thread->isRunning(); } // Start all the threads if they were not already. @@ -152,21 +152,21 @@ void ThreadPool::joinAll() { this->start(); // Clear any wait times so that the threads stop waiting for new tasks. - for (size_t i = 0; i < m_runnables.size(); i++) - m_runnables[i]->clearWait(); + for (auto &m_runnable : m_runnables) + m_runnable->clearWait(); // Sequentially join all the threads. - for (size_t i = 0; i < m_threads.size(); i++) { - m_threads[i]->join(); - delete m_threads[i]; + for (auto &m_thread : m_threads) { + m_thread->join(); + delete m_thread; } // Clear the vectors (the threads are deleted now). m_threads.clear(); // Get rid of the runnables too - for (size_t i = 0; i < m_runnables.size(); i++) - delete m_runnables[i]; + for (auto &m_runnable : m_runnables) + delete m_runnable; m_runnables.clear(); // This will make threads restart diff --git a/Framework/Kernel/src/TimeSeriesProperty.cpp b/Framework/Kernel/src/TimeSeriesProperty.cpp index 3029ef935c9..7f9507a27a4 100644 --- a/Framework/Kernel/src/TimeSeriesProperty.cpp +++ b/Framework/Kernel/src/TimeSeriesProperty.cpp @@ -343,8 +343,7 @@ void TimeSeriesProperty<TYPE>::filterByTimes( << " Original MP Size = " << m_values.size() << "\n"; // 4. Create new - for (size_t isp = 0; isp < splittervec.size(); ++isp) { - Kernel::SplittingInterval splitter = splittervec[isp]; + for (auto splitter : splittervec) { Kernel::DateAndTime t_start = splitter.start(); Kernel::DateAndTime t_stop = splitter.stop(); @@ -752,16 +751,16 @@ double TimeSeriesProperty<TYPE>::averageValueInFilter( double numerator(0.0), totalTime(0.0); // Loop through the filter ranges - for (auto it = filter.cbegin(); it != filter.cend(); ++it) { + for (const auto &it : filter) { // Calculate the total time duration (in seconds) within by the filter - totalTime += it->duration(); + totalTime += it.duration(); // Get the log value and index at the start time of the filter int index; - double value = getSingleValue(it->start(), index); - DateAndTime startTime = it->start(); + double value = getSingleValue(it.start(), index); + DateAndTime startTime = it.start(); - while (index < realSize() - 1 && m_values[index + 1].time() < it->stop()) { + while (index < realSize() - 1 && m_values[index + 1].time() < it.stop()) { ++index; numerator += DateAndTime::secondsFromDuration(m_values[index].time() - startTime) * @@ -772,7 +771,7 @@ double TimeSeriesProperty<TYPE>::averageValueInFilter( // Now close off with the end of the current filter range numerator += - DateAndTime::secondsFromDuration(it->stop() - startTime) * value; + DateAndTime::secondsFromDuration(it.stop() - startTime) * value; } // 'Normalise' by the total time diff --git a/Framework/Kernel/src/VMD.cpp b/Framework/Kernel/src/VMD.cpp index 432a4161c98..a7d95857a23 100644 --- a/Framework/Kernel/src/VMD.cpp +++ b/Framework/Kernel/src/VMD.cpp @@ -43,8 +43,8 @@ VMDBase<TYPE>::makeVectorsOrthogonal(std::vector<VMDBase> &vectors) { out = V3D::makeVectorsOrthogonal(in); std::vector<VMDBase> retVal; - for (size_t i = 0; i < out.size(); i++) - retVal.push_back(VMDBase(out[i])); + for (auto &i : out) + retVal.push_back(VMDBase(i)); return retVal; } diff --git a/Framework/Kernel/src/VectorHelper.cpp b/Framework/Kernel/src/VectorHelper.cpp index 914a2d86cb8..a8b27f440a2 100644 --- a/Framework/Kernel/src/VectorHelper.cpp +++ b/Framework/Kernel/src/VectorHelper.cpp @@ -451,10 +451,10 @@ std::vector<NumT> splitStringIntoVector(std::string listString) { split_vector_type strs; boost::split(strs, listString, boost::is_any_of(", ")); - for (auto it = strs.begin(); it != strs.end(); ++it) { - if (!it->empty()) { + for (auto &str : strs) { + if (!str.empty()) { // String not empty - std::stringstream oneNumber(*it); + std::stringstream oneNumber(str); NumT num; oneNumber >> num; values.push_back(num); -- GitLab