Cppreferences থেকে
std::chrono::years (since C++20) duration</*signed integer type of at least 17 bits*/, std::ratio<31556952>>
ব্যবহার libc++তা নিম্নরেখাঙ্কিত স্টোরেজ বলে মনে হয় std::chrono::yearsহয় shortযা সাইন করা হয়েছে 16 বিট ।
std::chrono::years( 30797 ) // yields 32767/01/01
std::chrono::years( 30797 ) + 365d // yields -32768/01/01 apparently UB
সিপ্রিফারেন্স বা অন্য কিছু নিয়ে টাইপো আছে ?
উদাহরণ:
#include <fmt/format.h>
#include <chrono>
template <>
struct fmt::formatter<std::chrono::year_month_day> {
char presentation = 'F';
constexpr auto parse(format_parse_context& ctx) {
auto it = ctx.begin(), end = ctx.end();
if (it != end && *it == 'F') presentation = *it++;
# ifdef __exception
if (it != end && *it != '}') {
throw format_error("invalid format");
}
# endif
return it;
}
template <typename FormatContext>
auto format(const std::chrono::year_month_day& ymd, FormatContext& ctx) {
int year(ymd.year() );
unsigned month(ymd.month() );
unsigned day(ymd.day() );
return format_to(
ctx.out(),
"{:#6}/{:#02}/{:#02}",
year, month, day);
}
};
using days = std::chrono::duration<int32_t, std::ratio<86400> >;
using sys_day = std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<int32_t, std::ratio<86400> >>;
template<typename D>
using sys_time = std::chrono::time_point<std::chrono::system_clock, D>;
using sys_day2 = sys_time<days>;
int main()
{
auto a = std::chrono::year_month_day(
sys_day(
std::chrono::floor<days>(
std::chrono::hours( (1<<23) - 1 )
)
)
);
auto b = std::chrono::year_month_day(
sys_day(
std::chrono::floor<days>(
std::chrono::minutes( (1l<<29) - 1 )
)
)
);
auto c = std::chrono::year_month_day(
sys_day(
std::chrono::floor<days>(
std::chrono::seconds( (1l<<35) - 1 )
)
)
);
auto e = std::chrono::year_month_day(
sys_day(
std::chrono::floor<days>(
std::chrono::days( (1<<25) - 1 )
)
)
);
auto f = std::chrono::year_month_day(
sys_day(
std::chrono::floor<days>(
std::chrono::weeks( (1<<22) - 1 )
)
)
);
auto g = std::chrono::year_month_day(
sys_day(
std::chrono::floor<days>(
std::chrono::months( (1<<20) - 1 )
)
)
);
auto h = std::chrono::year_month_day(
sys_day(
std::chrono::floor<days>(
std::chrono::years( 30797 ) // 0x7FFF - 1970
)
)
);
auto i = std::chrono::year_month_day(
sys_day(
std::chrono::floor<days>(
std::chrono::years( 30797 ) // 0x7FFF - 1970
) + std::chrono::days(365)
)
);
fmt::print("Calendar limit by duration's underlining storage:\n"
"23 bit hour : {:F}\n"
"29 bit minute : {:F}\n"
"35 bit second : {:F}\n"
"25 bit days : {:F}\n"
"22 bit week : {:F}\n"
"20 bit month : {:F}\n"
"16? bit year : {:F}\n"
"16? bit year+365d : {:F}\n"
, a, b, c, e, f, g, h, i);
}
[ গডবোল্ট লিঙ্ক ]
std::chrono::years( 30797 ) + 365dসংকলন করে না
years{30797} + days{365}216s এর ইউনিট 204528013 হয়।
hours{2} + seconds{5}।
durationনাম বহুবচন হল: years, months, days। Calendrical উপাদান নাম একবচন আছেন: year, month, day। year{30797} + day{365}একটি সংকলন-সময় ত্রুটি। year{2020}এই বছর হয়। years{2020}2020 বছর দীর্ঘ সময়কাল।
yearব্যাপ্তি: eel.is/c++draft/time.cal.year# মেম্বার 19-19yearsরেঞ্জ: eel.is/c++draft/time.syn ।yearএটি নাগরিক বছরের "নাম" এবং 16 বিটগুলির প্রয়োজন requiresyearsএকটি ক্রোনো সময়কাল, একটি হিসাবে একই জিনিস নয়year। একজন দুটি বিয়োগ করতে পারেyearএবং ফলাফলের ধরন রয়েছেyears।yearsএর ফলাফলটি ধারণ করতে সক্ষম হতে হবেyear::max() - year::min()।