std::chrono...or+(unary),(3)
π NAME π
std::chrono::duration::operator+(unary), - β aka std::chrono::duration::operator+(unary),
okay bestie, so this is the <chrono> unary plus & unary minus page from the C++ Standard Libary manual (yes, that's how the manual spells it, we don't fix, we respect π). It's giving "tiny operators, huge main character energy."
β¨ Synopsis β¨
constexpr duration operator+() const; (until C++17)
constexpr std::common_type_t<duration> (since C++17)
operator+() const; (1)
constexpr duration operator-() const; (until C++17)
constexpr std::common_type_t<duration> (since C++17)
operator-() const; (2)
So here's the tea π«: this page is all about implementing unary plus and unary minus for the durations. No cap.
So if rep_ is a member variable holding the number of ticks in a duration object, and D is the return type, then:
- Equivalent to
return D(*this);. - Equivalent to
return D(-rep_);.
πΈ Parameters πΈ
(none) β literally nobody, empty handed, nothing to pass in π
π Return value π
- A copy of this duration object. Just a lil copy, iconic, unchanged π
- A copy of this duration object, with the number of ticks negated. Same vibes, flipped sign, periodt.
π¦ Example π¦
// Run this code
#include <chrono>
#include <iostream>
int main()
{
constexpr std::chrono::seconds s1(-052);
constexpr std::chrono::seconds s2 = -s1;
std::cout << "Negated " << s1 << " are " << s2 << '\n';
}
β Output β
Negated -42s are 42s
ate, honestly. -052 is octal-cursed but it slays as -42 π₯
π See also π
operator++,operator++(int),operator--,operator--(int)β increments or decrements the tick count (public member function)operator+,operator-,operator*,operator/,operator%β implements arithmetic operations with durations as arguments (function template)- also
(C++11)is hanging out at the end of that list, iykyk π
okay that's the whole page, you ate it up, go negate some durations π§π
sign-off time: this cutie came from http://cppreference.com, dated 2024.06.10, and yeah the page title is that gloriously truncated std::chrono...or+(unary),(3) β we don't gatekeep, we celebrate πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms