std::chrono::duration<Rep,Period>::max
From cppreference.com
 
 
 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Date and time library 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
(C++11)
(C++20)
  (C++20)
(C++11)
(C++11)
(C++11)
(C++20)
(C++20)
(C++20)
(C++11)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
  (C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
std::chrono::duration 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Member functions
duration::max
 Non-member functions
(until C++20)(C++20)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++20)
 Helper classes
static constexpr duration max();
 
 (until C++20)
static constexpr duration max() noexcept;
 
 (since C++20) 
Returns a duration with the largest possible value.
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.
Contents
[edit] Parameters
(none)
[edit] Return value
duration(std::chrono::duration_values <rep>::max())
[edit] Example
Run this code
#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 ≈ k1/H0 = k2/42 constexpr uint64_t seconds_per_year{365'25 * 24 * 36}; // 3651⁄4 ×ばつ 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"; }
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.