std::chrono...operator++,(3)

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

🌸 NAME 🌸

hey bestie, welcome to std::chrono...operator++,(3) from the C++ Standard Libary β€” yes, β€œLibary,” typo and all, we’re keeping the lore. The actual page name is literally:

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

that comma is not a typo from me, it’s just the name, periodt. πŸ’…


✨ Synopsis ✨

ok so this is the duration increment/decrement situation. Four overloads, all since C++11 and all constexpr since C++17:

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

They increment or decrement the number of ticks for this duration.

If rep_ is a member variable holding the number of ticks in a duration object, then here’s the tea:

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

πŸ’– Parameters πŸ’–

(none) β€” no parameters, bestie. zero. nada. slay. 🫢


πŸŽ€ Return value πŸŽ€

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

πŸ¦‹ Example πŸ¦‹

here’s the whole little code moment, exactly as the page has it:

// 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

πŸ‘‘ See also πŸ‘‘

the see-also list is giving linked-list energy, so here are all the entries and their little tags exactly:

  • operator+=
  • operator-= β€” implements compound assignment between two durations
  • operator*= β€” (public member function)
  • operator/=
  • operator%=
  • operator+
  • operator-
  • operator* β€” implements arithmetic operations with durations as arguments
  • operator/ β€” (function template)
  • operator%
  • (C++11) β€” this tag is hanging out after operator% in the original list, iykyk

signing off with the footer tea: source http://cppreference.com, version/date 2024.06.10, page std::chrono...operator++,(3). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from