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 ? "は" : "は") << " 宇宙の年齢を年単位で保持" << (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 ? "は" : "は") << " 宇宙の年齢を秒単位で保持" << (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 を返す
(公開静的メンバ関数) |