std::chrono::abs(std::chrono::duration) - cppreference.com (original) (raw)
Returns the absolute value of the duration d. Specifically, if d >= d.zero(), return d, otherwise return -d.
The function does not participate in the overload resolution unless std::numeric_limits<Rep>::is_signed is true.
[edit] Parameters
[edit] Return value
Absolute value of d.
[edit] Possible implementation
[edit] Example
#include #include int main() { using namespace std::chrono; static_assert(abs(-42s) == std::chrono::abs(42s)); std::cout << "abs(+3min) = " << abs(3min).count() << '\n' << "abs(-3min) = " << abs(-3min).count() << '\n'; }
Output:
abs(+3min) = 3 abs(-3min) = 3