Refactor extended namespace std

  absolute-value, c++, std, undefined-behavior

I have a large project where namespace std is extended with std::abs for a custom type like in the following example.

struct A {
    int a;
};

namespace std {
    template <int i>
    auto abs(A<i> const& x) -> A<i>
    {
        return A<i>(std::abs(x.a));
    }
}

From my understanding, this is undefined behaviour, as it is not a template specialisation for std::abs, so I would like to refactor this. Is there any way to reasonably do this? The call std::abs(A<i>) is often used.

Source: Windows Questions C++

LEAVE A COMMENT