OPM / opm-grid

DUNE module supporting grids in a corner-point format
http://www.opm-project.org
GNU General Public License v3.0
18 stars 75 forks source link

Avoid capturing structured binding [&key]. #740

Closed atgeirr closed 1 month ago

atgeirr commented 1 month ago

This is not supported until C++20, and at least for clang on mac, is not yet supported in OpenMP:

/Users/atgeirr/opm/src/opm-grid/opm/grid/common/MetisPartition.cpp:111:112: warning: captured structured bindings are a C++20 extension [-Wc++20-extensions]
        } else if (std::any_of(metisOptionKeysForOtherMethods.begin(), metisOptionKeysForOtherMethods.end(), [&key](const std::string& otherKey) { return otherKey == key; })) {
                                                                                                               ^
/Users/atgeirr/opm/src/opm-grid/opm/grid/common/MetisPartition.cpp:95:23: note: 'key' declared here
    for (const auto& [key,value] : optionsMap) {
                      ^
/Users/atgeirr/opm/src/opm-grid/opm/grid/common/MetisPartition.cpp:111:112: error: capturing a structured binding is not yet supported in OpenMP
        } else if (std::any_of(metisOptionKeysForOtherMethods.begin(), metisOptionKeysForOtherMethods.end(), [&key](const std::string& otherKey) { return otherKey == key; })) {
                                                                                                               ^
/Users/atgeirr/opm/src/opm-grid/opm/grid/common/MetisPartition.cpp:95:23: note: 'key' declared here
    for (const auto& [key,value] : optionsMap) {

I replaced the std::any_of() with calling the count() function of the set, which is simpler in any case (contains() is not yet available).

Also improve formatting nearby avoiding overlong lines.

atgeirr commented 1 month ago

jenkins build this please