mirror of
https://github.com/OPM/opm-simulators.git
synced 2026-10-24 22:57:42 -05:00
replace std::find with std::ranges::find where appropriate
the c++-20 constrained algorithm is safer and code is more readable
This commit is contained in:
1 parent
c80a5575ee
commit
e030a590a9
8 files changed
+12
-15
No files matched your search
@@ -161,7 +161,7 @@ struct SupportedKeywords {
|
||||
|
||||
bool operator()(const T& value) const
|
||||
{
|
||||
return std::find(m_allowed_values.begin(), m_allowed_values.end(), value) != m_allowed_values.end();
|
||||
return std::ranges::find(m_allowed_values, value) != m_allowed_values.end();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -319,7 +319,7 @@ struct BlockExtractor
|
||||
}, handler);
|
||||
|
||||
const auto found_handler =
|
||||
std::find(gen_handlers.begin(), gen_handlers.end(), kw_name);
|
||||
std::ranges::find(gen_handlers, kw_name);
|
||||
if (found_handler != gen_handlers.end()) {
|
||||
phase = std::distance(gen_handlers.begin(), found_handler) % numPhases;
|
||||
}
|
||||
|
||||
@@ -226,9 +226,8 @@ void SimulatorSerializer::checkSerializedCmdLine(const std::string& current,
|
||||
if (!difference.empty()) {
|
||||
std::vector<std::string> only_stored, only_curr;
|
||||
for (std::size_t i = 0; i < difference.size(); ) {
|
||||
auto stored_it = std::find(stored_strings.begin(),
|
||||
stored_strings.end(), difference[i]);
|
||||
auto pos = difference[i].find_first_of('=');
|
||||
const auto stored_it = std::ranges::find(stored_strings, difference[i]);
|
||||
const auto pos = difference[i].find_first_of('=');
|
||||
if (i < difference.size() - 1 &&
|
||||
difference[i].compare(0, pos, difference[i+1], 0, pos) == 0) {
|
||||
if (stored_it == stored_strings.end()) {
|
||||
|
||||
@@ -135,7 +135,7 @@ int
|
||||
ReservoirCouplingMaster<Scalar>::
|
||||
getSlaveIdx(const std::string &slave_name) const
|
||||
{
|
||||
auto it = std::find(this->slave_names_.begin(), this->slave_names_.end(), slave_name);
|
||||
const auto it = std::ranges::find(this->slave_names_, slave_name);
|
||||
if (it != this->slave_names_.end()) {
|
||||
return std::distance(this->slave_names_.begin(), it);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ create_preconditioner_amg(BlockedMatrix<Scalar> *mat_)
|
||||
for (int row = 0; row < cprNb; ++row) {
|
||||
int start = mat->rowPointers[row];
|
||||
int end = mat->rowPointers[row + 1];
|
||||
auto candidate = std::find(mat->colIndices + start, mat->colIndices + end, row);
|
||||
const auto candidate = std::find(mat->colIndices + start, mat->colIndices + end, row);
|
||||
assert(candidate != mat->colIndices + end);
|
||||
diagIndices[0][row] = candidate - mat->colIndices;
|
||||
}
|
||||
|
||||
@@ -693,7 +693,7 @@ template<typename Scalar, typename IndexTraits>
|
||||
void WellInterfaceGeneric<Scalar, IndexTraits>::addPerforations(const std::vector<RuntimePerforation>& perfs)
|
||||
{
|
||||
for (const auto& perf : perfs) {
|
||||
auto it = std::find(well_cells_.begin(), well_cells_.end(), perf.cell);
|
||||
const auto it = std::ranges::find(well_cells_, perf.cell);
|
||||
if (it != this->well_cells_.end()) {
|
||||
// If perforation to cell already exists, just add contribution.
|
||||
const auto ind = std::distance(this->well_cells_.begin(), it);
|
||||
|
||||
@@ -334,7 +334,8 @@ public:
|
||||
}
|
||||
|
||||
bool is_permanently_inactive_well(const std::string& wname) const {
|
||||
return std::find(this->permanently_inactive_well_names_.begin(), this->permanently_inactive_well_names_.end(), wname) != this->permanently_inactive_well_names_.end();
|
||||
return std::ranges::find(this->permanently_inactive_well_names_, wname) !=
|
||||
this->permanently_inactive_well_names_.end();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(RstConvTest)
|
||||
std::vector<int>& v = max[c];
|
||||
while (v.size() < sample.N) {
|
||||
int m = dist(mersenne_engine);
|
||||
if (std::find(v.begin(), v.end(), m) == v.end()) {
|
||||
if (std::ranges::find(v, m) == v.end()) {
|
||||
v.push_back(m);
|
||||
}
|
||||
}
|
||||
@@ -145,9 +145,7 @@ BOOST_AUTO_TEST_CASE(RstConvTest)
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
for (int c = 0; c < 6; ++c) {
|
||||
if (sample.phase[c] != -1) {
|
||||
bool inMax = std::find(max[c].begin(),
|
||||
max[c].end(),
|
||||
cellMapping[i]) != max[c].end();
|
||||
const bool inMax = std::ranges::find(max[c], cellMapping[i]) != max[c].end();
|
||||
residual[i][sample.phase[c]] = inMax ? 1.0 : 1.0 / (i+2);
|
||||
}
|
||||
}
|
||||
@@ -169,8 +167,7 @@ BOOST_AUTO_TEST_CASE(RstConvTest)
|
||||
for (int i = 0; i < cc.size() * 10; ++i) {
|
||||
for (int c = 0; c < 6; ++c) {
|
||||
if (sample.phase[c] != -1) {
|
||||
bool inMax = std::find(max[c].begin(),
|
||||
max[c].end(), i) != max[c].end();
|
||||
const bool inMax = std::ranges::find(max[c], i) != max[c].end();
|
||||
BOOST_CHECK_EQUAL(cnv.getData()[c][i], inMax ? 2 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user