std::chrono::duration<Rep,Period>:: max
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
static
constexpr
duration max
(
)
;
|
(до C++20) | |
|
static
constexpr
duration max
(
)
noexcept
;
|
(начиная с C++20) | |
Возвращает длительность с максимально возможным значением.
Если представление
rep
длительности требует, чтобы другая реализация возвращала длительность максимальной длины,
std::chrono::duration_values
может быть специализирована для возврата требуемого значения.
Содержание |
Параметры
(нет)
Возвращаемое значение
duration ( std:: chrono :: duration_values < rep > :: max ( ) )
Пример
#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) << "Возраст Вселенной составляет ≈ " << static_cast<double>(age_of_universe_in_years) << " лет или " << static_cast<double>(age_of_universe_in_seconds) << " секунд.\n\n" << "chrono::years::max() = " << chrono_years_max << ", sizeof(chrono::years) = " << sizeof(std::chrono::years) << " байт.\n" "chrono::years " << (age_of_universe_in_years <= chrono_years_max ? "МОЖЕТ" : "НЕ МОЖЕТ") << " хранить Возраст Вселенной в ГОДАХ.\n\n" << "chrono::seconds::max() = " << chrono_seconds_max << ", sizeof(chrono::seconds) = " << sizeof(std::chrono::seconds) << " байт.\n" "chrono::seconds " << (age_of_universe_in_seconds <= chrono_seconds_max ? "МОЖЕТ" : "НЕ МОЖЕТ") << " хранить Возраст Вселенной в СЕКУНДАХ.\n"; }
Возможный вывод:
Возраст Вселенной составляет ≈ 1.38e+10 лет или 4.35e+17 секунд. chrono::years::max() = 2147483647, sizeof(chrono::years) = 4 байт. chrono::years НЕ МОЖЕТ хранить Возраст Вселенной в ГОДАХ. chrono::seconds::max() = 9223372036854775807, sizeof(chrono::seconds) = 8 байт. chrono::seconds МОЖЕТ хранить Возраст Вселенной в СЕКУНДАХ.
Смотрите также
|
[static]
|
возвращает специальное значение длительности zero
(публичная статическая функция-член) |
|
[static]
|
возвращает специальное значение длительности min
(публичная статическая функция-член) |