diff options
| author | Patrick Venture <venture@google.com> | 2018-10-13 14:08:09 -0700 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2018-10-13 14:09:17 -0700 |
| commit | 107a25da65dfe080d905b193b5a3845c391c3d20 (patch) | |
| tree | 31ad947c6d9be4aeeb71967a6404edc918b92372 /dbus | |
| parent | df766f251f25e32ccbfe1e3ea429f118478422bd (diff) | |
| download | phosphor-pid-control-107a25da65dfe080d905b193b5a3845c391c3d20.tar.gz phosphor-pid-control-107a25da65dfe080d905b193b5a3845c391c3d20.zip | |
dbus: transition to find_if
[dbus/dbusconfiguration.cpp:58]: (style) Consider using std::find_if algorithm
instead of a raw loop.
Change-Id: I6fdabecc027addfc6f843a4b5f4621a61db39c2d
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'dbus')
| -rw-r--r-- | dbus/dbusconfiguration.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/dbus/dbusconfiguration.cpp b/dbus/dbusconfiguration.cpp index 45f51b6..499dca1 100644 --- a/dbus/dbusconfiguration.cpp +++ b/dbus/dbusconfiguration.cpp @@ -14,6 +14,7 @@ // limitations under the License. */ +#include <algorithm> #include <chrono> #include <conf.hpp> #include <dbus/util.hpp> @@ -52,14 +53,16 @@ bool findSensor(const std::unordered_map<std::string, std::string>& sensors, const std::string& search, std::pair<std::string, std::string>& sensor) { - for (const auto& s : sensors) + auto found = + std::find_if(sensors.begin(), sensors.end(), [&search](const auto& s) { + return (s.first.find(search) != std::string::npos); + }); + if (found != sensors.end()) { - if (s.first.find(search) != std::string::npos) - { - sensor = s; - return true; - } + sensor = *found; + return true; } + return false; } |

