summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2018-10-13 13:25:15 -0700
committerPatrick Venture <venture@google.com>2018-10-13 14:51:35 -0700
commit0956017412c84ac2a264d44dbb3f201d2f6c96f1 (patch)
treef412e496ea7fcd2165f4c659bd1b846ed9618af5
parent685efa165adc20d480e4c4994d62d62cd1e2f2d6 (diff)
downloadphosphor-hwmon-0956017412c84ac2a264d44dbb3f201d2f6c96f1.tar.gz
phosphor-hwmon-0956017412c84ac2a264d44dbb3f201d2f6c96f1.zip
sysfs: transition to std::find_if
[sysfs.cpp:228]: (style) Consider using std::find_if algorithm instead of a raw loop. Change-Id: Ie07ca5e32405fc7d27e85936377cec44291d3f94 Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r--sysfs.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/sysfs.cpp b/sysfs.cpp
index dd711e5..ba07c15 100644
--- a/sysfs.cpp
+++ b/sysfs.cpp
@@ -221,13 +221,15 @@ std::string findHwmonFromDevPath(const std::string& devPath)
path.replace(pos, 2, ":");
}
- for (const auto& hwmonInst : fs::directory_iterator(path))
+ auto dir_iter = fs::directory_iterator(path);
+ auto hwmonInst = std::find_if(
+ dir_iter, end(dir_iter), [](const fs::directory_entry& d) {
+ return (d.path().filename().string().find("hwmon") !=
+ std::string::npos);
+ });
+ if (hwmonInst != end(dir_iter))
{
- if ((hwmonInst.path().filename().string().find("hwmon") !=
- std::string::npos))
- {
- return hwmonInst.path();
- }
+ return hwmonInst->path();
}
}
catch (const std::exception& e)
OpenPOWER on IntegriCloud