std::chrono::duration::max(3)
β¨ NAME β¨
std::chrono::duration::max β std::chrono::duration::max
okay bestie, welcome to the std::chrono::duration::max(3) page from the C++ Standard Libary manual (yes, thatβs the manual name, keeping it exactly, no cap π). This is the static cutie that hands you the biggest duration value possible. ππ
πΈ Synopsis πΈ
static constexpr duration max(); (until C++20)
static constexpr duration max() noexcept; (since C++20)
Returns a duration with the largest possible value. literally the maximum-length duration energy β¨
If the representation rep of the duration requires some other implementation to return a maximum-length duration, std::chrono::duration_values can be specialized to return the desired value. π«Ά important caveat, bestie, donβt skip it.
π Parameters π
(none) β she takes zero arguments, main character with no entourage π
π¦ Return value π¦
duration(std::chrono::duration_values<rep>::max())
π₯ Example π₯
#include <chrono>
#include <cstdint>
#include <iomanip>
#include <iostream>
int main()
{
constexpr uint64_t chrono_years_max =
std::chrono::years::max().count();
constexpr uint64_t chrono_seconds_max =
std::chrono::seconds::max().count();
constexpr uint64_t age_of_universe_in_years{13'787'000'000}; //
Ξ-CDM β kβ/Hβ = kβ/42
constexpr uint64_t seconds_per_year{365'25 * 24 * 36}; // 365ΒΌ Γ 24
Γ 60 Γ 60
constexpr uint64_t
age_of_universe_in_seconds{age_of_universe_in_years *
seconds_per_year};
std::cout
<< std::scientific << std::setprecision(2)
<< "The Age of the Universe is β "
<< static_cast<double>(age_of_universe_in_years) << " years or
"
<< static_cast<double>(age_of_universe_in_seconds) << "
seconds.\n\n"
<< "chrono::years::max() = " << chrono_years_max
<< ", sizeof(chrono::years) = "
<< sizeof(std::chrono::years) << " bytes.\n" "chrono::years "
<< (age_of_universe_in_years <= chrono_years_max ? "CAN" :
"CANNOT")
<< " keep the Age of the Universe in YEARS.\n\n"
<< "chrono::seconds::max() = " << chrono_seconds_max
<< ", sizeof(chrono::seconds) = "
<< sizeof(std::chrono::seconds) << " bytes.\n" "chrono::seconds
"
<< (age_of_universe_in_seconds <= chrono_seconds_max ? "CAN" :
"CANNOT")
<< " keep the Age of the Universe in SECONDS.\n";
}
// Run this code β yes bestie, run it, itβs giving big brain astronomy vibes ππ«
π Possible output π
The Age of the Universe is β 1.38e+10 years or 4.35e+17 seconds.
chrono::years::max() = 2147483647, sizeof(chrono::years) = 4 bytes.
chrono::years CANNOT keep the Age of the Universe in YEARS.
chrono::seconds::max() = 9223372036854775807, sizeof(chrono::seconds) =
8 bytes.
chrono::seconds CAN keep the Age of the Universe in SECONDS.
π See also π
zeroβ returns the special duration value zero[static] (public static member function)minβ returns the special duration value min[static] (public static member function)
mwah π this iconic little page came from http://cppreference.com, dated 2024.06.10 β stay sliving, bestie π«Άβ¨
π¦ 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