C++ Weekly - Ep 397 - std::chrono Quickstart With C++20 Calendars! #cpp #cplusplus #cpp20 #calendar

preview_player
Показать описание
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟

T-SHIRTS AVAILABLE!

WANT MORE JASON?

SUPPORT THE CHANNEL

GET INVOLVED

JASON'S BOOKS

► C++23 Best Practices

► C++ Best Practices

JASON'S PUZZLE BOOKS

► Object Lifetime Puzzlers Book 1

► Object Lifetime Puzzlers Book 2

► Object Lifetime Puzzlers Book 3

► Copy and Reference Puzzlers Book 1

► Copy and Reference Puzzlers Book 2

► Copy and Reference Puzzlers Book 3

► OpCode Puzzlers Book 1


RECOMMENDED BOOKS

AWESOME PROJECTS

O'Reilly VIDEOS

Рекомендации по теме
Комментарии
Автор

I think there are two more things about the example that are worth mentioning:

- The use of duration_cast is needed only when you lose precision (e.g., casting us -> ms is imprecise, as it requires rounding down, whereas assigning ms to us is perfectly fine).
- The reason why one can't subtract timepoints from two different clocks is commonly because it is meaningless. Two clocks may not share the same timebase and epochs. If it is really needed, the somewhat acceptable way to perform subtraction is by using time_since_epoch() to obtain the "duration" and then performing the subtraction.

janmacheta
Автор

Chrono is great. Haven't had the chance yet to look into the calendar features yet. Thank you for the video, Jason!

dextercd_
Автор

These calendar features are really neat!!

KhalilEstell
Автор

I was expecting to see something about the chrono string literal operators, they are really handy.

sarok
Автор

The output of the floor example was just really weird and counter intuitive. It left me feeling as a user that I don't know what the function is actually supposed to do. I was surprised that the video just passed over it without commenting on it!

CharlesHogg
Автор

@lefticus Please please please do a series on chrono. Time management in C++ is a huge bugbear for me and patently I ( and ChatGPT for that matter) don't know how to use this library. In Java, Python and even C, time management is pretty straightforward but I always seem to wind up with strange artifacts or behaviour e.g where timers don't update for some reason.

JeremyCoppin
Автор

How did the floor function move to the previous day?

hbburlingame
Автор

hmm, seems to not be supported by msvc latest (19 something) and needs clang15 or gcc12 (after some quick tryouts on compiler explorer), can't use it for now :(

frydac
Автор

I agree with others here in the assessment that it works but it's not simple to use, I always find myself having to look for examples to do simple things. Where the strong typing really starts to suck is any type of unit test that needs to mock the clock type...don't get me started...

aklcraigc
Автор

I agree. It seems overly complicated. Maybe it's improved since I last tried it but it was painful a few years ago when j tried it.

Lalasoth
Автор

This video just proves that "quickstarting" is not a good thing.
Jason should have first taken a look at the video: Opening Keynote Meeting C++ 2019 - Howard Hinnant - Design Rationale for the chrono Library
There it is shown how to use the library correctly.

schekla
Автор

high_resolution_clock is obviously the one you're going to use for any kind of timing or profiling as what you want is right there in the name - high resolution. That should be the one that isn't adjusted and WTF is "steady" meant to mean anyway? Stupid naming.

I'm not a fan of using namespace but I tend to do it for std::chrono as it quickly becomes a nightmare as you clearly see in this example.

Talon-txih
Автор

ah yes, the dreaded std::chrono. Sometimes it almost feels better to use c's time primitives than making a bunch of aliases or 'using namespace std::chrono's in local scopes

Raspredval
Автор

I get it that people think all conversions need to be explicit these days, but it's really tiresome. Obviously I don't want C++ to be JavaScript, because that's how the world ends, but some things are just obvious and I feel like as large as chrono is, the committee just didn't go far enough in its design. I want more implicit conversions where they make sense, not less overall just because someone thinks that explicit is always the way. And yeah, some direction is necessary to make sense of things, but I don't want to hold its hand the whole way through. However, I will say this, they had a good start with the time literals to quickly input various time aspects, it just needs more.

anon_y_mousse