Skip to content

Commit

Permalink
delegating to push_back the logic of x,f capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
darioizzo committed May 18, 2020
1 parent 1525ce0 commit d15a0c6
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,16 +592,21 @@ void population::push_back_impl(T &&x, U &&f)
const auto new_id = std::uniform_int_distribution<unsigned long long>()(m_e);
auto x_copy(std::forward<T>(x));
auto f_copy(std::forward<U>(f));
// Reserve space in the vectors.
m_ID.reserve(m_ID.size() + 1u);
m_x.reserve(m_x.size() + 1u);
m_f.reserve(m_f.size() + 1u);

// update_champion() either throws before modfying anything, or it completes successfully. The rest is noexcept.
update_champion(x_copy, f_copy);
m_ID.push_back(new_id);
m_x.push_back(std::move(x_copy));
m_f.push_back(std::move(f_copy));
try {
m_ID.push_back(new_id);
m_x.push_back(std::move(x_copy));
m_f.push_back(std::move(f_copy));
} catch (...) {
auto n = m_ID.size();
n = std::min(n, m_x.size());
n = std::min(n, m_f.size());
m_ID.resize(n);
m_x.resize(n);
m_f.resize(n);
}
}

// Short routine to update the champion. Does nothing if the problem is MO
Expand Down

0 comments on commit d15a0c6

Please sign in to comment.