Namespaces
Variants
Views
Actions

std::chrono::duration::operator+(unary), std::chrono::duration::operator-(unary)

From cppreference.com
< cpp‎ | chrono‎ | duration
Revision as of 16:27, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
 
 

Template:ddcl list begin <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
constexpr duration operator+() const;
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
constexpr duration operator-() const;
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

Implements unary plus and unary minus for the durations.

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

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

Contents

Parameters

(none)

Return value

1) a copy of this duration object
2) a copy of this duration object, with the number of ticks negated

Example

#include <chrono>
#include <iostream>
 
int main()
{
    std::chrono::seconds s1(10);
    std::chrono::seconds s2 = -s1;
 
    std::cout << "negated 10 seconds are " << s2.count() << " seconds\n";
}

Output:

negated 10 seconds are -10 seconds

See also

Template:cpp/chrono/duration/dcl list operator arith2Template:cpp/chrono/duration/dcl list operator arith4