use STL to calculate L1 distance and max norm

This commit is contained in:
Tiago Gomes
2012-05-29 13:48:08 +01:00
parent 3ac854b2ff
commit 6feb746412
2 changed files with 49 additions and 31 deletions

View File

@@ -382,5 +382,41 @@ std::ostream& operator << (std::ostream& os, const vector<T>& v)
return os;
}
namespace FuncObject {
template<typename T>
struct max : public std::binary_function<T, T, T>
{
T operator() (const T& x, const T& y) const
{
return x < y ? y : x;
}
};
template <typename T>
struct abs_diff : public std::binary_function<T, T, T>
{
T operator() (const T& x, const T& y) const
{
return std::abs (x - y);
}
};
template <typename T>
struct abs_diff_exp : public std::binary_function<T, T, T>
{
T operator() (const T& x, const T& y) const
{
return std::abs (std::exp (x) - std::exp (y));
}
};
}
#endif // HORUS_UTIL_H