std::chrono::year_month_day_last
From cppreference.com
| ヘッダー <chrono> で定義 |
||
| class year_month_day_last; |
(C++20以降) | |
クラスyear_month_day_lastは、特定の年と月の最終日を表します。これはフィールドベースの時間点であり、解像度はstd::chrono::daysですが、月に一度しか最終日を表現できないという制限があります。
std::chrono::yearsとstd::chrono::monthsを基にした算術演算が直接サポートされています。std::chrono::sys_daysへの暗黙的な変換により、std::chrono::daysを基にした算術演算を効率的に実行できます。
year_month_day_lastは、TriviallyCopyableかつStandardLayoutTypeです。
目次 |
[編集] メンバ関数
year_month_day_lastオブジェクトを構築します(public member function) | |
| 月または年数によって時間点を変更します。 (public member function) | |
| このオブジェクトのフィールドにアクセスします。 (public member function) | |
| std::chrono::time_point に変換します。 (public member function) | |
| このオブジェクトが有効な日付を表すかどうかをチェックします。 (public member function) |
[編集] 非メンバ関数
| (C++20) |
2つのyear_month_day_last値を比較します(function) |
| (C++20) |
year_month_day_last と年または月の数値を加算または減算する(関数) |
| (C++20) |
year_month_day_lastをストリームに出力します(function template) |
[編集] ヘルパークラス
year_month_day_last の書式設定サポート(クラス テンプレートの特殊化) | |
| std::chrono::year_month_day_lastのハッシュサポート (クラステンプレートの特殊化) |
[編集] 例
このコードを実行
#include <chrono> #include <iostream> int main() { const auto ymd = std::chrono::year_month_day { std::chrono::floor<std::chrono::days>(std::chrono::system_clock::now()) }; const std::chrono::year_month_day_last ymdl { ymd.year(), ymd.month() / std::chrono::last }; std::cout << "The last day of present month (" << ymdl << ") is: " << std::chrono::year_month_day{ymdl}.day() << '\n'; // The 'last' object can be placed wherever it is legal to place a 'day': using namespace std::chrono; constexpr std::chrono::year_month_day_last ymdl1 = 2023y / February / last, ymdl2 = last / February / 2023y, ymdl3 = February / last / 2023y; static_assert(ymdl1 == ymdl2 && ymdl2 == ymdl3); }
実行結果の例
The last day of present month (2023/Aug/last) is: 31
[編集] 関連項目
| (C++20) |
特定のyear、month、dayを表す (クラス) |