Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ abs template

template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr T abs(T n)
{
  	if constexpr (std::is_signed_v<T>)
  	{
    	return n >= 0 ? n : -n;
  	}
	return n;
}
 
PREVIOUS NEXT
Tagged: #abs #template
ADD COMMENT
Topic
Name
7+1 =