18 #ifndef __itkGenericUtilities_h
19 #define __itkGenericUtilities_h
45 template<
class TInputIter >
46 std::pair< TInputIter, TInputIter >
min_max_element(TInputIter first, TInputIter last)
48 std::pair< TInputIter, TInputIter > result(first, first);
55 while ( ++first != last )
57 TInputIter prev = first;
58 if ( ++first == last )
60 if ( *prev < *( result.first ) )
64 if ( *( result.second ) < *prev )
70 else if ( *first < *prev )
72 if ( *first < *( result.first ) )
76 if ( *( result.second ) < *prev )
83 if ( *prev < *( result.first ) )
87 if ( *( result.second ) < *first )
89 result.second = first;
101 template<
class TInputIter,
class TCompare >
102 std::pair< TInputIter, TInputIter >
min_max_element(TInputIter first, TInputIter last, TCompare comp)
104 std::pair< TInputIter, TInputIter > result(first, first);
111 while ( ++first != last )
113 TInputIter prev = first;
114 if ( ++first == last )
116 if ( comp( *prev, *( result.first ) ) )
120 if ( comp(*( result.second ), *prev) )
122 result.second = prev;
126 else if ( comp(*first, *prev) )
128 if ( comp( *first, *( result.first ) ) )
130 result.first = first;
132 if ( comp(*( result.second ), *prev) )
134 result.second = prev;
139 if ( comp( *prev, *( result.first ) ) )
143 if ( comp(*( result.second ), *first) )
145 result.second = first;
153 #endif //__itkGenericUtilities_h