Commit d5783db6 authored by Hahn, Steven's avatar Hahn, Steven
Browse files

Apply changes suggested by modernize-use-emplace

parent 5a8a099a
......@@ -311,7 +311,7 @@ void Expression::tokenize() {
if (!tokens.empty()) {
// remove operators of higher prec
m_tokens.push_back(Token(tokens[0]));
m_tokens.emplace_back(tokens[0]);
for (size_t i = 0; i < tokens.size(); i++) {
Token &tok = tokens[i];
std::string op = m_expr.substr(tok.ie + 1, tok.is1 - tok.ie - 1); //?
......@@ -320,7 +320,7 @@ void Expression::tokenize() {
last_tok.ie = tok.ie;
last_tok.is1 = tok.is1;
if (i != tokens.size() - 1)
m_tokens.push_back(Token(tokens[i + 1]));
m_tokens.emplace_back(tokens[i + 1]);
}
}
}
......
......@@ -182,7 +182,7 @@ void EQSANSTofStructure::execEvent(
// At this point the events in the second frame are still off by a frame
if (frame_skipping && rel_tof > tof_frame_width)
newtof += tof_frame_width;
clean_events.push_back(TofEvent(newtof, it->pulseTime()));
clean_events.emplace_back(newtof, it->pulseTime());
}
events.clear();
events.reserve(clean_events.size());
......
......@@ -153,7 +153,7 @@ void FilterByLogValue::exec() {
splitter.push_back(interval);
}
// And the last one
splitter.push_back(SplittingInterval(lastTime, run_stop, 0));
splitter.emplace_back(lastTime, run_stop, 0);
} else {
// ----- Filter by value ------
......
......@@ -176,12 +176,12 @@ void FindPeakBackground::exec() {
// for loop can start > 1 for multiple peaks
vector<cont_peak> peaks;
if (mask[0] == 1) {
peaks.push_back(cont_peak());
peaks.emplace_back();
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.emplace_back();
peaks.back().start = l + l0;
} else if (!peaks.empty()) {
size_t ipeak = peaks.size() - 1;
......
......@@ -340,7 +340,7 @@ void GetAllEi::exec() {
bool found = findMonitorPeak(monitorWS, guess_ei[i], monsRangeMin,
monsRangeMax, energy, height, twoSigma);
if (found) {
peaks.push_back(peakKeeper(energy, height, 0.5 * twoSigma));
peaks.emplace_back(energy, height, 0.5 * twoSigma);
if (peaks.back().energy > maxPeakEnergy)
maxPeakEnergy = peaks.back().energy;
}
......
......@@ -250,7 +250,7 @@ void SmoothNeighbours::findNeighboursRectangular() {
// Build a map to sort by the detectorID
std::vector<std::pair<int, int>> v1;
for (int i = 0; i < static_cast<int>(detList.size()); i++)
v1.push_back(std::pair<int, int>(detList[i]->getAtXY(0, 0)->getID(), i));
v1.emplace_back(detList[i]->getAtXY(0, 0)->getID(), i);
// To sort in descending order
if (sum)
......@@ -287,7 +287,7 @@ void SmoothNeighbours::findNeighboursRectangular() {
auto mapEntry = pixel_to_wi.find(pixelID);
if (mapEntry != pixel_to_wi.end()) {
size_t wi = mapEntry->second;
neighbours.push_back(weightedNeighbour(wi, smweight));
neighbours.emplace_back(wi, smweight);
// Count the total weight
totalWeight += smweight;
}
......@@ -421,7 +421,7 @@ void SmoothNeighbours::findNeighboursUbiqutious() {
noNeigh++;
used[neighWI] = true;
}
neighbours.push_back(weightedNeighbour(neighWI, weight));
neighbours.emplace_back(neighWI, weight);
totalWeight += weight;
}
}
......
......@@ -143,7 +143,7 @@ size_t doConnectedComponentLabeling(IMDIterator *iterator,
correcly provided for all neighbours until the end. We must store
indexes instead.
*/
edgeIndexVec.push_back(EdgeIndexPair(currentIndex, neighIndex));
edgeIndexVec.emplace_back(currentIndex, neighIndex);
continue;
}
......
......@@ -1944,11 +1944,11 @@ DataModeHandler::CalcConstraints(std::vector<std::pair<double, double>> &Bounds,
double min =
max<double>(0.0, back_calc - NSigs * (1 + relError) * sqrt(backVar));
double maxx = back + NSigs * (1.8 + relError) * sqrt(backVar);
Bounds.push_back(pair<double, double>(min, maxx));
Bounds.push_back(pair<double, double>(
Bounds.emplace_back(min, maxx);
Bounds.emplace_back(
max<double>(0.0,
Intensity_calc - NSigs * (1 + relError) * sqrt(IntensVar)),
Intensity_calc + NSigs * (1 + relError) * sqrt(IntensVar)));
Intensity_calc + NSigs * (1 + relError) * sqrt(IntensVar));
double relErr1 = relError * .75;
double val = col_calc;
double minn = std::max<double>(MinCol - .5, (1 - relErr1) * val);
......@@ -1957,7 +1957,7 @@ DataModeHandler::CalcConstraints(std::vector<std::pair<double, double>> &Bounds,
str << "," << minn << "<"
<< "Mcol"
<< "<" << maxx;
Bounds.push_back(pair<double, double>(minn, maxx));
Bounds.emplace_back(minn, maxx);
val = row_calc;
......@@ -1966,7 +1966,7 @@ DataModeHandler::CalcConstraints(std::vector<std::pair<double, double>> &Bounds,
str << "," << minn << "<"
<< "Mrow"
<< "<" << maxx;
Bounds.push_back(pair<double, double>(minn, maxx));
Bounds.emplace_back(minn, maxx);
if (N >= 5) {
val = Vx_calc;
......@@ -1981,8 +1981,7 @@ DataModeHandler::CalcConstraints(std::vector<std::pair<double, double>> &Bounds,
str << "," << (1 - relErr1) * valmin << "<"
<< "SScol"
<< "<" << (1 + relErr1) * valmax;
Bounds.push_back(
pair<double, double>((1 - relErr1) * valmin, (1 + relErr1) * valmax));
Bounds.emplace_back((1 - relErr1) * valmin, (1 + relErr1) * valmax);
val = Vy_calc;
valmin = val;
......@@ -1994,8 +1993,7 @@ DataModeHandler::CalcConstraints(std::vector<std::pair<double, double>> &Bounds,
str << "," << (1 - relErr1) * valmin << "<"
<< "SSrow"
<< "<" << (1 + relErr1) * valmax;
Bounds.push_back(
pair<double, double>((1 - relErr1) * valmin, (1 + relErr1) * valmax));
Bounds.emplace_back((1 - relErr1) * valmin, (1 + relErr1) * valmax);
}
return str.str();
......
......@@ -190,8 +190,7 @@ void OptimizeCrystalPlacement::exec() {
Geometry::Goniometer Gon(peak.getGoniometerMatrix());
std::vector<double> phichiOmega = Gon.getEulerAngles("YZY");
ChiPhiOmega.push_back(
V3D(phichiOmega[1], phichiOmega[2], phichiOmega[0]));
ChiPhiOmega.emplace_back(phichiOmega[1], phichiOmega[2], phichiOmega[0]);
}
if (use) // add to lists for workspace
......
......@@ -933,9 +933,8 @@ void LoadEventPreNexus::readPulseidFile(const std::string &filename,
if (num_pulses > 0) {
this->pulsetimes.reserve(num_pulses);
for (const auto &pulse : pulses) {
this->pulsetimes.push_back(
DateAndTime(static_cast<int64_t>(pulse.seconds),
static_cast<int64_t>(pulse.nanoseconds)));
this->pulsetimes.emplace_back(static_cast<int64_t>(pulse.seconds),
static_cast<int64_t>(pulse.nanoseconds));
this->event_indices.push_back(pulse.event_index);
temp = pulse.pCurrent;
......
......@@ -137,7 +137,7 @@ MantidVec LoadSassena::loadQvectors(const hid_t &h5file,
if (getProperty("SortByQVectors")) {
std::vector<mypair> qvmodpair;
for (int iq = 0; iq < nq; iq++)
qvmodpair.push_back(mypair(qvmod[iq], iq));
qvmodpair.emplace_back(qvmod[iq], iq);
std::sort(qvmodpair.begin(), qvmodpair.end(), compare);
for (int iq = 0; iq < nq; iq++)
sorting_indexes.push_back(qvmodpair[iq].second);
......
......@@ -247,8 +247,8 @@ public:
const std::vector<coord_t> &Coord, const std::vector<uint16_t> &runIndex,
const std::vector<uint32_t> &detectorId, size_t nEvents) {
for (size_t i = 0; i < nEvents; i++) {
data.push_back(MDE(sigErrSq[2 * i], sigErrSq[2 * i + 1], runIndex[i],
detectorId[i], &Coord[i * nd]));
data.emplace_back(sigErrSq[2 * i], sigErrSq[2 * i + 1], runIndex[i],
detectorId[i], &Coord[i * nd]);
}
}
// create single generic event from event's data
......@@ -269,8 +269,7 @@ public:
const std::vector<uint32_t> & /*detectorId*/,
size_t nEvents) {
for (size_t i = 0; i < nEvents; i++) {
data.push_back(MDLeanEvent<nd>(sigErrSq[2 * i], sigErrSq[2 * i + 1],
&Coord[i * nd]));
data.emplace_back(sigErrSq[2 * i], sigErrSq[2 * i + 1], &Coord[i * nd]);
}
}
// create single lean event from event's data
......
......@@ -247,9 +247,9 @@ public:
coord_t const *const centers = &(data[ii + 4]);
// Create the event with signal, error squared, and the centers
events.push_back(MDEvent<nd>(signal_t(data[ii]), signal_t(data[ii + 1]),
uint16_t(data[ii + 2]),
int32_t(data[ii + 3]), centers));
events.emplace_back(signal_t(data[ii]), signal_t(data[ii + 1]),
uint16_t(data[ii + 2]), int32_t(data[ii + 3]),
centers);
}
}
};
......
......@@ -297,8 +297,8 @@ public:
const coord_t *centers = &(coord[ii + 2]);
// Create the event with signal, error squared, and the centers
events.push_back(MDLeanEvent<nd>(signal_t(coord[ii]),
signal_t(coord[ii + 1]), centers));
events.emplace_back(signal_t(coord[ii]), signal_t(coord[ii + 1]),
centers);
}
}
};
......
......@@ -216,7 +216,7 @@ protected:
if (index < m_data.size())
m_data.insert(m_data.begin() + index, Type());
else
m_data.push_back(Type());
m_data.emplace_back();
}
/// Removes an item at index.
void remove(size_t index) override { m_data.erase(m_data.begin() + index); }
......
......@@ -249,8 +249,7 @@ void EventList::createFromHistogram(const ISpectrum *inSpec, bool GenerateZeros,
double tof = X[i] + tofStep * (0.5 + double(j));
// Create and add the event
// TODO: try emplace_back() here.
weightedEventsNoTime.push_back(
WeightedEventNoTime(tof, weight, errorSquared));
weightedEventsNoTime.emplace_back(tof, weight, errorSquared);
}
} else {
// --------- Single event per bin ----------
......@@ -260,8 +259,7 @@ void EventList::createFromHistogram(const ISpectrum *inSpec, bool GenerateZeros,
double errorSquared = E[i];
errorSquared *= errorSquared;
// Create and add the event
weightedEventsNoTime.push_back(
WeightedEventNoTime(tof, weight, errorSquared));
weightedEventsNoTime.emplace_back(tof, weight, errorSquared);
}
} // error is nont NAN or infinite
} // weight is non-zero, not NAN, and non-infinite
......@@ -308,11 +306,11 @@ EventList &EventList::operator+=(const TofEvent &event) {
break;
case WEIGHTED:
this->weightedEvents.push_back(WeightedEvent(event));
this->weightedEvents.emplace_back(event);
break;
case WEIGHTED_NOTIME:
this->weightedEventsNoTime.push_back(WeightedEventNoTime(event));
this->weightedEventsNoTime.emplace_back(event);
break;
}
......@@ -692,7 +690,7 @@ void EventList::switchToWeightedEvents() {
std::vector<TofEvent>::const_iterator it_end =
events.end(); // Cache for speed
for (it = events.begin(); it != it_end; ++it)
this->weightedEvents.push_back(WeightedEvent(*it));
this->weightedEvents.emplace_back(*it);
// Get rid of the old events
events.clear();
eventType = WEIGHTED;
......@@ -717,7 +715,7 @@ void EventList::switchToWeightedEventsNoTime() {
std::vector<TofEvent>::const_iterator it_end =
events.end(); // Cache for speed
for (it = events.begin(); it != it_end; ++it)
this->weightedEventsNoTime.push_back(WeightedEventNoTime(*it));
this->weightedEventsNoTime.emplace_back(*it);
// Get rid of the old events
events.clear();
weightedEvents.clear();
......@@ -731,7 +729,7 @@ void EventList::switchToWeightedEventsNoTime() {
std::vector<WeightedEvent>::const_iterator it_end =
weightedEvents.end(); // Cache for speed
for (it = weightedEvents.begin(); it != it_end; ++it)
this->weightedEventsNoTime.push_back(WeightedEventNoTime(*it));
this->weightedEventsNoTime.emplace_back(*it);
// Get rid of the old events
events.clear();
weightedEvents.clear();
......@@ -1676,8 +1674,7 @@ EventList::compressEventsHelper(const std::vector<T> &events,
if (num > 0) {
// Create a new event with the average TOF and summed weights and
// squared errors.
out.push_back(
WeightedEventNoTime(totalTof / num, weight, errorSquared));
out.emplace_back(totalTof / num, weight, errorSquared);
}
// Start a new combined object
num = 1;
......@@ -1692,7 +1689,7 @@ EventList::compressEventsHelper(const std::vector<T> &events,
if (num > 0) {
// Create a new event with the average TOF and summed weights and squared
// errors.
out.push_back(WeightedEventNoTime(totalTof / num, weight, errorSquared));
out.emplace_back(totalTof / num, weight, errorSquared);
}
// If you have over-allocated by more than 5%, reduce the size.
......@@ -1761,8 +1758,7 @@ void EventList::compressEventsParallelHelper(
if (num > 0) {
// Create a new event with the average TOF and summed weights and
// squared errors.
localOut.push_back(
WeightedEventNoTime(totalTof / num, weight, errorSquared));
localOut.emplace_back(totalTof / num, weight, errorSquared);
}
// Start a new combined object
num = 1;
......@@ -1777,8 +1773,7 @@ void EventList::compressEventsParallelHelper(
if (num > 0) {
// Create a new event with the average TOF and summed weights and squared
// errors.
localOut.push_back(
WeightedEventNoTime(totalTof / num, weight, errorSquared));
localOut.emplace_back(totalTof / num, weight, errorSquared);
}
}
......
......@@ -1835,12 +1835,12 @@ int Object::searchForObject(Kernel::V3D &point) const {
return 1;
std::vector<Kernel::V3D> axes;
axes.reserve(6);
axes.push_back(Kernel::V3D(1, 0, 0));
axes.push_back(Kernel::V3D(-1, 0, 0));
axes.push_back(Kernel::V3D(0, 1, 0));
axes.push_back(Kernel::V3D(0, -1, 0));
axes.push_back(Kernel::V3D(0, 0, 1));
axes.push_back(Kernel::V3D(0, 0, -1));
axes.emplace_back(1, 0, 0);
axes.emplace_back(-1, 0, 0);
axes.emplace_back(0, 1, 0);
axes.emplace_back(0, -1, 0);
axes.emplace_back(0, 0, 1);
axes.emplace_back(0, 0, -1);
std::vector<Kernel::V3D>::const_iterator dir;
for (dir = axes.begin(); dir != axes.end(); ++dir) {
Geometry::Track tr(point, (*dir));
......
......@@ -370,12 +370,10 @@ void TimeSeriesProperty<TYPE>::filterByTimes(
TimeValueUnit<TYPE> temp(t_start, m_values[tstartindex].value());
mp_copy.push_back(temp);
} else {
mp_copy.push_back(
TimeValueUnit<TYPE>(t_start, m_values[tstartindex].value()));
mp_copy.emplace_back(t_start, m_values[tstartindex].value());
for (size_t im = size_t(tstartindex + 1); im <= size_t(tstopindex);
++im) {
mp_copy.push_back(
TimeValueUnit<TYPE>(m_values[im].time(), m_values[im].value()));
mp_copy.emplace_back(m_values[im].time(), m_values[im].value());
}
}
} // ENDFOR
......@@ -621,7 +619,7 @@ void TimeSeriesProperty<TYPE>::makeFilterByValue(
// boundaries are centred.
// Otherwise, use the first 'bad' time.
stop = centre ? lastTime + tol : t;
split.push_back(SplittingInterval(start, stop, 0));
split.emplace_back(start, stop, 0);
// Reset the number of good ones, for next time
numgood = 0;
}
......@@ -633,7 +631,7 @@ void TimeSeriesProperty<TYPE>::makeFilterByValue(
// The log ended on "good" so we need to close it using the last time we
// found
stop = t + tol;
split.push_back(SplittingInterval(start, stop, 0));
split.emplace_back(start, stop, 0);
}
return;
......@@ -686,7 +684,7 @@ void TimeSeriesProperty<TYPE>::expandFilterToRange(
double val = firstValue();
if ((val >= min) && (val <= max)) {
TimeSplitterType extraFilter;
extraFilter.push_back(SplittingInterval(range.begin(), firstTime(), 0));
extraFilter.emplace_back(range.begin(), firstTime(), 0);
// Include everything from the start of the run to the first time measured
// (which may be a null time interval; this'll be ignored)
split = split | extraFilter;
......@@ -696,7 +694,7 @@ void TimeSeriesProperty<TYPE>::expandFilterToRange(
val = lastValue();
if ((val >= min) && (val <= max)) {
TimeSplitterType extraFilter;
extraFilter.push_back(SplittingInterval(lastTime(), range.end(), 0));
extraFilter.emplace_back(lastTime(), range.end(), 0);
// Include everything from the start of the run to the first time measured
// (which may be a null time interval; this'll be ignored)
split = split | extraFilter;
......@@ -777,7 +775,7 @@ double TimeSeriesProperty<TYPE>::timeAverageValue() const {
double retVal = 0.0;
try {
TimeSplitterType filter;
filter.push_back(SplittingInterval(this->firstTime(), this->lastTime()));
filter.emplace_back(this->firstTime(), this->lastTime());
retVal = this->averageValueInFilter(filter);
} catch (std::exception &) {
// just return nan
......
......@@ -186,7 +186,7 @@ TimeSplitterType removeFilterOverlap(const TimeSplitterType &a) {
++it;
}
// We've reached a gap point. Output this merged interval and move on.
out.push_back(SplittingInterval(start, stop, 0));
out.emplace_back(start, stop, 0);
}
return out;
......@@ -242,8 +242,7 @@ TimeSplitterType operator~(const TimeSplitterType &a) {
// No entries: then make a "filter" that keeps everything
if ((temp.empty())) {
out.push_back(
SplittingInterval(DateAndTime::minimum(), DateAndTime::maximum(), 0));
out.emplace_back(DateAndTime::minimum(), DateAndTime::maximum(), 0);
return out;
}
......@@ -251,7 +250,7 @@ TimeSplitterType operator~(const TimeSplitterType &a) {
ait = temp.begin();
if (ait != temp.end()) {
// First entry; start at -infinite time
out.push_back(SplittingInterval(DateAndTime::minimum(), ait->start(), 0));
out.emplace_back(DateAndTime::minimum(), ait->start(), 0);
// Now start at the second entry
while (ait != temp.end()) {
DateAndTime start, stop;
......@@ -262,7 +261,7 @@ TimeSplitterType operator~(const TimeSplitterType &a) {
} else { // Stop at the start of the next entry
stop = ait->start();
}
out.push_back(SplittingInterval(start, stop, 0));
out.emplace_back(start, stop, 0);
}
}
return out;
......
......@@ -194,8 +194,8 @@ MDBox<MDLeanEvent<3>, 3> *makeMDBox3() {
std::vector<MDLeanEvent<1>> makeMDEvents1(size_t num) {
std::vector<MDLeanEvent<1>> out;
for (std::size_t i = 0; i < num; i++) {
double coords[1] = {static_cast<double>(i) * 1.0 + 0.5};
out.push_back(MDLeanEvent<1>(1.0, 1.0, coords));
double coords[1] = {static_cast<double>(i) + 0.5};
out.emplace_back(1.0, 1.0, coords);
}
return out;
}
......
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