c++ - Find minimum value of member in list<MyStruct> using STL -
i have list of mystruct objects.
struct task { std::function<void()> _fn = nullptr; std::chrono::system_clock::time_point _exectime; };
how find minimum value of _exectime in list using stl algorithm ? can find iteration, there more elegant way this? below:
std::chrono::system_clock::time_point nearestexectime = std::min(auto t = tasks.begin(), auto p = tasks.end(), [t,p]() {return t.exectime < p.exetime;});
use std::min_element
.
std::min_element(tasks.begin(), tasks.end(), [](const task& t, const task& p) { return t._exectime < p._exectime; });
Comments
Post a Comment