stl - Find the minimum number +ve number in c++? -
i want find minimum number using stl in c++, know syntax should min(x,y). want find minimum +ve numbers in list. not inlcuding -ves. how do that? p.s numbers in array for finding minimum number, makes sense use std::min_element . fortunately, comes optional comparison parameter, can make use of: ( sample here ) auto pos = std::min_element(std::begin(arr), std::end(arr), [](const t &t1, const t &t2) {return t1 > 0 && (t2 <= 0 || t1 < t2);} ); you have careful take account if it's comparing positive t1 negative number, should true. if none of elements positive, give location of first number in array. if 0 should treated part of positives, change t1 > 0 t1 >= 0 , t2 <= 0 t2 < 0 .