Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Math code snippet to make all elements in a container positive.
There are multiple ways to implement MakeAbs:
#include <algorithm> |
Note: I did not find any way to refrain from writing a functor (for example, by using std::ptr_fun) as shown in the lines below...
std::transform(v.begin(),v.end(),v.begin(),std::abs); //Does not work |
#include <cmath> |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.