[STL] Is there a std::abs<>() function?

Hello, It's strange to me that there seems not to be a std::abs<>() function in STL, with it I can write code like this: double d = std::abs(-1.0); int i = std::abs(-1); Does anybody else have the same feeling? Being uncomfortable with the abcence of it, I've wrote my own version in my namespace: #include <boost/utility/value_init.hpp> // my abs function // it works not only for POD types, but also for // user types that are default constructible and // support operator<() and unary operator-() template<class T> T abs(const T & x) { static boost::value_initialized<T> zero; return (x < zero? -x : x); } Thanks for any information. Best regards Max ------------------------------------------------------------------- 新浪空间——与朋友开心分享网络新生活!(http://space.sina.com.cn/ )

Max schrieb:
Hello,
It's strange to me that there seems not to be a std::abs<>() function in STL, with it I can write code like this:
double d = std::abs(-1.0); int i = std::abs(-1);
Does anybody else have the same feeling?
#include <cmath> double d = std::abs (-1.0); cmath pulls the standard math functions into the std namespace, and adds a few overloads. See for example: http://www.dinkumware.com/manuals/?manual=compleat&page=math.html#abs Cheers, Anteru
participants (2)
-
Anteru
-
Max