Commit fb193b02d497e0a3f2e8439e72aa4be99d92c271
1 parent
a3d504b5
generalized some Common functions to operate on templated data structures
Showing
1 changed file
with
8 additions
and
8 deletions
openbr/core/common.h
| ... | ... | @@ -72,8 +72,8 @@ QList< QPair<T,int> > Sort(const QList<T> &vals, bool decending = false, int n = |
| 72 | 72 | /*! |
| 73 | 73 | * \brief Returns the minimum, maximum, minimum index, and maximum index of a vector of values. |
| 74 | 74 | */ |
| 75 | -template <typename T> | |
| 76 | -void MinMax(const QList<T> &vals, T *min, T *max, int *min_index, int *max_index) | |
| 75 | +template <template<class> class V, typename T> | |
| 76 | +void MinMax(const V<T> &vals, T *min, T *max, int *min_index, int *max_index) | |
| 77 | 77 | { |
| 78 | 78 | const int size = vals.size(); |
| 79 | 79 | assert(size > 0); |
| ... | ... | @@ -92,23 +92,23 @@ void MinMax(const QList<T> &vals, T *min, T *max, int *min_index, int *max_index |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | -template <typename T> | |
| 96 | -void MinMax(const QList<T> &vals, T *min, T *max) | |
| 95 | +template <template<class> class V, typename T> | |
| 96 | +void MinMax(const V<T> &vals, T *min, T *max) | |
| 97 | 97 | { |
| 98 | 98 | int min_index, max_index; |
| 99 | 99 | MinMax(vals, min, max, &min_index, &max_index); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | -template <typename T> | |
| 103 | -T Min(const QList<T> &vals) | |
| 102 | +template <template<class> class V, typename T> | |
| 103 | +T Min(const V<T> &vals) | |
| 104 | 104 | { |
| 105 | 105 | T min, max; |
| 106 | 106 | MinMax(vals, &min, &max); |
| 107 | 107 | return min; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | -template <typename T> | |
| 111 | -T Max(const QList<T> &vals) | |
| 110 | +template <template<class> class V, typename T> | |
| 111 | +T Max(const V<T> &vals) | |
| 112 | 112 | { |
| 113 | 113 | T min, max; |
| 114 | 114 | MinMax(vals, &min, &max); | ... | ... |