std::chrono...or+(unary),(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… 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:

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

🌸 Parameters 🌸

(none) β€” literally nobody, empty handed, nothing to pass in πŸ™ˆ


πŸŽ€ Return value πŸŽ€

  1. A copy of this duration object. Just a lil copy, iconic, unchanged πŸ’…
  2. 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