std::chrono::duration::operator++, std::chrono::duration::operator-- - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::chrono::duration::operator++, std::chrono::duration::operator--

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

| (1) |
duration& operator++(); |  | (until C++17)
constexpr duration& operator++(); |  | (since C++17)
| (2) |
duration operator++(int); |  | (until C++17)
constexpr duration operator++(int); |  | (since C++17)
| (3) |
duration& operator--(); |  | (until C++17)
constexpr duration& operator--(); |  | (since C++17)
| (4) |
duration operator--(int); |  | (until C++17)
constexpr duration operator--(int); |  | (since C++17)

Increments or decrements the number of ticks for this duration.

If `rep_` is a member variable holding the number of ticks in a duration object,

1) Equivalent to ++rep_; return *this;
2) Equivalent to return duration(rep_++)
3) Equivalent to --rep_; return *this;
4) Equivalent to return duration(rep_--);

### [edit] Parameters

(none)

### [edit] Return value

1,3) a reference to this duration after modification
2,4) a copy of the duration made before modification

### [edit] Example

Run this code

    #include <chrono>
    #include <iostream>

    int main()
    {
        std::chrono::hours h(1);
        std::chrono::minutes m = ++h;
        m--;
        std::cout << m.count() << " minutes\n";
    }

Output:

    119 minutes

### [edit] See also

operator+=operator-=operator*=operator/=operator%= | implements compound assignment between two durations (public member function) [edit]
operator+operator-operator*operator/operator% | implements arithmetic operations with durations as arguments (function template) [edit]

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