std::chrono::duration<Rep,Period>:: max
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
static
constexpr
duration max
(
)
;
|
(hasta C++20) | |
|
static
constexpr
duration max
(
)
noexcept
;
|
(desde C++20) | |
Devuelve una duración con el valor máximo posible.
Si la representación
rep
de la duración requiere que alguna otra implementación devuelva una duración de longitud máxima,
std::chrono::duration_values
puede especializarse para devolver el valor deseado.
Contenidos |
Parámetros
(ninguno)
Valor de retorno
duration ( std:: chrono :: duration_values < rep > :: max ( ) )
Ejemplo
#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) << "La Edad del Universo es ≈ " << static_cast<double>(age_of_universe_in_years) << " años o " << static_cast<double>(age_of_universe_in_seconds) << " segundos.\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 ? "PUEDE" : "NO PUEDE") << " almacenar la Edad del Universo en AÑOS.\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 ? "PUEDE" : "NO PUEDE") << " almacenar la Edad del Universo en SEGUNDOS.\n"; }
Salida posible:
La Edad del Universo es ≈ 1.38e+10 años o 4.35e+17 segundos. chrono::years::max() = 2147483647, sizeof(chrono::years) = 4 bytes. chrono::years NO PUEDE almacenar la Edad del Universo en AÑOS. chrono::seconds::max() = 9223372036854775807, sizeof(chrono::seconds) = 8 bytes. chrono::seconds PUEDE almacenar la Edad del Universo en SEGUNDOS.
Véase también
|
[static]
|
devuelve el valor de duración especial zero
(función miembro pública estática) |
|
[static]
|
devuelve el valor de duración especial min
(función miembro pública estática) |