##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::chrono::abs(std::chrono::duration)

From cppreference.com
< cpp‎ | chrono‎ | duration

Defined in header `<chrono>` |  |
template <class Rep, class Period> constexpr duration<Rep, Period> abs(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.

### [edit] Parameters

d | - | duration

### [edit] Return value

Absolute value of `d`

### [edit] Possible implementation

    template <class Rep, class Period, class = std::enable_if_t<
       std::chrono::duration<Rep, Period>::min() < std::chrono::duration<Rep, Period>::zero()>>
    constexpr std::chrono::duration<Rep, Period> abs(duration<Rep, Period> d)
    {
        return d >= d.zero() ? d : -d;
    }

### [edit] Example

| This section is incomplete Reason: no example

### [edit] See also

operator+operator- | implements unary + and unary - (public member function) [edit]
abs(int)labs llabs (C++11) | computes absolute value of an integral value (|x|) (function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/chrono/duration/abs&oldid=81533"
Category:

- Todo no example