Commit 6c918cc5 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony Committed by Martyn Gigg
Browse files

Update codebase ready for std=c++17

- Remove bind1st/bind2nd usage.
- Avoids an internal compiler error in gcc with getProperty.
- Adds wrapper around sip executable to process the output and
  remove the throw specifiers. They are not allowed in C++ 17.
Refs #26261
parent e5150013
......@@ -508,8 +508,9 @@ void CompositeFunction::replaceFunction(size_t i, IFunction_sptr f) {
} else if (np_new > 0) // it could happen if the old function is an empty
// CompositeFunction
{
using std::placeholders::_1;
itFun = std::find_if(m_IFunction.begin(), m_IFunction.end(),
std::bind2nd(std::greater<size_t>(), i));
std::bind(std::greater<size_t>(), _1, i));
m_IFunction.insert(itFun, np_new, i);
}
}
......
......@@ -377,11 +377,12 @@ void Bin2DPowderDiffraction::normalizeToBinArea(MatrixWorkspace_sptr outWS) {
// divide by the xBinWidth
outWS->convertToFrequencies(idx);
auto &freqs = outWS->mutableY(idx);
using std::placeholders::_1;
std::transform(freqs.begin(), freqs.end(), freqs.begin(),
std::bind1st(std::multiplies<double>(), factor));
std::bind(std::multiplies<double>(), factor, _1));
auto &errors = outWS->mutableE(idx);
std::transform(errors.begin(), errors.end(), errors.begin(),
std::bind1st(std::multiplies<double>(), factor));
std::bind(std::multiplies<double>(), factor, _1));
}
}
......
......@@ -121,7 +121,11 @@ void CalculateTransmissionBeamSpreader::exec() {
}
// Extract the required spectra into separate workspaces
std::vector<detid_t> udets{getProperty("IncidentBeamMonitor")};
// The static_cast should not be necessary but it is required to avoid a
// "internal compiler error: segmentation fault" when compiling with gcc
// and std=c++1z
std::vector<detid_t> udets{
static_cast<detid_t>(getProperty("IncidentBeamMonitor"))};
// Convert UDETs to workspace indices
// Get monitors (assume that the detector mapping is the same for all data
......
......@@ -383,8 +383,10 @@ EventWorkspace_sptr CreateSampleWorkspace::createEventWorkspace(
// to find the events per bin
double sum_of_elems = std::accumulate(yValues.begin(), yValues.end(), 0.0);
double event_distrib_factor = numEvents / sum_of_elems;
std::transform(yValues.begin(), yValues.end(), yValues.begin(),
std::bind1st(std::multiplies<double>(), event_distrib_factor));
using std::placeholders::_1;
std::transform(
yValues.begin(), yValues.end(), yValues.begin(),
std::bind(std::multiplies<double>(), event_distrib_factor, _1));
// the array should now contain the number of events required per bin
// Make fake events
......
......@@ -113,12 +113,13 @@ void CrossCorrelate::exec() {
// Now check if the range between x_min and x_max is valid
auto &referenceX = inputWS->x(index_ref);
using std::placeholders::_1;
auto minIt = std::find_if(referenceX.cbegin(), referenceX.cend(),
std::bind2nd(std::greater<double>(), xmin));
std::bind(std::greater<double>(), _1, xmin));
if (minIt == referenceX.cend())
throw std::runtime_error("No data above XMin");
auto maxIt = std::find_if(minIt, referenceX.cend(),
std::bind2nd(std::greater<double>(), xmax));
std::bind(std::greater<double>(), _1, xmax));
if (minIt == maxIt)
throw std::runtime_error("Range is not valid");
......
......@@ -175,10 +175,11 @@ void FFTSmooth::truncate(int n) {
xr.assign(X.begin(), X.begin() + nx);
xi.assign(X.begin(), X.begin() + nx);
using std::placeholders::_1;
std::transform(yr.begin(), yr.end(), yr.begin(),
std::bind2nd(std::multiplies<double>(), f));
std::bind(std::multiplies<double>(), _1, f));
std::transform(yi.begin(), yi.end(), yi.begin(),
std::bind2nd(std::multiplies<double>(), f));
std::bind(std::multiplies<double>(), _1, f));
}
/** Smoothing by zeroing.
......
......@@ -532,8 +532,9 @@ double GetEi2::calculatePeakWidthAtHalfHeight(
peak_x.resize(nvalues);
std::copy(Xs.begin() + im, Xs.begin() + ip + 1, peak_x.begin());
peak_y.resize(nvalues);
using std::placeholders::_1;
std::transform(Ys.begin() + im, Ys.begin() + ip + 1, peak_y.begin(),
std::bind2nd(std::minus<double>(), bkgd));
std::bind(std::minus<double>(), _1, bkgd));
peak_e.resize(nvalues);
std::copy(Es.begin() + im, Es.begin() + ip + 1, peak_e.begin());
......
......@@ -113,8 +113,9 @@ MantidVec GetQsInQENSData::extractQValues(
// Convert Q-values to point values.
qValues.pop_back();
qValues.erase(qValues.begin());
using std::placeholders::_1;
std::transform(qValues.begin(), qValues.end(), qValues.begin(),
std::bind2nd(std::divides<double>(), 2.0));
std::bind(std::divides<double>(), _1, 2.0));
}
} else {
......
......@@ -122,9 +122,11 @@ void MaxMin::exec() {
if (MaxRange == EMPTY_DBL())
highit = X.end();
else
else {
using std::placeholders::_1;
highit = std::find_if(lowit, X.end(),
std::bind2nd(std::greater<double>(), MaxRange));
std::bind(std::greater<double>(), _1, MaxRange));
}
// If range specified doesn't overlap with this spectrum then bail out
if (lowit == X.end() || highit == X.begin() || lowit == highit)
......
......@@ -31,12 +31,13 @@ void Minus::performBinaryOperation(const HistogramData::Histogram &lhs,
const double rhsY, const double rhsE,
HistogramData::HistogramY &YOut,
HistogramData::HistogramE &EOut) {
using std::placeholders::_1;
std::transform(lhs.y().begin(), lhs.y().end(), YOut.begin(),
std::bind2nd(std::minus<double>(), rhsY));
std::bind(std::minus<double>(), _1, rhsY));
// Only do E if non-zero, otherwise just copy
if (rhsE != 0)
std::transform(lhs.e().begin(), lhs.e().end(), EOut.begin(),
std::bind2nd(VectorHelper::SumGaussError<double>(), rhsE));
std::bind(VectorHelper::SumGaussError<double>(), _1, rhsE));
else
EOut = lhs.e();
}
......
......@@ -90,12 +90,13 @@ void MultiplyRange::exec() {
auto &newE = outputWS->mutableE(i);
// Now multiply the requested range
using std::placeholders::_1;
std::transform(newY.begin() + startBin, newY.begin() + endBin + 1,
newY.begin() + startBin,
std::bind2nd(std::multiplies<double>(), factor));
std::bind(std::multiplies<double>(), _1, factor));
std::transform(newE.begin() + startBin, newE.begin() + endBin + 1,
newE.begin() + startBin,
std::bind2nd(std::multiplies<double>(), factor));
std::bind(std::multiplies<double>(), _1, factor));
progress.report();
PARALLEL_END_INTERUPT_REGION
......
......@@ -34,12 +34,13 @@ void Plus::performBinaryOperation(const HistogramData::Histogram &lhs,
const double rhsY, const double rhsE,
HistogramData::HistogramY &YOut,
HistogramData::HistogramE &EOut) {
using std::placeholders::_1;
std::transform(lhs.y().begin(), lhs.y().end(), YOut.begin(),
std::bind2nd(std::plus<double>(), rhsY));
std::bind(std::plus<double>(), _1, rhsY));
// Only do E if non-zero, otherwise just copy
if (rhsE != 0)
std::transform(lhs.e().begin(), lhs.e().end(), EOut.begin(),
std::bind2nd(VectorHelper::SumGaussError<double>(), rhsE));
std::bind(VectorHelper::SumGaussError<double>(), _1, rhsE));
else
EOut = lhs.e();
}
......
......@@ -118,8 +118,9 @@ void PointByPointVCorrection::exec() {
(error2_factor1 / factor1 / factor1 + error2_factor2);
// Calculate the normalized Y values
using std::placeholders::_1;
// NOTE: Previously, we had been using std::transform with
// std::bind2nd(std::multiplies<double>(),factor)
// std::bind(std::multiplies<double>(), _1,factor)
// here, but that seemed to have strange effects in Windows Debug
// builds which caused the unit tests
// to sometimes fail. Maybe this is some compiler bug to do with
......
......@@ -190,8 +190,9 @@ int Regroup::newAxis(const std::vector<double> &params,
int isteps = ibounds - 1; // highest index in params array containing a step
xcurr = params[0];
using std::placeholders::_1;
auto iup = std::find_if(xold.cbegin(), xold.cend(),
std::bind2nd(std::greater_equal<double>(), xcurr));
std::bind(std::greater_equal<double>(), _1, xcurr));
if (iup != xold.end()) {
xcurr = *iup;
xnew.push_back(xcurr);
......@@ -211,7 +212,7 @@ int Regroup::newAxis(const std::vector<double> &params,
// find nearest x_i that is >= xcurr
iup = std::find_if(xold.begin(), xold.end(),
std::bind2nd(std::greater_equal<double>(), xcurr + xs));
std::bind(std::greater_equal<double>(), _1, xcurr + xs));
if (iup != xold.end()) {
if (*iup <= params[ibound]) {
xcurr = *iup;
......
......@@ -143,8 +143,9 @@ void ScaleX::exec() {
if ((i >= m_wi_min) && (i <= m_wi_max)) {
double factor = getScaleFactor(inputW, i);
// Do the offsetting
using std::placeholders::_1;
std::transform(inX.begin(), inX.end(), outX.begin(),
std::bind2nd(m_binOp, factor));
std::bind(m_binOp, _1, factor));
// reverse the vector if multiplicative factor was negative
if (multiply && factor < 0.0) {
std::reverse(outX.begin(), outX.end());
......
......@@ -199,10 +199,11 @@ void SofQWCentre::makeDistribution(API::MatrixWorkspace &outputWS,
for (size_t i = 0; i < numQBins; ++i) {
auto &Y = outputWS.mutableY(i);
auto &E = outputWS.mutableE(i);
using std::placeholders::_1;
std::transform(Y.begin(), Y.end(), Y.begin(),
std::bind2nd(std::divides<double>(), widths[i + 1]));
std::bind(std::divides<double>(), _1, widths[i + 1]));
std::transform(E.begin(), E.end(), E.begin(),
std::bind2nd(std::divides<double>(), widths[i + 1]));
std::bind(std::divides<double>(), _1, widths[i + 1]));
}
}
......
......@@ -570,11 +570,11 @@ private:
std::vector<double> diff(inY.size());
std::transform(inY.begin(), inY.end(), outY.begin(), diff.begin(),
std::minus<double>());
using std::placeholders::_1;
auto countPos = std::count_if(diff.begin(), diff.end(),
std::bind2nd(std::greater<double>(), 0.0));
std::bind(std::greater<double>(), _1, 0.0));
auto countNeg = std::count_if(diff.begin(), diff.end(),
std::bind2nd(std::less<double>(), 0.0));
std::bind(std::less<double>(), _1, 0.0));
// the delta here is just a guess
TS_ASSERT_DELTA(double(countPos) / double(countNeg), 1.0, 1e-1);
......@@ -646,9 +646,9 @@ private:
X.assign(x, x + nx);
Y.assign(y, y + ny);
E.assign(e, e + ny);
using std::placeholders::_1;
std::transform(Y.begin(), Y.end(), Y.begin(),
std::bind2nd(std::multiplies<double>(), double(i + 1)));
std::bind(std::multiplies<double>(), _1, i + 1));
}
return dataWS;
......
......@@ -307,12 +307,12 @@ PeakFindingStrategy::getBounds(const HistogramData::HistogramX &x) const {
auto lowit = (m_minValue == EMPTY_DBL())
? x.begin()
: std::lower_bound(x.begin(), x.end(), m_minValue);
using std::placeholders::_1;
auto highit =
(m_maxValue == EMPTY_DBL())
? x.end()
: std::find_if(lowit, x.end(),
std::bind2nd(std::greater<double>(), m_maxValue));
std::bind(std::greater<double>(), _1, m_maxValue));
return std::make_pair(lowit, highit);
}
......
......@@ -753,7 +753,11 @@ std::vector<MatrixWorkspace_sptr> QENSFitSequential::getWorkspaces() const {
const auto inputString = getPropertyValue("Input");
if (!inputString.empty())
return extractWorkspaces(inputString);
return {getProperty("InputWorkspace")};
// The static_cast should not be necessary but it is required to avoid a
// "internal compiler error: segmentation fault" when compiling with gcc
// and std=c++1z
return std::vector<MatrixWorkspace_sptr>{
static_cast<MatrixWorkspace_sptr>(getProperty("InputWorkspace"))};
}
std::vector<MatrixWorkspace_sptr> QENSFitSequential::convertInputToElasticQ(
......
......@@ -32,6 +32,7 @@ using namespace Kernel;
using namespace CurveFitting;
using namespace CurveFitting::Functions;
using namespace std;
using std::placeholders::_1;
// Subscription
DECLARE_ALGORITHM(VesuvioCalculateGammaBackground)
......@@ -255,7 +256,7 @@ void VesuvioCalculateGammaBackground::calculateSpectrumFromDetector(
// Correct for distance to the detector: 0.5/l2^2
const double detDistCorr = 0.5 / detPar.l2 / detPar.l2;
std::transform(ctdet.begin(), ctdet.end(), ctdet.begin(),
std::bind2nd(std::multiplies<double>(), detDistCorr));
std::bind(std::multiplies<double>(), _1, detDistCorr));
}
/**
......@@ -302,7 +303,7 @@ void VesuvioCalculateGammaBackground::calculateBackgroundFromFoils(
if (reversed) {
// The reversed ones should be (C0 - C1)
std::transform(ctfoil.begin(), ctfoil.end(), ctfoil.begin(),
std::bind2nd(std::multiplies<double>(), -1.0));
std::bind(std::multiplies<double>(), _1, -1.0));
}
}
......@@ -398,7 +399,7 @@ std::vector<double> VesuvioCalculateGammaBackground::calculateTofSpectrum(
// Assumes the input is in seconds, transform it temporarily
auto &tseconds = m_backgroundWS->mutableX(wsIndex);
std::transform(tseconds.begin(), tseconds.end(), tseconds.begin(),
std::bind2nd(std::multiplies<double>(), 1e-6));
std::bind(std::multiplies<double>(), _1, 1e-6));
// retrieveInputs ensures we will get a composite function and that each
// member is a ComptonProfile
......@@ -429,7 +430,7 @@ std::vector<double> VesuvioCalculateGammaBackground::calculateTofSpectrum(
}
// Put X back microseconds
std::transform(tseconds.begin(), tseconds.end(), tseconds.begin(),
std::bind2nd(std::multiplies<double>(), 1e6));
std::bind(std::multiplies<double>(), _1, 1e6));
return correctedVals;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment