We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
時間型 ( std::chrono::duration ) を fmt に対応させることを提案します。
std::chrono::duration
# include <Siv3D.hpp> // OpenSiv3D v0.6.5 void Main() { Print << 1h + 3s; //Print << U"{}"_fmt(1h + 3s); // error! while (System::Update()); }
s3d::Format
# include <Siv3D.hpp> // OpenSiv3D v0.6.5 template <class Rep, class Period> struct SIV3D_HIDDEN fmt::formatter<std::chrono::duration<Rep, Period>, s3d::char32> { std::u32string tag; auto parse(basic_format_parse_context<s3d::char32>& ctx) { return s3d::detail::GetFormatTag(tag, ctx); } template <class FormatContext> auto format(const std::chrono::duration<Rep, Period>& value, FormatContext& ctx) { const s3d::String s = s3d::Format(value); const basic_string_view<s3d::char32> sv(s.data(), s.size()); if (tag.empty()) { return format_to(ctx.out(), U"{}", sv); } else { const std::u32string format = (U"{:" + tag + U'}'); return format_to(ctx.out(), format, sv); } } }; void Main() { Print << 1h + 3s; Print << U"{}"_fmt(1h + 3s); while (System::Update()); }
fmt::format
s3d::Literals::FormatLiterals::operator ""_fmt
s3d::Microseconds
μs
us
# include <Siv3D.hpp> // OpenSiv3D v0.6.5 template <class Rep, class Period> struct SIV3D_HIDDEN fmt::formatter<std::chrono::duration<Rep, Period>, s3d::char32> { std::u32string tag; auto parse(basic_format_parse_context<s3d::char32>& ctx) { return s3d::detail::GetFormatTag(tag, ctx); } template <class FormatContext> auto format(const std::chrono::duration<Rep, Period>& value, FormatContext& ctx) { const s3d::String s = s3d::Unicode::Widen(fmt::format("{}", value)); const basic_string_view<s3d::char32> sv(s.data(), s.size()); if (tag.empty()) { return format_to(ctx.out(), U"{}", sv); } else { const std::u32string format = (U"{:" + tag + U'}'); return format_to(ctx.out(), format, sv); } } }; void Main() { using Picoseconds = std::chrono::duration<int64, std::pico>; using FemtosecondsF = std::chrono::duration<double, std::femto>; //Print << Picoseconds{ 42 }; // error! Print << U"{}"_fmt(Picoseconds{ 42 }); Print << U"{}"_fmt(FemtosecondsF{ 42 }); Print << U"{}"_fmt(std::chrono::years{ 42 }); { // 標準の出力と同じ std::ostringstream oss; oss << Picoseconds{ 42 }; assert(U"{}"_fmt(Picoseconds{ 42 }) == Unicode::Widen(oss.str())); } while (System::Update()); }
The text was updated successfully, but these errors were encountered:
詳しい報告ありがとうございます! μs/us の差異は好ましくない(Siv3D は μs us で統一したい)ので、v0.6 世代では実装案 1 が良いです。 pull-request と、コメントで assert で良いので簡単なテストを合わせて送っていただければマージします。
対応する時間型を増やせる件については、v0.8 世代で調査・検討したいと思います。
Sorry, something went wrong.
Siv3D って us じゃないですか?
OpenSiv3D/Siv3D/src/Siv3D/Duration/SivDuration.cpp
Lines 248 to 251 in 4247cab
私の記憶違いでした。 us で一貫させたいです。
No branches or pull requests
時間型 (
std::chrono::duration
) を fmt に対応させることを提案します。実装案1
s3d::Format
を使う実装案2
fmt::format
を使うs3d::Literals::FormatLiterals::operator ""_fmt
の結果はfmt::format
と同じ方が自然?s3d::Microseconds
などの出力の単位が処理系定義になる (μs
orus
)The text was updated successfully, but these errors were encountered: