From 08088625620bbb6b8a39fbe378138b41158fd577 Mon Sep 17 00:00:00 2001 From: David Fairbrother <DavidFair@users.noreply.github.com> Date: Thu, 19 Mar 2020 16:35:24 +0000 Subject: [PATCH] Hand-fix some cppcheck warnings Hand-fixes some cppcheck warnings, this was work prior to fixing the cppcheck target. --- Framework/API/src/Algorithm.cpp | 1 + Framework/API/src/CatalogManager.cpp | 8 +++++--- Framework/API/src/CompositeDomainMD.cpp | 9 ++++++++- Framework/API/src/ExperimentInfo.cpp | 6 ++++-- Framework/API/src/IFunction.cpp | 7 ++++--- Framework/API/src/IndexProperty.cpp | 1 + Framework/API/src/MatrixWorkspace.cpp | 11 +++++++---- Framework/API/src/ParameterTie.cpp | 5 ++--- Framework/API/src/WorkspaceGroup.cpp | 8 +++++--- Framework/API/test/MultiDomainFunctionTest.h | 6 +++--- Framework/Algorithms/src/AddLogDerivative.cpp | 5 +++-- .../Algorithms/src/CalculateDynamicRange.cpp | 6 +++--- .../src/CalculatePlaczekSelfScattering.cpp | 13 ++++++++----- Framework/Algorithms/src/ChangeBinOffset.cpp | 4 ++-- Framework/Algorithms/src/ChangeTimeZero.cpp | 11 +++++------ .../Algorithms/src/ConvertSpectrumAxis2.cpp | 7 ++++--- .../Algorithms/src/CorelliCrossCorrelate.cpp | 5 +++-- .../Algorithms/src/CreateDummyCalFile.cpp | 12 +++--------- .../Algorithms/src/CreateLogPropertyTable.cpp | 9 ++++++--- .../Algorithms/src/EQSANSCorrectFrame.cpp | 6 +++--- .../Algorithms/src/MagFormFactorCorrection.cpp | 8 +++++--- .../src/MaxEnt/MaxentTransformMultiFourier.cpp | 4 +--- Framework/Algorithms/src/ModeratorTzero.cpp | 6 +++--- .../Algorithms/src/PaddingAndApodization.cpp | 1 - .../Algorithms/src/PointByPointVCorrection.cpp | 8 ++++---- .../src/PolarizationCorrectionWildes.cpp | 17 +++++++++++++++++ .../src/ReflectometryReductionOne2.cpp | 2 +- Framework/Algorithms/src/ResetNegatives.cpp | 6 +++--- Framework/Algorithms/src/SmoothData.cpp | 9 +++++---- Framework/Algorithms/src/Stitch1DMany.cpp | 6 ++++-- .../Crystal/src/FindUBUsingIndexedPeaks.cpp | 6 +++--- Framework/Crystal/src/LoadIsawPeaks.cpp | 2 -- Framework/Crystal/src/LoadIsawSpectrum.cpp | 1 - Framework/Crystal/src/PeakAlgorithmHelpers.cpp | 11 +++++------ Framework/Crystal/src/SaveIsawPeaks.cpp | 1 - .../Crystal/src/SetSpecialCoordinates.cpp | 4 ++-- .../src/Algorithms/EstimateFitParameters.cpp | 9 ++++----- .../Algorithms/PlotPeakByLogValueHelper.cpp | 1 - .../src/Algorithms/QENSFitSequential.cpp | 11 ++++++----- .../src/Algorithms/SplineSmoothing.cpp | 9 +++++---- .../src/AugmentedLagrangianOptimizer.cpp | 6 +++--- .../src/CostFunctions/CostFuncFitting.cpp | 2 -- .../Functions/CrystalFieldMultiSpectrum.cpp | 8 +++++--- Framework/CurveFitting/src/GSLVector.cpp | 10 ++++------ .../src/TableWorkspaceDomainCreator.cpp | 2 -- .../DataHandling/src/DataBlockComposite.cpp | 9 ++++++--- Framework/DataHandling/src/GroupDetectors2.cpp | 18 ++++++------------ Framework/Kernel/test/CowPtrTest.h | 5 ++--- 48 files changed, 174 insertions(+), 148 deletions(-) diff --git a/Framework/API/src/Algorithm.cpp b/Framework/API/src/Algorithm.cpp index 3420f7b7aff..1bd805d03f9 100644 --- a/Framework/API/src/Algorithm.cpp +++ b/Framework/API/src/Algorithm.cpp @@ -1569,6 +1569,7 @@ void Algorithm::copyNonWorkspaceProperties(IAlgorithm *alg, int periodNum) { const auto &props = this->getProperties(); for (const auto &prop : props) { if (prop) { + auto *wsProp = dynamic_cast<IWorkspaceProperty *>(prop); // Copy the property using the string if (!wsProp) diff --git a/Framework/API/src/CatalogManager.cpp b/Framework/API/src/CatalogManager.cpp index 9dd38cd2f51..e5dd10da271 100644 --- a/Framework/API/src/CatalogManager.cpp +++ b/Framework/API/src/CatalogManager.cpp @@ -7,6 +7,7 @@ #include "MantidAPI/CatalogManager.h" #include "MantidAPI/CatalogFactory.h" #include "MantidAPI/CompositeCatalog.h" +#include "MantidAPI/FunctionFactory.h" #include "MantidKernel/ConfigService.h" #include "MantidKernel/FacilityInfo.h" @@ -105,9 +106,10 @@ void CatalogManagerImpl::destroyCatalog(const std::string &sessionID) { std::vector<CatalogSession_sptr> CatalogManagerImpl::getActiveSessions() { std::vector<CatalogSession_sptr> sessions; sessions.reserve(m_activeCatalogs.size()); - for (const auto &activeCatalog : m_activeCatalogs) { - sessions.emplace_back(activeCatalog.first); - } + + std::transform(m_activeCatalogs.begin(), m_activeCatalogs.end(), + std::back_inserter(sessions), + [](const auto &activeCatalog) { return activeCatalog.first; }); return sessions; } diff --git a/Framework/API/src/CompositeDomainMD.cpp b/Framework/API/src/CompositeDomainMD.cpp index 1a549852bc5..cd4ac347923 100644 --- a/Framework/API/src/CompositeDomainMD.cpp +++ b/Framework/API/src/CompositeDomainMD.cpp @@ -25,7 +25,14 @@ CompositeDomainMD::CompositeDomainMD(IMDWorkspace_const_sptr ws, size_t maxDomainSize) : m_iterator(ws->createIterator()) { m_totalSize = m_iterator->getDataSize(); - size_t nParts = m_totalSize / maxDomainSize + 1; + + size_t maxDomainSizeDiv = maxDomainSize + 1; + if (maxDomainSizeDiv == 0) { + throw std::runtime_error( + "Attempted to use a maximum domain size that equals 0"); + } + size_t nParts = m_totalSize / maxDomainSizeDiv; + m_domains.resize(nParts); for (size_t i = 0; i < nParts - 1; ++i) { size_t start = i * maxDomainSize; diff --git a/Framework/API/src/ExperimentInfo.cpp b/Framework/API/src/ExperimentInfo.cpp index 8b351649ca6..f369dad741b 100644 --- a/Framework/API/src/ExperimentInfo.cpp +++ b/Framework/API/src/ExperimentInfo.cpp @@ -944,8 +944,10 @@ std::vector<std::string> ExperimentInfo::getResourceFilenames( std::vector<std::string> pathNames; if (!matchingFiles.empty()) { pathNames.reserve(matchingFiles.size()); - for (auto &elem : matchingFiles) - pathNames.emplace_back(std::move(elem.second)); + + std::transform(matchingFiles.begin(), matchingFiles.end(), + std::back_inserter(pathNames), + [](const auto &elem) { return elem.second; }); } else { pathNames.emplace_back(std::move(mostRecentFile)); } diff --git a/Framework/API/src/IFunction.cpp b/Framework/API/src/IFunction.cpp index 425ca89b111..848edf8ec09 100644 --- a/Framework/API/src/IFunction.cpp +++ b/Framework/API/src/IFunction.cpp @@ -1361,9 +1361,10 @@ IFunction_sptr IFunction::getFunction(std::size_t) const { std::vector<std::string> IFunction::getAttributeNames() const { std::vector<std::string> names; names.reserve(m_attrs.size()); - for (const auto &attr : m_attrs) { - names.emplace_back(attr.first); - } + + std::transform(m_attrs.begin(), m_attrs.end(), std::back_inserter(names), + [](const auto &attr) { return attr.first; }); + return names; } diff --git a/Framework/API/src/IndexProperty.cpp b/Framework/API/src/IndexProperty.cpp index d3dece74626..e26dd75e507 100644 --- a/Framework/API/src/IndexProperty.cpp +++ b/Framework/API/src/IndexProperty.cpp @@ -75,6 +75,7 @@ Indexing::SpectrumIndexSet IndexProperty::getIndices() const { static_cast<Indexing::SpectrumNumber>(static_cast<int32_t>(max))); } } else { + // cppcheck-suppress constArgument MSVC_DIAG_OFF(4244); switch (type) { case IndexType::WorkspaceIndex: diff --git a/Framework/API/src/MatrixWorkspace.cpp b/Framework/API/src/MatrixWorkspace.cpp index 41d8c4fe152..479adf454d0 100644 --- a/Framework/API/src/MatrixWorkspace.cpp +++ b/Framework/API/src/MatrixWorkspace.cpp @@ -1237,9 +1237,10 @@ MatrixWorkspace::maskedBinsIndices(const size_t &workspaceIndex) const { auto maskedBins = it->second; std::vector<size_t> maskedIds; maskedIds.reserve(maskedBins.size()); - for (const auto &mb : maskedBins) { - maskedIds.emplace_back(mb.first); - } + + std::transform(maskedBins.begin(), maskedBins.end(), + std::back_inserter(maskedIds), + [](const auto &mb) { return mb.first; }); return maskedIds; } @@ -1939,7 +1940,8 @@ MatrixWorkspace::findY(double value, if (std::isnan(value)) { for (int64_t i = idx.first; i < numHists; ++i) { const auto &Y = this->y(i); - // cppcheck-suppress syntaxError + // https://trac.cppcheck.net/ticket/9237 if init buggy with cppcheck + // cppcheck-suppress stlIfFind if (auto it = std::find_if(std::next(Y.begin(), idx.second), Y.end(), [](double v) { return std::isnan(v); }); it != Y.end()) { @@ -1950,6 +1952,7 @@ MatrixWorkspace::findY(double value, } else { for (int64_t i = idx.first; i < numHists; ++i) { const auto &Y = this->y(i); + // cppcheck-suppress stlIfFind if (auto it = std::find(std::next(Y.begin(), idx.second), Y.end(), value); it != Y.end()) { out = {i, std::distance(Y.begin(), it)}; diff --git a/Framework/API/src/ParameterTie.cpp b/Framework/API/src/ParameterTie.cpp index eddfb788399..a3ae0083301 100644 --- a/Framework/API/src/ParameterTie.cpp +++ b/Framework/API/src/ParameterTie.cpp @@ -202,9 +202,8 @@ bool ParameterTie::isConstant() const { return m_varMap.empty(); } std::vector<ParameterReference> ParameterTie::getRHSParameters() const { std::vector<ParameterReference> out; out.reserve(m_varMap.size()); - for (auto &&varPair : m_varMap) { - out.emplace_back(varPair.second); - } + std::transform(m_varMap.begin(), m_varMap.end(), std::back_inserter(out), + [](auto &&varPair) { return varPair.second; }); return out; } diff --git a/Framework/API/src/WorkspaceGroup.cpp b/Framework/API/src/WorkspaceGroup.cpp index a251a3b2ed3..3db1116e68b 100644 --- a/Framework/API/src/WorkspaceGroup.cpp +++ b/Framework/API/src/WorkspaceGroup.cpp @@ -191,9 +191,11 @@ std::vector<std::string> WorkspaceGroup::getNames() const { std::vector<std::string> out; std::lock_guard<std::recursive_mutex> _lock(m_mutex); out.reserve(m_workspaces.size()); - for (const auto &workspace : m_workspaces) { - out.emplace_back(workspace->getName()); - } + + std::transform(m_workspaces.begin(), m_workspaces.end(), + std::back_inserter(out), + [](const auto &ws) { return ws->getName(); }); + return out; } diff --git a/Framework/API/test/MultiDomainFunctionTest.h b/Framework/API/test/MultiDomainFunctionTest.h index 3b87ef057f3..141e3ce8591 100644 --- a/Framework/API/test/MultiDomainFunctionTest.h +++ b/Framework/API/test/MultiDomainFunctionTest.h @@ -336,7 +336,7 @@ public: const FunctionDomain1D &d0 = static_cast<const FunctionDomain1D &>(domain.getDomain(0)); for (size_t i = 0; i < 9; ++i) { - TS_ASSERT_EQUALS(values.getCalculated(i), A + B * d0[i]); + TS_ASSERT_DELTA(values.getCalculated(i), A + B * d0[i], 1e-6); } A = multi.getFunction(0)->getParameter("A") + @@ -346,7 +346,7 @@ public: const FunctionDomain1D &d1 = static_cast<const FunctionDomain1D &>(domain.getDomain(1)); for (size_t i = 9; i < 19; ++i) { - TS_ASSERT_EQUALS(values.getCalculated(i), A + B * d1[i - 9]); + TS_ASSERT_DELTA(values.getCalculated(i), A + B * d1[i - 9], 1e-6); } A = multi.getFunction(0)->getParameter("A") + @@ -356,7 +356,7 @@ public: const FunctionDomain1D &d2 = static_cast<const FunctionDomain1D &>(domain.getDomain(2)); for (size_t i = 19; i < 30; ++i) { - TS_ASSERT_EQUALS(values.getCalculated(i), A + B * d2[i - 19]); + TS_ASSERT_DELTA(values.getCalculated(i), A + B * d2[i - 19], 1e-6); } } diff --git a/Framework/Algorithms/src/AddLogDerivative.cpp b/Framework/Algorithms/src/AddLogDerivative.cpp index 2e9dc599a61..a30db421d65 100644 --- a/Framework/Algorithms/src/AddLogDerivative.cpp +++ b/Framework/Algorithms/src/AddLogDerivative.cpp @@ -103,8 +103,9 @@ Mantid::Kernel::TimeSeriesProperty<double> *AddLogDerivative::makeDerivative( DateAndTime start = input->nthTime(0); std::vector<DateAndTime> timeFull; timeFull.reserve(times.size()); - for (const double time : times) - timeFull.emplace_back(start + time); + + std::transform(times.begin(), times.end(), std::back_inserter(timeFull), + [&start](const double time) { return start + time; }); // Create the TSP out of it auto out = new TimeSeriesProperty<double>(name); diff --git a/Framework/Algorithms/src/CalculateDynamicRange.cpp b/Framework/Algorithms/src/CalculateDynamicRange.cpp index f7a871d6b2c..50e7b95c74e 100644 --- a/Framework/Algorithms/src/CalculateDynamicRange.cpp +++ b/Framework/Algorithms/src/CalculateDynamicRange.cpp @@ -146,9 +146,9 @@ void CalculateDynamicRange::exec() { } if (!dets.empty()) { detIDs.reserve(dets.size()); - for (const auto &det : dets) { - detIDs.emplace_back(det->getID()); - } + std::transform(dets.begin(), dets.end(), std::back_inserter(detIDs), + [](const auto &det) { return det->getID(); }); + const auto indices = workspace->getIndicesFromDetectorIDs(detIDs); calculateQMinMax(workspace, indices, compName); } diff --git a/Framework/Algorithms/src/CalculatePlaczekSelfScattering.cpp b/Framework/Algorithms/src/CalculatePlaczekSelfScattering.cpp index a6cf141beb0..4869be6a5d0 100644 --- a/Framework/Algorithms/src/CalculatePlaczekSelfScattering.cpp +++ b/Framework/Algorithms/src/CalculatePlaczekSelfScattering.cpp @@ -91,7 +91,6 @@ CalculatePlaczekSelfScattering::validateInputs() { void CalculatePlaczekSelfScattering::exec() { const API::MatrixWorkspace_sptr inWS = getProperty("InputWorkspace"); const API::MatrixWorkspace_sptr incidentWS = getProperty("IncidentSpecta"); - API::MatrixWorkspace_sptr outWS = getProperty("OutputWorkspace"); constexpr double factor = 1.0 / 1.66053906660e-27; // atomic mass unit-kilogram relationship constexpr double neutronMass = factor * 1.674927471e-27; // neutron mass @@ -99,11 +98,15 @@ void CalculatePlaczekSelfScattering::exec() { // of each species auto atomSpecies = getSampleSpeciesInfo(inWS); // calculate summation term w/ neutron mass over molecular mass ratio - double summationTerm = 0.0; - for (auto atom : atomSpecies) { - summationTerm += atom.second["concentration"] * atom.second["bSqrdBar"] * + + auto sumLambda = [&neutronMass](double sum, auto &atom) { + return sum + atom.second["concentration"] * atom.second["bSqrdBar"] * neutronMass / atom.second["mass"]; - } + }; + + double summationTerm = + std::accumulate(atomSpecies.begin(), atomSpecies.end(), 0.0, sumLambda); + // get incident spectrum and 1st derivative const MantidVec xLambda = incidentWS->readX(0); const MantidVec incident = incidentWS->readY(0); diff --git a/Framework/Algorithms/src/ChangeBinOffset.cpp b/Framework/Algorithms/src/ChangeBinOffset.cpp index aecd1761eae..869acd987f5 100644 --- a/Framework/Algorithms/src/ChangeBinOffset.cpp +++ b/Framework/Algorithms/src/ChangeBinOffset.cpp @@ -54,8 +54,8 @@ void ChangeBinOffset::exec() { this->for_each<Indices::FromProperty>( *outputW, std::make_tuple(MatrixWorkspaceAccess::x), [offset](std::vector<double> &dataX) { - for (auto &x : dataX) - x += offset; + std::transform(dataX.begin(), dataX.end(), dataX.begin(), + [offset](double x) { return x + offset; }); }); } } diff --git a/Framework/Algorithms/src/ChangeTimeZero.cpp b/Framework/Algorithms/src/ChangeTimeZero.cpp index 83a54079d4d..201a387d5bf 100644 --- a/Framework/Algorithms/src/ChangeTimeZero.cpp +++ b/Framework/Algorithms/src/ChangeTimeZero.cpp @@ -82,12 +82,11 @@ void ChangeTimeZero::exec() { // Set up remaining progress points const double progressStartShiftTimeLogs = progressStopCreateOutputWs; - double progressStopShiftTimeLogs = progressStartShiftTimeLogs; - if (boost::dynamic_pointer_cast<Mantid::API::IEventWorkspace>(out_ws)) { - progressStopShiftTimeLogs = progressStartShiftTimeLogs + 0.1; - } else { - progressStopShiftTimeLogs = 1.0; - } + + double progressStopShiftTimeLogs = + boost::dynamic_pointer_cast<Mantid::API::IEventWorkspace>(out_ws) + ? progressStartShiftTimeLogs + 0.1 + : 1.0; const double progressStartShiftNeutrons = progressStopShiftTimeLogs; const double progressStopShiftNeutrons = 1.0; diff --git a/Framework/Algorithms/src/ConvertSpectrumAxis2.cpp b/Framework/Algorithms/src/ConvertSpectrumAxis2.cpp index eaba2ca93a9..f224599c47a 100644 --- a/Framework/Algorithms/src/ConvertSpectrumAxis2.cpp +++ b/Framework/Algorithms/src/ConvertSpectrumAxis2.cpp @@ -238,9 +238,10 @@ MatrixWorkspace_sptr ConvertSpectrumAxis2::createOutputWorkspace( create<MatrixWorkspace>(*inputWS, m_indexMap.size(), hist); std::vector<double> axis; axis.reserve(m_indexMap.size()); - for (const auto &it : m_indexMap) { - axis.emplace_back(it.first); - } + std::transform(m_indexMap.begin(), m_indexMap.end(), + std::back_inserter(axis), + [](const auto &it) { return it.first; }); + newAxis = std::make_unique<NumericAxis>(std::move(axis)); } else { // If there is no reordering we can simply clone. diff --git a/Framework/Algorithms/src/CorelliCrossCorrelate.cpp b/Framework/Algorithms/src/CorelliCrossCorrelate.cpp index 5ee37f06a77..29162143663 100644 --- a/Framework/Algorithms/src/CorelliCrossCorrelate.cpp +++ b/Framework/Algorithms/src/CorelliCrossCorrelate.cpp @@ -157,8 +157,9 @@ void CorelliCrossCorrelate::exec() { int offset_int = getProperty("TimingOffset"); const auto offset = static_cast<int64_t>(offset_int); - for (auto &timing : tdc) - timing += offset; + + std::transform(tdc.begin(), tdc.end(), tdc.begin(), + [offset](auto timing) { return timing + offset; }); // Determine period from chopper frequency. auto motorSpeed = dynamic_cast<TimeSeriesProperty<double> *>( diff --git a/Framework/Algorithms/src/CreateDummyCalFile.cpp b/Framework/Algorithms/src/CreateDummyCalFile.cpp index 5fd56a26e74..afa35e62f7b 100644 --- a/Framework/Algorithms/src/CreateDummyCalFile.cpp +++ b/Framework/Algorithms/src/CreateDummyCalFile.cpp @@ -110,9 +110,6 @@ void CreateDummyCalFile::exec() { std::string filename = getProperty("CalFilename"); - // Plan to overwrite file, so do not check if it exists - const bool overwrite = false; - int number = 0; Progress prog(this, 0.0, 0.8, assemblies.size()); while (!assemblies.empty()) // Travel the tree from the instrument point @@ -128,12 +125,7 @@ void CreateDummyCalFile::exec() { currentIComp); if (currentDet.get()) // Is detector { - if (overwrite) // Map will contains udet as the key - instrcalib[currentDet->getID()] = - std::make_pair(number++, top_group); - else // Map will contains the entry number as the key - instrcalib[number++] = - std::make_pair(currentDet->getID(), top_group); + instrcalib[number++] = std::make_pair(currentDet->getID(), top_group); } else // Is an assembly, push in the queue { currentchild = @@ -151,6 +143,8 @@ void CreateDummyCalFile::exec() { prog.report(); } // Write the results in a file + // Plan to overwrite file, so do not check if it exists + const bool overwrite = false; saveGroupingFile(filename, overwrite); progress(0.2); } diff --git a/Framework/Algorithms/src/CreateLogPropertyTable.cpp b/Framework/Algorithms/src/CreateLogPropertyTable.cpp index 7b67c9e232b..ab9cda98e38 100644 --- a/Framework/Algorithms/src/CreateLogPropertyTable.cpp +++ b/Framework/Algorithms/src/CreateLogPropertyTable.cpp @@ -195,9 +195,12 @@ retrieveMatrixWsList(const std::vector<std::string> &wsNames, // Retrieve pointers to all the child workspaces. std::vector<MatrixWorkspace_sptr> childWsList; childWsList.reserve(childNames.size()); - for (const auto &childName : childNames) { - childWsList.emplace_back(ADS.retrieveWS<MatrixWorkspace>(childName)); - } + + std::transform(childNames.begin(), childNames.end(), + std::back_inserter(childWsList), + [&ADS](const auto &childName) { + return ADS.retrieveWS<MatrixWorkspace>(childName); + }); // Deal with child workspaces according to policy. switch (groupPolicy) { diff --git a/Framework/Algorithms/src/EQSANSCorrectFrame.cpp b/Framework/Algorithms/src/EQSANSCorrectFrame.cpp index 58b64d47ad6..b7cebbb4dec 100644 --- a/Framework/Algorithms/src/EQSANSCorrectFrame.cpp +++ b/Framework/Algorithms/src/EQSANSCorrectFrame.cpp @@ -95,11 +95,11 @@ void EQSANSCorrectFrame::exec() { double newTOF = tof + m_framesOffsetTime; // TOF values smaller than that of the fastest neutrons have been // 'folded' by the data acquisition system. They must be shifted - double minTOF = m_minTOF * pathToPixelFactor; - if (newTOF < minTOF) + double scaledMinTOF = m_minTOF * pathToPixelFactor; + if (newTOF < scaledMinTOF) newTOF += m_frameWidth; // Events from the skipped pulse are delayed by one pulse period - if (m_isFrameSkipping && newTOF > minTOF + m_pulsePeriod) + if (m_isFrameSkipping && newTOF > scaledMinTOF + m_pulsePeriod) newTOF += m_pulsePeriod; return newTOF; } diff --git a/Framework/Algorithms/src/MagFormFactorCorrection.cpp b/Framework/Algorithms/src/MagFormFactorCorrection.cpp index 5cd00fbdf35..d49836999fc 100644 --- a/Framework/Algorithms/src/MagFormFactorCorrection.cpp +++ b/Framework/Algorithms/src/MagFormFactorCorrection.cpp @@ -96,9 +96,11 @@ void MagFormFactorCorrection::exec() { // Gets the vector of form factor values std::vector<double> FF; FF.reserve(Qvals.size()); - for (double Qval : Qvals) { - FF.emplace_back(ion.analyticalFormFactor(Qval * Qval)); - } + + std::transform( + Qvals.begin(), Qvals.end(), std::back_inserter(FF), + [&ion](double qval) { return ion.analyticalFormFactor(qval * qval); }); + if (!ffwsStr.empty()) { HistogramBuilder builder; builder.setX(Qvals.size()); diff --git a/Framework/Algorithms/src/MaxEnt/MaxentTransformMultiFourier.cpp b/Framework/Algorithms/src/MaxEnt/MaxentTransformMultiFourier.cpp index 19dac6d580f..fe3a9aabcac 100644 --- a/Framework/Algorithms/src/MaxEnt/MaxentTransformMultiFourier.cpp +++ b/Framework/Algorithms/src/MaxEnt/MaxentTransformMultiFourier.cpp @@ -40,9 +40,7 @@ MaxentTransformMultiFourier::imageToData(const std::vector<double> &image) { std::vector<double> data; data.reserve(m_numSpec * dataOneSpec.size()); for (size_t s = 0; s < m_numSpec; s++) { - for (const double &data_item : dataOneSpec) { - data.emplace_back(data_item); - } + std::copy(dataOneSpec.begin(), dataOneSpec.end(), std::back_inserter(data)); } // Apply adjustments (we assume there are sufficient adjustments supplied) diff --git a/Framework/Algorithms/src/ModeratorTzero.cpp b/Framework/Algorithms/src/ModeratorTzero.cpp index 6960ca6d2d9..67e1a3395f1 100644 --- a/Framework/Algorithms/src/ModeratorTzero.cpp +++ b/Framework/Algorithms/src/ModeratorTzero.cpp @@ -354,9 +354,9 @@ void ModeratorTzero::execEvent(const std::string &emode) { evlist.mutableX() -= t0_direct; MantidVec tofs = evlist.getTofs(); - for (double &tof : tofs) { - tof -= t0_direct; - } + + std::transform(tofs.begin(), tofs.end(), tofs.begin(), + [&t0_direct](double tof) { return tof - t0_direct; }); evlist.setTofs(tofs); evlist.setSortOrder(Mantid::DataObjects::EventSortType::UNSORTED); } // end of else if(emode=="Direct") diff --git a/Framework/Algorithms/src/PaddingAndApodization.cpp b/Framework/Algorithms/src/PaddingAndApodization.cpp index a2975167ee4..9aaad011702 100644 --- a/Framework/Algorithms/src/PaddingAndApodization.cpp +++ b/Framework/Algorithms/src/PaddingAndApodization.cpp @@ -115,7 +115,6 @@ void PaddingAndApodization::exec() { fptr apodizationFunction = getApodizationFunction(method); // Do the specified spectra only auto specLength = static_cast<int>(spectra.size()); - std::vector<double> norm(specLength, 0.0); PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS)) for (int i = 0; i < specLength; ++i) { PARALLEL_START_INTERUPT_REGION diff --git a/Framework/Algorithms/src/PointByPointVCorrection.cpp b/Framework/Algorithms/src/PointByPointVCorrection.cpp index ee0591db07a..96fc5e9a6e9 100644 --- a/Framework/Algorithms/src/PointByPointVCorrection.cpp +++ b/Framework/Algorithms/src/PointByPointVCorrection.cpp @@ -125,10 +125,10 @@ void PointByPointVCorrection::exec() { // builds which caused the unit tests // to sometimes fail. Maybe this is some compiler bug to do with // using bind2nd within the parrallel macros. - for (double &rY : resultY) { - // Now result is s_i/v_i*Dlam_i*(sum_i s_i)/(sum_i S_i/v_i*Dlam_i) - rY *= factor; - } + + // Now result is s_i/v_i*Dlam_i*(sum_i s_i)/(sum_i S_i/v_i*Dlam_i) + std::transform(resultY.begin(), resultY.end(), resultY.begin(), + [&factor](double rY) { return rY * factor; }); // Finally get the normalized errors for (int j = 0; j < size - 1; j++) diff --git a/Framework/Algorithms/src/PolarizationCorrectionWildes.cpp b/Framework/Algorithms/src/PolarizationCorrectionWildes.cpp index 8547cdd06f8..4d7d409f427 100644 --- a/Framework/Algorithms/src/PolarizationCorrectionWildes.cpp +++ b/Framework/Algorithms/src/PolarizationCorrectionWildes.cpp @@ -96,21 +96,30 @@ void fourInputsCorrectedAndErrors( const auto diag1 = 1. / f1; const auto off1 = (f1 - 1.) / f1; Eigen::Matrix4d F1m; + // Suppress warnings about suspicious init with Eigen + // cppcheck-suppress constStatement F1m << 1., 0., 0., 0., 0., 1., 0., 0., off1, 0., diag1, 0., 0., off1, 0., diag1; + const auto diag2 = 1. / f2; const auto off2 = (f2 - 1.) / f2; Eigen::Matrix4d F2m; + + // cppcheck-suppress constStatement F2m << 1., 0., 0., 0., off2, diag2, 0., 0., 0., 0., 1., 0., 0., 0., off2, diag2; const auto diag3 = (p1 - 1.) / (2. * p1 - 1.); const auto off3 = p1 / (2. * p1 - 1); Eigen::Matrix4d P1m; + + // cppcheck-suppress constStatement P1m << diag3, 0, off3, 0, 0, diag3, 0, off3, off3, 0, diag3, 0, 0, off3, 0, diag3; const auto diag4 = (p2 - 1.) / (2. * p2 - 1.); const auto off4 = p2 / (2. * p2 - 1.); Eigen::Matrix4d P2m; + + // cppcheck-suppress constStatement P2m << diag4, off4, 0., 0., off4, diag4, 0., 0., 0., 0., diag4, off4, 0., 0., off4, diag4; const Eigen::Vector4d intensities(ppy, pmy, mpy, mmy); @@ -122,18 +131,26 @@ void fourInputsCorrectedAndErrors( // the matrices above, multiplied by the error. const auto elemE1 = -1. / pow<2>(f1) * f1E; Eigen::Matrix4d F1Em; + + // cppcheck-suppress constStatement F1Em << 0., 0., 0., 0., 0., 0., 0., 0., -elemE1, 0., elemE1, 0., 0., -elemE1, 0., elemE1; const auto elemE2 = -1. / pow<2>(f2) * f2E; Eigen::Matrix4d F2Em; + + // cppcheck-suppress constStatement F2Em << 0., 0., 0., 0., -elemE2, elemE2, 0., 0., 0., 0., 0., 0., 0., 0., -elemE2, elemE2; const auto elemE3 = 1. / pow<2>(2. * p1 - 1.) * p1E; Eigen::Matrix4d P1Em; + + // cppcheck-suppress constStatement P1Em << elemE3, 0., -elemE3, 0., 0., elemE3, 0., -elemE3, -elemE3, 0., elemE3, 0., 0., -elemE3, 0., elemE3; const auto elemE4 = 1. / pow<2>(2. * p2 - 1.) * p2E; Eigen::Matrix4d P2Em; + + // cppcheck-suppress constStatement P2Em << elemE4, -elemE4, 0., 0., -elemE4, elemE4, 0., 0., 0., 0., elemE4, -elemE4, 0., 0., -elemE4, elemE4; const Eigen::Vector4d yErrors(ppyE, pmyE, mpyE, mmyE); diff --git a/Framework/Algorithms/src/ReflectometryReductionOne2.cpp b/Framework/Algorithms/src/ReflectometryReductionOne2.cpp index 4a30b192f8a..9f887d7e93c 100644 --- a/Framework/Algorithms/src/ReflectometryReductionOne2.cpp +++ b/Framework/Algorithms/src/ReflectometryReductionOne2.cpp @@ -709,7 +709,7 @@ void ReflectometryReductionOne2::findDetectorGroups() { // Sort the groups by the first spectrum number in the group (to give the same // output order as GroupDetectors) std::sort(m_detectorGroups.begin(), m_detectorGroups.end(), - [](const std::vector<size_t> a, const std::vector<size_t> b) { + [](const std::vector<size_t> &a, const std::vector<size_t> &b) { return a.front() < b.front(); }); diff --git a/Framework/Algorithms/src/ResetNegatives.cpp b/Framework/Algorithms/src/ResetNegatives.cpp index 93fda48e7f8..430b9dc3870 100644 --- a/Framework/Algorithms/src/ResetNegatives.cpp +++ b/Framework/Algorithms/src/ResetNegatives.cpp @@ -151,9 +151,9 @@ void ResetNegatives::pushMinimum(MatrixWorkspace_const_sptr minWS, if (minValue <= 0) { minValue *= -1.; auto &y = wksp->mutableY(i); - for (double &value : y) { - value = fixZero(value + minValue); - } + std::transform(y.begin(), y.end(), y.begin(), [minValue](double value) { + return fixZero(value + minValue); + }); } prog.report(); PARALLEL_END_INTERUPT_REGION diff --git a/Framework/Algorithms/src/SmoothData.cpp b/Framework/Algorithms/src/SmoothData.cpp index b7ed93f3449..8893838585b 100644 --- a/Framework/Algorithms/src/SmoothData.cpp +++ b/Framework/Algorithms/src/SmoothData.cpp @@ -73,11 +73,12 @@ void SmoothData::exec() { int npts = nptsGroup[0]; if (groupWS) { const int group = validateSpectrumInGroup(static_cast<size_t>(i)); - if (group < 0) + if (group == -1) { npts = 3; - else - // group is never 0. We can safely subtract. + } else { + assert(group != 0); npts = nptsGroup[group - 1]; + } } if (npts >= vecSize) { g_log.error("The number of averaging points requested is larger than the " @@ -103,7 +104,7 @@ void SmoothData::exec() { // Set the output workspace to its property setProperty("OutputWorkspace", outputWorkspace); -} +} // namespace Algorithms //============================================================================= /** Verify that all the contributing detectors to a spectrum belongs to the same * group diff --git a/Framework/Algorithms/src/Stitch1DMany.cpp b/Framework/Algorithms/src/Stitch1DMany.cpp index d89ceb8c802..bc582d28486 100644 --- a/Framework/Algorithms/src/Stitch1DMany.cpp +++ b/Framework/Algorithms/src/Stitch1DMany.cpp @@ -269,8 +269,10 @@ void Stitch1DMany::exec() { for (size_t i = 0; i < m_inputWSMatrix.front().size(); ++i) { std::vector<MatrixWorkspace_sptr> inMatrix; inMatrix.reserve(m_inputWSMatrix.size()); - for (const auto &ws : m_inputWSMatrix) - inMatrix.emplace_back(ws[i]); + + std::transform(m_inputWSMatrix.begin(), m_inputWSMatrix.end(), + std::back_inserter(inMatrix), + [i](const auto &ws) { return ws[i]; }); outName = groupName; Workspace_sptr outStitchedWS; diff --git a/Framework/Crystal/src/FindUBUsingIndexedPeaks.cpp b/Framework/Crystal/src/FindUBUsingIndexedPeaks.cpp index 7cbe615d2f9..4d9444bffea 100644 --- a/Framework/Crystal/src/FindUBUsingIndexedPeaks.cpp +++ b/Framework/Crystal/src/FindUBUsingIndexedPeaks.cpp @@ -108,9 +108,9 @@ void FindUBUsingIndexedPeaks::exec() { { // from the full list of peaks, and q_vectors.clear(); // save the UB in the sample q_vectors.reserve(n_peaks); - for (const auto &peak : peaks) { - q_vectors.emplace_back(peak.getQSampleFrame()); - } + + std::transform(peaks.begin(), peaks.end(), std::back_inserter(q_vectors), + [](const auto &peak) { return peak.getQSampleFrame(); }); int num_indexed = IndexingUtils::NumberIndexed(UB, q_vectors, tolerance); int sate_indexed = 0; diff --git a/Framework/Crystal/src/LoadIsawPeaks.cpp b/Framework/Crystal/src/LoadIsawPeaks.cpp index 4ce06b8fed3..4efad112094 100644 --- a/Framework/Crystal/src/LoadIsawPeaks.cpp +++ b/Framework/Crystal/src/LoadIsawPeaks.cpp @@ -67,7 +67,6 @@ int LoadIsawPeaks::confidence(Kernel::FileDescriptor &descriptor) const { throw std::logic_error(std::string("No Version for Peaks file")); getWord(in, false); // tag - // cppcheck-suppress unreadVariable std::string C_Facility = getWord(in, false); getWord(in, false); // tag @@ -142,7 +141,6 @@ std::string LoadIsawPeaks::readHeader(PeaksWorkspace_sptr outWS, throw std::logic_error(std::string("No Version for Peaks file")); getWord(in, false); // tag - // cppcheck-suppress unreadVariable std::string C_Facility = getWord(in, false); getWord(in, false); // tag diff --git a/Framework/Crystal/src/LoadIsawSpectrum.cpp b/Framework/Crystal/src/LoadIsawSpectrum.cpp index 3e24646201a..9263a6de4d3 100644 --- a/Framework/Crystal/src/LoadIsawSpectrum.cpp +++ b/Framework/Crystal/src/LoadIsawSpectrum.cpp @@ -56,7 +56,6 @@ void LoadIsawSpectrum::exec() { const V3D pos = inst->getSource()->getPos() - samplePos; double l1 = pos.norm(); - std::vector<double> spec(11); std::string STRING; std::ifstream infile; std::string spectraFile = getPropertyValue("SpectraFile"); diff --git a/Framework/Crystal/src/PeakAlgorithmHelpers.cpp b/Framework/Crystal/src/PeakAlgorithmHelpers.cpp index 493f447ec2a..6d01489f6c8 100644 --- a/Framework/Crystal/src/PeakAlgorithmHelpers.cpp +++ b/Framework/Crystal/src/PeakAlgorithmHelpers.cpp @@ -200,12 +200,11 @@ generateOffsetVectors(const std::vector<double> &hOffsets, std::vector<MNPOffset> offsets; for (double hOffset : hOffsets) { for (double kOffset : kOffsets) { - for (double lOffset : lOffsets) { - // mnp = 0, 0, 0 as - // it's not quite clear how to interpret them as mnp indices - offsets.emplace_back( - std::make_tuple(0, 0, 0, V3D(hOffset, kOffset, lOffset))); - } + std::transform( + lOffsets.begin(), lOffsets.end(), std::back_inserter(offsets), + [&hOffset, &kOffset](double lOffset) { + return std::make_tuple(0, 0, 0, V3D(hOffset, kOffset, lOffset)); + }); } } return offsets; diff --git a/Framework/Crystal/src/SaveIsawPeaks.cpp b/Framework/Crystal/src/SaveIsawPeaks.cpp index deed32269bb..83d817599b9 100644 --- a/Framework/Crystal/src/SaveIsawPeaks.cpp +++ b/Framework/Crystal/src/SaveIsawPeaks.cpp @@ -318,7 +318,6 @@ void SaveIsawPeaks::exec() { const int run = runBankMap.first; const auto &bankMap = runBankMap.second; - bankMap_t::iterator bankMap_it; for (const auto &bankIDs : bankMap) { // Start of a new bank. const int bank = bankIDs.first; diff --git a/Framework/Crystal/src/SetSpecialCoordinates.cpp b/Framework/Crystal/src/SetSpecialCoordinates.cpp index ec7453d2044..5139e8b13ce 100644 --- a/Framework/Crystal/src/SetSpecialCoordinates.cpp +++ b/Framework/Crystal/src/SetSpecialCoordinates.cpp @@ -95,7 +95,7 @@ void SetSpecialCoordinates::init() { bool SetSpecialCoordinates::writeCoordinatesToMDEventWorkspace( Workspace_sptr inWS, SpecialCoordinateSystem /*unused*/) { bool written = false; - if (auto mdEventWS = boost::dynamic_pointer_cast<IMDEventWorkspace>(inWS)) { + if (boost::dynamic_pointer_cast<IMDEventWorkspace>(inWS)) { g_log.warning("SetSpecialCoordinates: This algorithm cannot set the " "special coordinate system for an MDEvent workspace any " "longer."); @@ -107,7 +107,7 @@ bool SetSpecialCoordinates::writeCoordinatesToMDEventWorkspace( bool SetSpecialCoordinates::writeCoordinatesToMDHistoWorkspace( Workspace_sptr inWS, SpecialCoordinateSystem /*unused*/) { bool written = false; - if (auto mdHistoWS = boost::dynamic_pointer_cast<IMDHistoWorkspace>(inWS)) { + if (boost::dynamic_pointer_cast<IMDHistoWorkspace>(inWS)) { g_log.warning("SetSpecialCoordinates: This algorithm cannot set the " "special coordinate system for an MDHisto workspace any " "longer."); diff --git a/Framework/CurveFitting/src/Algorithms/EstimateFitParameters.cpp b/Framework/CurveFitting/src/Algorithms/EstimateFitParameters.cpp index 00cbc81571d..1c9273de679 100644 --- a/Framework/CurveFitting/src/Algorithms/EstimateFitParameters.cpp +++ b/Framework/CurveFitting/src/Algorithms/EstimateFitParameters.cpp @@ -138,9 +138,8 @@ public: std::vector<GSLVector> getParams() const { std::vector<GSLVector> res; res.reserve(m_params.size()); - for (auto &it : m_params) { - res.emplace_back(it.second); - } + std::transform(m_params.begin(), m_params.end(), std::back_inserter(res), + [](const auto &it) { return it.second; }); return res; } }; @@ -383,12 +382,12 @@ void EstimateFitParameters::execConcrete() { continue; } auto constraint = func->getConstraint(i); - if (constraint == nullptr) { + if (!constraint) { func->fix(i); continue; } auto boundary = dynamic_cast<Constraints::BoundaryConstraint *>(constraint); - if (boundary == nullptr) { + if (!boundary) { throw std::runtime_error("Parameter " + func->parameterName(i) + " must have a boundary constraint. "); } diff --git a/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValueHelper.cpp b/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValueHelper.cpp index 3382a04eaa3..d6c2bfa8721 100644 --- a/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValueHelper.cpp +++ b/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValueHelper.cpp @@ -212,7 +212,6 @@ std::vector<int> getWorkspaceIndicesFromAxes(API::MatrixWorkspace &ws, } } } else { // numeric axis - spectrumNumber = SpecialIndex::NOT_SET; if (workspaceIndex >= 0) { out.clear(); } else { diff --git a/Framework/CurveFitting/src/Algorithms/QENSFitSequential.cpp b/Framework/CurveFitting/src/Algorithms/QENSFitSequential.cpp index 2af32db01fe..dee0ebc28b1 100644 --- a/Framework/CurveFitting/src/Algorithms/QENSFitSequential.cpp +++ b/Framework/CurveFitting/src/Algorithms/QENSFitSequential.cpp @@ -170,9 +170,10 @@ std::vector<MatrixWorkspace_sptr> extractWorkspaces(const std::string &input) { std::vector<MatrixWorkspace_sptr> workspaces; - for (const auto &wsName : workspaceNames) { - workspaces.emplace_back(getADSMatrixWorkspace(wsName)); - } + std::transform(workspaceNames.begin(), workspaceNames.end(), + std::back_inserter(workspaces), [](const auto &wsName) { + return getADSMatrixWorkspace(wsName); + }); return workspaces; } @@ -541,9 +542,9 @@ void QENSFitSequential::exec() { getPropertyValue("OutputWorkspace"), resultWs); if (containsMultipleData(workspaces)) { - const auto inputString = getPropertyValue("Input"); + const auto inputStringProp = getPropertyValue("Input"); renameWorkspaces(groupWs, spectra, outputBaseName, "_Workspace", - extractWorkspaceNames(inputString)); + extractWorkspaceNames(inputStringProp)); } else { renameWorkspaces(groupWs, spectra, outputBaseName, "_Workspace"); } diff --git a/Framework/CurveFitting/src/Algorithms/SplineSmoothing.cpp b/Framework/CurveFitting/src/Algorithms/SplineSmoothing.cpp index b0b09aab49c..dff88dc8f29 100644 --- a/Framework/CurveFitting/src/Algorithms/SplineSmoothing.cpp +++ b/Framework/CurveFitting/src/Algorithms/SplineSmoothing.cpp @@ -306,9 +306,10 @@ void SplineSmoothing::addSmoothingPoints(const std::set<int> &points, std::vector<double> breakPoints; breakPoints.reserve(num_points); // set each of the x and y points to redefine the spline - for (auto const &point : points) { - breakPoints.emplace_back(xs[point]); - } + + std::transform(points.begin(), points.end(), std::back_inserter(breakPoints), + [&xs](const auto &point) { return xs[point]; }); + m_cspline->setAttribute("BreakPoints", API::IFunction::Attribute(breakPoints)); @@ -367,7 +368,7 @@ void SplineSmoothing::selectSmoothingPoints( break; } - } else if (!incBreaks) { + } else { if (smoothPts.size() >= xs.size() - 1) { break; } diff --git a/Framework/CurveFitting/src/AugmentedLagrangianOptimizer.cpp b/Framework/CurveFitting/src/AugmentedLagrangianOptimizer.cpp index edbeff12fe1..2b325168c3c 100644 --- a/Framework/CurveFitting/src/AugmentedLagrangianOptimizer.cpp +++ b/Framework/CurveFitting/src/AugmentedLagrangianOptimizer.cpp @@ -137,7 +137,7 @@ void AugmentedLagrangianOptimizer::minimize(std::vector<double> &xv) const { assert(numParameters() == xv.size()); double ICM(HUGE_VAL), minf_penalty(HUGE_VAL), rho(0.0); - double fcur(0.0), minf(HUGE_VAL), penalty(0.0); + double minf(HUGE_VAL), penalty(0.0); std::vector<double> xcur(xv), lambda(numEqualityConstraints(), 0), mu(numInequalityConstraints()); int minfIsFeasible = 0; @@ -149,7 +149,7 @@ void AugmentedLagrangianOptimizer::minimize(std::vector<double> &xv) const { if (numEqualityConstraints() > 0 || numInequalityConstraints() > 0) { double con2 = 0; - fcur = m_userfunc(numParameters(), xcur.data()); + double fcur = m_userfunc(numParameters(), xcur.data()); int feasible = 1; for (size_t i = 0; i < numEqualityConstraints(); ++i) { double hi = evaluateConstraint(m_eq, i, numParameters(), xcur.data()); @@ -177,7 +177,7 @@ void AugmentedLagrangianOptimizer::minimize(std::vector<double> &xv) const { unconstrainedOptimization(lambda, mu, rho, xcur); - fcur = m_userfunc(numParameters(), xcur.data()); + double fcur = m_userfunc(numParameters(), xcur.data()); ICM = 0.0; penalty = 0.0; int feasible = 1; diff --git a/Framework/CurveFitting/src/CostFunctions/CostFuncFitting.cpp b/Framework/CurveFitting/src/CostFunctions/CostFuncFitting.cpp index d5163767645..07c6a543b7b 100644 --- a/Framework/CurveFitting/src/CostFunctions/CostFuncFitting.cpp +++ b/Framework/CurveFitting/src/CostFunctions/CostFuncFitting.cpp @@ -418,9 +418,7 @@ double CostFuncFitting::valDerivHessian(bool evalDeriv, } } m_dirtyDeriv = false; - } - if (evalDeriv) { if (m_includePenalty) { size_t i = 0; for (size_t ip = 0; ip < np; ++ip) { diff --git a/Framework/CurveFitting/src/Functions/CrystalFieldMultiSpectrum.cpp b/Framework/CurveFitting/src/Functions/CrystalFieldMultiSpectrum.cpp index 2841d4b75ba..2134f11c772 100644 --- a/Framework/CurveFitting/src/Functions/CrystalFieldMultiSpectrum.cpp +++ b/Framework/CurveFitting/src/Functions/CrystalFieldMultiSpectrum.cpp @@ -125,10 +125,12 @@ CrystalFieldMultiSpectrum::CrystalFieldMultiSpectrum() size_t CrystalFieldMultiSpectrum::getNumberDomains() const { if (!m_target) { buildTargetFunction(); + + if (!m_target) { + throw std::runtime_error("Failed to build target function."); + } } - if (!m_target) { - throw std::runtime_error("Failed to build target function."); - } + return m_target->getNumberDomains(); } diff --git a/Framework/CurveFitting/src/GSLVector.cpp b/Framework/CurveFitting/src/GSLVector.cpp index 03f64506103..87bdc8c1f11 100644 --- a/Framework/CurveFitting/src/GSLVector.cpp +++ b/Framework/CurveFitting/src/GSLVector.cpp @@ -168,18 +168,16 @@ GSLVector &GSLVector::operator*=(const GSLVector &v) { /// Multiply by a number /// @param d :: The number GSLVector &GSLVector::operator*=(const double d) { - for (auto &x : m_data) { - x *= d; - } + std::transform(m_data.begin(), m_data.end(), m_data.begin(), + [d](double x) { return x * d; }); return *this; } /// Add a number /// @param d :: The number GSLVector &GSLVector::operator+=(const double d) { - for (auto &x : m_data) { - x += d; - } + std::transform(m_data.begin(), m_data.end(), m_data.begin(), + [d](double x) { return x + d; }); return *this; } diff --git a/Framework/CurveFitting/src/TableWorkspaceDomainCreator.cpp b/Framework/CurveFitting/src/TableWorkspaceDomainCreator.cpp index 566167061b7..ee80a475e4a 100644 --- a/Framework/CurveFitting/src/TableWorkspaceDomainCreator.cpp +++ b/Framework/CurveFitting/src/TableWorkspaceDomainCreator.cpp @@ -174,8 +174,6 @@ void TableWorkspaceDomainCreator::declareDatasetProperties( "(default the highest value of x)"); if (m_domainType != Simple && !m_manager->existsProperty(m_maxSizePropertyName)) { - auto mustBePositive = boost::make_shared<BoundedValidator<int>>(); - mustBePositive->setLower(0); declareProperty( new PropertyWithValue<int>(m_maxSizePropertyName, 1, mustBePositive), "The maximum number of values per a simple domain."); diff --git a/Framework/DataHandling/src/DataBlockComposite.cpp b/Framework/DataHandling/src/DataBlockComposite.cpp index 6560c92166d..e8c7da11196 100644 --- a/Framework/DataHandling/src/DataBlockComposite.cpp +++ b/Framework/DataHandling/src/DataBlockComposite.cpp @@ -208,9 +208,12 @@ std::vector<std::pair<int64_t, int64_t>> spectrumIDIntervals( const std::vector<Mantid::DataHandling::DataBlock> &blocks) { std::vector<std::pair<int64_t, int64_t>> intervals; intervals.reserve(blocks.size()); - for (const auto &block : blocks) { - intervals.emplace_back(block.getMinSpectrumID(), block.getMaxSpectrumID()); - } + + std::transform(blocks.begin(), blocks.end(), std::back_inserter(intervals), + [](const auto &block) { + return std::make_pair(block.getMinSpectrumID(), + block.getMaxSpectrumID()); + }); return intervals; } } // namespace diff --git a/Framework/DataHandling/src/GroupDetectors2.cpp b/Framework/DataHandling/src/GroupDetectors2.cpp index 82af6435fda..366ab1ef5fe 100644 --- a/Framework/DataHandling/src/GroupDetectors2.cpp +++ b/Framework/DataHandling/src/GroupDetectors2.cpp @@ -589,9 +589,7 @@ void GroupDetectors2::processXMLFile(const std::string &fname, if (ind != detIdToWiMap.end()) { size_t wsid = ind->second; wsindexes.emplace_back(wsid); - if (unUsedSpec[wsid] != (USED)) { - unUsedSpec[wsid] = (USED); - } + unUsedSpec[wsid] = (USED); } else { g_log.error() << "Detector with ID " << detid << " is not found in instrument \n"; @@ -615,9 +613,7 @@ void GroupDetectors2::processXMLFile(const std::string &fname, if (ind != specs2index.end()) { size_t wsid = ind->second; wsindexes.emplace_back(wsid); - if (unUsedSpec[wsid] != (USED)) { - unUsedSpec[wsid] = (USED); - } + unUsedSpec[wsid] = (USED); } else { g_log.error() << "Spectrum with ID " << specNum << " is not found in instrument \n"; @@ -649,6 +645,7 @@ void GroupDetectors2::processGroupingWorkspace( size_t groupid = static_cast<int>(groupWS->y(i)[0]); // group 0 is are unused spectra - don't process them if (groupid > 0) { + // cppcheck-suppress stlFindInsert if (group2WSIndexSetmap.find(groupid) == group2WSIndexSetmap.end()) { // not found - create an empty set group2WSIndexSetmap.emplace(groupid, std::set<size_t>()); @@ -662,9 +659,7 @@ void GroupDetectors2::processGroupingWorkspace( detIdToWiMap[detectorIDs[spectrumDefinition.first]]; targetWSIndexSet.insert(targetWSIndex); // mark as used - if (unUsedSpec[targetWSIndex] != (USED)) { - unUsedSpec[targetWSIndex] = (USED); - } + unUsedSpec[targetWSIndex] = (USED); } } } @@ -701,6 +696,7 @@ void GroupDetectors2::processMatrixWorkspace( // read spectra from groupingws size_t groupid = i; + // cppcheck-suppress stlFindInsert if (group2WSIndexSetmap.find(groupid) == group2WSIndexSetmap.end()) { // not found - create an empty set group2WSIndexSetmap.emplace(groupid, std::set<size_t>()); @@ -716,9 +712,7 @@ void GroupDetectors2::processMatrixWorkspace( detIdToWiMap[detectorIDs[spectrumDefinition.first]]; targetWSIndexSet.insert(targetWSIndex); // mark as used - if (unUsedSpec[targetWSIndex] != (USED)) { - unUsedSpec[targetWSIndex] = (USED); - } + unUsedSpec[targetWSIndex] = (USED); } } } diff --git a/Framework/Kernel/test/CowPtrTest.h b/Framework/Kernel/test/CowPtrTest.h index e8de0414bac..d4a97a9cc9e 100644 --- a/Framework/Kernel/test/CowPtrTest.h +++ b/Framework/Kernel/test/CowPtrTest.h @@ -38,9 +38,8 @@ public: } void testConstructorByPtr() { - - auto *resource = new MyType{2}; - cow_ptr<MyType> cow{resource}; + auto resource = std::make_unique<MyType>(2); + cow_ptr<MyType> cow{resource.release()}; TSM_ASSERT_EQUALS("COW does not hold the expected value", 2, cow->value); } -- GitLab