namespace std {
template <class charT>
struct formatter<chrono::month_weekday_last, charT>;
}
概要
month_weekday_lastクラスに対するstd::formatterクラステンプレートの特殊化。
フォーマットフラグとしては、monthとweekday_lastで利用可能なフォーマットフラグを使用できる。
例
#include <iostream>
#include <chrono>
#include <format>
namespace chrono = std::chrono;
int main() {
chrono::month_weekday_last date = chrono::March/chrono::Sunday[chrono::last];
// デフォルトフォーマットはoperator<<と同じ
std::cout << std::format("1 : {}", date) << std::endl;
std::cout << std::format("2 : {:%B, %A}", date) << std::endl;
std::cout << std::format("3 : {:%m, %a}", date) << std::endl;
// ロケール依存の出力
std::cout << std::format(std::locale("ja_JP.UTF-8"), "4 : {:%b, %a}", date) << std::endl;
std::cout << std::format(std::locale("ja_JP.UTF-8"), "5 : {:%b, %A}", date) << std::endl;
}
出力
1 : Mar/Sun[last]
2 : March, Sunday
3 : 03, Sun
4 : 3月, 日
4 : 3月, 日曜日
バージョン
言語
- C++20
処理系
- Clang: 9.0 ❌
- GCC: 9.2 ❌, 15.1 ✅
- Visual C++: 2019 Update 3 ❌
関連項目
- chronoの
std::format()(フォーマットの詳細)