| Defined in header <chrono>
|
||
| template< class Rep, class Period > constexpr std::chrono::duration<Rep, Period> abs( std::chrono::duration<Rep, Period> d ); |
(since C++17) | |
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.
Parameters
| d | - | duration |
Return value
Absolute value of d.
Possible implementation
|
Example
#include <chrono>
#include <iostream>
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';
}abs(+3min) = 3
abs(-3min) = 3See also
| implements unary + and unary - (public member function) | |
| (C++11) |
computes absolute value of an integral value (|x|) (function) |
Content from this page on cppreference.com, licensed under CC-BY-SA 3.0 and GFDL. Modified: restyled, site navigation removed, code windows added. Offline snapshot of 9 February 2025.