Commit 954130d5 authored by Hahn, Steven's avatar Hahn, Steven
Browse files

use back() member function to return last element of a container.

parent aecbde37
......@@ -336,7 +336,7 @@ public:
* */
double getAverageDepth() const {
double total = 0;
double maxNumberOfFinestBoxes = m_maxNumMDBoxes[m_maxNumMDBoxes.size() - 1];
double maxNumberOfFinestBoxes = m_maxNumMDBoxes.back();
for (size_t depth = 0; depth < m_numMDBoxes.size(); depth++) {
// Add up the number of MDBoxes at that depth, weighed by their volume in
// units of the volume of the finest possible box.
......
......@@ -123,8 +123,7 @@ void Expression::parse(const std::string &str) {
m_expr = str;
trim(m_expr);
if (m_expr.size() > 1 && m_expr[0] == '(' &&
m_expr[m_expr.size() - 1] == ')') {
if (m_expr.size() > 1 && m_expr.front() == '(' && m_expr.back() == ')') {
if (m_expr.find('(', 1) == std::string::npos) {
m_expr.erase(0, 1);
m_expr.erase(m_expr.size() - 1, 1);
......
......@@ -292,10 +292,10 @@ void FunctionFactoryImpl::addTie(IFunction_sptr fun,
if (expr.size() > 1) { // if size > 2 it is interpreted as setting a tie (last
// expr.term) to multiple parameters, e.g
// f1.alpha = f2.alpha = f3.alpha = f0.beta^2/2
const std::string value = expr[expr.size() - 1].str();
for (size_t i = expr.size() - 1; i != 0;) {
--i;
fun->tie(expr[i].name(), value);
const std::string value = expr[expr.size() - 1].str();
for (size_t i = expr.size() - 1; i != 0;) {
--i;
fun->tie(expr[i].name(), value);
}
}
}
......
......@@ -572,7 +572,7 @@ protected:
}
if (m_value.size() > 2) {
// check if the value is in barckets (...)
if (m_value[0] == '(' && m_value[m_value.size() - 1] == ')') {
if (m_value.front() == '(' && m_value.back() == ')') {
m_value.erase(0, 1);
m_value.erase(m_value.size() - 1);
}
......
......@@ -219,14 +219,12 @@ void DiffractionFocussing::calculateRebinParams(
int64_t length = workspace->getNumberHistograms();
for (int64_t i = 0; i < length; i++) {
const MantidVec &xVec = workspace->readX(i);
const double &localMin = xVec[0];
const double &localMax = xVec[xVec.size() - 1];
const double &localMin = xVec.front();
const double &localMax = xVec.back();
if (localMin != std::numeric_limits<double>::infinity() &&
localMax != std::numeric_limits<double>::infinity()) {
if (localMin < min)
min = localMin;
if (localMax > max)
max = localMax;
min = std::min(min, localMin);
max = std::max(max, localMax);
}
}
......
......@@ -361,7 +361,7 @@ bool FFT::areBinWidthsUneven(const MantidVec &xValues) const {
const double dx = [&] {
if (acceptXRoundingErrors) {
// use average bin width
return (xValues[xValues.size() - 1] - xValues[0]) /
return (xValues.back() - xValues.front()) /
static_cast<double>(xValues.size() - 1);
} else {
// use first bin width
......
......@@ -187,12 +187,12 @@ void FindPeakBackground::exec() {
vector<cont_peak> peaks;
if (mask[0] == 1) {
peaks.push_back(cont_peak());
peaks[peaks.size() - 1].start = l0;
peaks.back().start = l0;
}
for (size_t l = 1; l < n - l0; ++l) {
if (mask[l] != mask[l - 1] && mask[l] == 1) {
peaks.push_back(cont_peak());
peaks[peaks.size() - 1].start = l + l0;
peaks.back().start = l + l0;
} else if (!peaks.empty()) {
size_t ipeak = peaks.size() - 1;
if (mask[l] != mask[l - 1] && mask[l] == 0) {
......@@ -208,8 +208,8 @@ void FindPeakBackground::exec() {
if (!peaks.empty()) {
g_log.debug() << "Peaks' size = " << peaks.size()
<< " -> esitmate background. \n";
if (peaks[peaks.size() - 1].stop == 0)
peaks[peaks.size() - 1].stop = n - 1;
if (peaks.back().stop == 0)
peaks.back().stop = n - 1;
std::sort(peaks.begin(), peaks.end(), by_len());
// save endpoints
......
......@@ -310,7 +310,7 @@ void GetTimeSeriesLogInformation::exportErrorLog(MatrixWorkspace_sptr ws,
vector<DateAndTime> abstimevec,
double dts) {
std::string outputdir = getProperty("OutputDirectory");
if (!outputdir.empty() && outputdir[outputdir.size() - 1] != '/')
if (!outputdir.empty() && outputdir.back() != '/')
outputdir += "/";
std::string ofilename = outputdir + "errordeltatime.txt";
......
......@@ -287,11 +287,12 @@ void InterpolatingRebin::cubicInterpolation(
throw std::invalid_argument(
std::string("At least one x-value to interpolate to is outside the "
"range of the original data.\n") +
"original data range: " + boost::lexical_cast<std::string>(xOld[0]) +
" to " + boost::lexical_cast<std::string>(xOld[xOld.size() - 1]) +
"\n" + "range to try to interpolate to " +
boost::lexical_cast<std::string>(xNew[0]) + " to " +
boost::lexical_cast<std::string>(xNew[xNew.size() - 1]));
"original data range: " +
boost::lexical_cast<std::string>(xOld.front()) + " to " +
boost::lexical_cast<std::string>(xOld.back()) + "\n" +
"range to try to interpolate to " +
boost::lexical_cast<std::string>(xNew.front()) + " to " +
boost::lexical_cast<std::string>(xNew.back()));
}
}
......
......@@ -172,7 +172,7 @@ std::map<std::string, std::string> MaxEnt::validateInputs() {
// Average spacing
const MantidVec &X = inWS->readX(0);
const double dx =
(X[X.size() - 1] - X[0]) / static_cast<double>(X.size() - 1);
(X.back() - X.front()) / static_cast<double>(X.size() - 1);
for (size_t i = 1; i < X.size() - 1; i++) {
// 1% accuracy exceeded, but data still usable
if (std::abs(X[i] - X[0] - static_cast<double>(i) * dx) / dx >
......
......@@ -329,8 +329,8 @@ RadiusSum::getBoundariesOfNumericImage(API::MatrixWorkspace_sptr inWS) {
double min_x, max_x;
const double &first_x(refX[0]);
const double &last_x(refX[refX.size() - 1]);
const double &first_x = refX.front();
const double &last_x = refX.back();
if (first_x < last_x) {
min_x = first_x;
max_x = last_x;
......@@ -651,7 +651,7 @@ void RadiusSum::setUpOutputWorkspace(std::vector<double> &values) {
for (int i = 0; i < (static_cast<int>(refX.size())) - 1; i++)
refX[i] = min_radius + i * bin_size;
refX[refX.size() - 1] = max_radius;
refX.back() = max_radius;
// configure the axis:
// for numeric images, the axis are the same as the input workspace, and are
......
......@@ -338,8 +338,8 @@ void RingProfile::checkInputsForNumericWorkspace(
const MantidVec &refX = inputWS->readX(inputWS->getNumberHistograms() / 2);
// get the limits of the axis 0 (X)
double min_v_x, max_v_x;
min_v_x = std::min(refX[0], refX[refX.size() - 1]);
max_v_x = std::max(refX[0], refX[refX.size() - 1]);
min_v_x = std::min(refX[0], refX.back());
max_v_x = std::max(refX[0], refX.back());
g_log.notice() << "Limits X = " << min_v_x << " " << max_v_x << std::endl;
// check centre is inside the X domain
if (centre_x < min_v_x || centre_x > max_v_x) {
......
......@@ -441,10 +441,8 @@ VesuvioL1ThetaResolution::processDistribution(MatrixWorkspace_sptr ws,
double xMax(DBL_MIN);
for (size_t i = 0; i < numHist; i++) {
const std::vector<double> &x = ws->readX(i);
if (x[0] < xMin)
xMin = x[0];
if (x[x.size() - 1] > xMax)
xMax = x[x.size() - 1];
xMin = std::min(xMin, x.front());
xMax = std::max(xMax, x.back());
}
std::stringstream binParams;
......
......@@ -229,11 +229,10 @@ public:
// compare y data instead of workspaces.
auto scaledYData = scaledWS->readY(0);
auto nonScaledYData = nonScaledWS->readY(0);
TS_ASSERT_EQUALS(scaledYData[0], 2 * nonScaledYData[0]);
TS_ASSERT_EQUALS(scaledYData.front(), 2 * nonScaledYData.front());
TS_ASSERT_EQUALS(scaledYData[scaledYData.size() / 2],
2 * nonScaledYData[nonScaledYData.size() / 2]);
TS_ASSERT_EQUALS(scaledYData[scaledYData.size() - 1],
2 * nonScaledYData[nonScaledYData.size() - 1]);
TS_ASSERT_EQUALS(scaledYData.back(), 2 * nonScaledYData.back());
// Remove workspace from the data service.
AnalysisDataService::Instance().remove("Test");
AnalysisDataService::Instance().remove("scaledTest");
......@@ -265,7 +264,7 @@ public:
TSM_ASSERT_DELTA("DQQ should be the same as abs(x[1]/x[0] - 1)",
binWidthFromLogarithmicEquation, 0.1, 1e-06);
TSM_ASSERT_DELTA("Qmax should be the same as last Params entry (5.0)",
xData[xData.size() - 1], 15.0, 1e-06);
xData.back(), 15.0, 1e-06);
}
void test_post_processing_rebin_step_with_logarithmic_rebinning() {
auto alg = construct_standard_algorithm();
......@@ -287,7 +286,7 @@ public:
TSM_ASSERT_DELTA("DQQ should be the same as abs(x[1]/x[0] - 1)",
binWidthFromLogarithmicEquation, 0.2, 1e-06);
TSM_ASSERT_EQUALS("QMax should be the same as last Param entry",
xData[xData.size() - 1], 5.0);
xData.back(), 5.0);
}
void test_post_processing_rebin_step_with_linear_rebinning() {
auto alg = construct_standard_algorithm();
......@@ -307,7 +306,7 @@ public:
TSM_ASSERT_DELTA("DQQ should the same as 0.2", xData[1] - xData[0], 0.2,
1e-06);
TSM_ASSERT_DELTA("QMax should be the same as the last Param entry (5.233)",
xData[xData.size() - 1], 5.233, 1e-06);
xData.back(), 5.233, 1e-06);
}
void test_Qrange() {
// set up the axis for the instrument
......
......@@ -334,9 +334,8 @@ public:
}
}
double start_overlap_determined = stitched_x[overlap_indexes[0]];
double end_overlap_determined =
stitched_x[overlap_indexes[overlap_indexes.size() - 1]];
double start_overlap_determined = stitched_x[overlap_indexes.front()];
double end_overlap_determined = stitched_x[overlap_indexes.back()];
TS_ASSERT_DELTA(start_overlap_determined, -0.4, 0.000000001);
TS_ASSERT_DELTA(end_overlap_determined, 0.2, 0.000000001);
}
......@@ -363,9 +362,8 @@ public:
}
}
double start_overlap_determined = stitched_x[overlap_indexes[0]];
double end_overlap_determined =
stitched_x[overlap_indexes[overlap_indexes.size() - 1]];
double start_overlap_determined = stitched_x[overlap_indexes.front()];
double end_overlap_determined = stitched_x[overlap_indexes.back()];
TS_ASSERT_DELTA(start_overlap_determined, -0.4, 0.000000001);
TS_ASSERT_DELTA(end_overlap_determined, 0.2, 0.000000001);
}
......@@ -392,9 +390,8 @@ public:
}
}
double start_overlap_determined = stitched_x[overlap_indexes[0]];
double end_overlap_determined =
stitched_x[overlap_indexes[overlap_indexes.size() - 1]];
double start_overlap_determined = stitched_x[overlap_indexes.front()];
double end_overlap_determined = stitched_x[overlap_indexes.back()];
TS_ASSERT_DELTA(start_overlap_determined, -0.4, 0.000000001);
TS_ASSERT_DELTA(end_overlap_determined, 0.2, 0.000000001);
}
......@@ -569,7 +566,7 @@ public:
TSM_ASSERT("All error values are non-zero", !alg.hasNonzeroErrors(ws));
// Run it again with some zeros
e[e.size() - 1] = 1;
e.back() = 1;
ws = createWorkspace(x, y, e, 1);
TSM_ASSERT("NOT all error values are non-zero", alg.hasNonzeroErrors(ws));
}
......@@ -597,7 +594,7 @@ public:
TSM_ASSERT("All error values are non-zero", !alg.hasNonzeroErrors(ws));
// Run it again with some zeros
e[e.size() - 1] = 1;
e.back() = 1;
ws = createWorkspace(x, y, e, nspectrum);
TSM_ASSERT("NOT all error values are non-zero", alg.hasNonzeroErrors(ws));
}
......
......@@ -190,7 +190,7 @@ void OptimizeLatticeForCellType::exec() {
AnalysisDataService::Instance().remove("_peaks");
if (perRun) {
std::string outputdir = getProperty("OutputDirectory");
if (outputdir[outputdir.size() - 1] != '/')
if (outputdir.back() != '/')
outputdir += "/";
// Save Peaks
Mantid::API::IAlgorithm_sptr savePks_alg =
......
......@@ -448,7 +448,7 @@ void ProcessBackground::addRegion() {
m_outputWS->dataE(0)[i] = ve[i];
}
if (vx.size() > vy.size())
m_outputWS->dataX(0)[vx.size() - 1] = vx.back();
m_outputWS->dataX(0).back() = vx.back();
// Write out dummy output workspaces
setupDummyOutputWSes();
......
......@@ -119,7 +119,7 @@ DownloadInstrument::StringToStringMap DownloadInstrument::processRepository() {
// get the instrument directories
auto instrumentDirs =
Mantid::Kernel::ConfigService::Instance().getInstrumentDirectories();
Poco::Path installPath(instrumentDirs[instrumentDirs.size() - 1]);
Poco::Path installPath(instrumentDirs.back());
installPath.makeDirectory();
Poco::Path localPath(instrumentDirs[0]);
localPath.makeDirectory();
......
......@@ -288,8 +288,8 @@ void LoadMask::bankToDetectors(std::vector<std::string> singlebanks,
// a) get information
size_t numdets = idetectors.size();
detid_t detid_first = idetectors[0]->getID();
detid_t detid_last = idetectors[idetectors.size() - 1]->getID();
detid_t detid_first = idetectors.front()->getID();
detid_t detid_last = idetectors.back()->getID();
// b) set detectors
if (detid_first + int32_t(numdets) == detid_last + 1 && false) {
......
......@@ -164,8 +164,7 @@ void LoadSNSspec::exec() {
spectra[working_with_spectrum_nbr].dataE().push_back(input[j]);
nBins = j / 3;
}
spectra[working_with_spectrum_nbr].dataX().push_back(
input[input.size() - 1]);
spectra[working_with_spectrum_nbr].dataX().push_back(input.back());
}
working_with_spectrum_nbr++;
input.clear();
......@@ -186,8 +185,7 @@ void LoadSNSspec::exec() {
spectra[working_with_spectrum_nbr].dataE().push_back(input[j]);
nBins = j / 3;
}
spectra[working_with_spectrum_nbr].dataX().push_back(
input[input.size() - 1]);
spectra[working_with_spectrum_nbr].dataX().push_back(input.back());
}
} catch (...) {
}
......
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