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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -