py::builtins::abs¶
Defined in <pypp/builtins/abs.hpp>
template <class type>
auto abs(const type& x) -> decltype(x * 1)
Returns the absolute value of x.
Template parameters¶
type: The type of paramter.
Requirement of type
type must be a scalar type or any other type meeting the
following requirements:
Comparable with operator
<Multiplable with operator
*
Parameters¶
x: The value whose absolute value to return.
Return value¶
The absolute value of x. The type of return value is
decltype(x * 1).
Complexity¶
Constant.
Specializing¶
py::builtins::abs specialized as the following when the return
value and the parameter type is same:
template <>
/* type */ py::builtins::abs< /* type */ >(const /* type */ & x);
Example¶
#include <pypp/builtins/abs.hpp>
#include <pypp/builtins/print.hpp>
int main()
{
py::print(py::abs(-5));
}
Output:
5