Тёмный

C++ Weekly - Ep 419 - The Important Parts of C++23 

C++ Weekly With Jason Turner
Подписаться 110 тыс.
Просмотров 13 тыс.
50% 1

☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟
Upcoming Workshop: Understanding Object Lifetime, C++ On Sea, July 2, 2024
► cpponsea.uk/2024/sessions/und...
Upcoming Workshop: C++ Best Practices, NDC TechTown, Sept 9-10, 2024
► ndctechtown.com/workshops/c-b...
Upcoming Workshop: Applied constexpr: The Power of Compile-Time Resources, C++ Under The Sea, October 10, 2024
► cppunderthesea.nl/workshops/
This episode is sponsored by think-cell. think-cell.com/cppweekly
Episode details: github.com/lefticus/cpp_weekl...
T-SHIRTS AVAILABLE!
► The best C++ T-Shirts anywhere! my-store-d16a2f.creator-sprin...
WANT MORE JASON?
► My Training Classes: emptycrate.com/training.html
► Follow me on twitter: / lefticus
SUPPORT THE CHANNEL
► Patreon: / lefticus
► Github Sponsors: github.com/sponsors/lefticus
► Paypal Donation: www.paypal.com/donate/?hosted...
GET INVOLVED
► Video Idea List: github.com/lefticus/cpp_weekl...
JASON'S BOOKS
► C++23 Best Practices
Leanpub Ebook: leanpub.com/cpp23_best_practi...
► C++ Best Practices
Amazon Paperback: amzn.to/3wpAU3Z
Leanpub Ebook: leanpub.com/cppbestpractices
JASON'S PUZZLE BOOKS
► Object Lifetime Puzzlers Book 1
Amazon Paperback: amzn.to/3g6Ervj
Leanpub Ebook: leanpub.com/objectlifetimepuz...
► Object Lifetime Puzzlers Book 2
Amazon Paperback: amzn.to/3whdUDU
Leanpub Ebook: leanpub.com/objectlifetimepuz...
► Object Lifetime Puzzlers Book 3
Leanpub Ebook: leanpub.com/objectlifetimepuz...
► Copy and Reference Puzzlers Book 1
Amazon Paperback: amzn.to/3g7ZVb9
Leanpub Ebook: leanpub.com/copyandreferencep...
► Copy and Reference Puzzlers Book 2
Amazon Paperback: amzn.to/3X1LOIx
Leanpub Ebook: leanpub.com/copyandreferencep...
► Copy and Reference Puzzlers Book 3
Leanpub Ebook: leanpub.com/copyandreferencep...
► OpCode Puzzlers Book 1
Amazon Paperback: amzn.to/3KCNJg6
Leanpub Ebook: leanpub.com/opcodepuzzlers_book1
RECOMMENDED BOOKS
► Bjarne Stroustrup's A Tour of C++ (now with C++20/23!): amzn.to/3X4Wypr
AWESOME PROJECTS
► The C++ Starter Project - Gets you started with Best Practices Quickly - github.com/cpp-best-practices...
► C++ Best Practices Forkable Coding Standards - github.com/cpp-best-practices...
O'Reilly VIDEOS
► Inheritance and Polymorphism in C++ - www.oreilly.com/library/view/...
► Learning C++ Best Practices - www.oreilly.com/library/view/...

Наука

Опубликовано:

 

25 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 70   
@jonasbachmann2650
@jonasbachmann2650 3 месяца назад
std::print can also print standard containers!
@TheClonerx
@TheClonerx 3 месяца назад
It can print anything that's formattable, which doesn't just include containers but also ranges!
@antoniogarest7516
@antoniogarest7516 3 месяца назад
🐐
@sinom
@sinom 3 месяца назад
​@@TheClonerx does that also include std::filesystem::paths though
@CharlesHogg
@CharlesHogg 3 месяца назад
Monadic interfaces for optional is definitely a headline feature. It makes std::optional dramatically easier to use correctly! And the paper, p0798, is a very accessible and engaging read.
@cppweekly
@cppweekly 3 месяца назад
My main problem with it is that common functions now become template functions which complicates some other things in subtle ways. But yes, it's a very important feature.
@mjKlaim
@mjKlaim 3 месяца назад
i would say `to()` is probably an important tool for ranges too, probably more often needed than zip?
@VincentZalzal
@VincentZalzal 3 месяца назад
I was about to say the same. I think zip and to will be the two most commonly used additions to ranges. No more collecting into a vector using back_inserters!
@Felianther
@Felianther 3 месяца назад
I would say even more than zip, but depends on the application really, but i have many many more places where i'll refactor into ranges::to and maybe one case for a zip once we eventually move to C++23
@not_ever
@not_ever 3 месяца назад
Yes zip is nice but I don't think ranges are very usuable (or nice to use maybe) without ranges::to
@LogicEu
@LogicEu 3 месяца назад
Wow, the stacktrace stuff looks amazing
@abirbasak1948
@abirbasak1948 3 месяца назад
Deducing this is my top ranked feature ! Now all functions has similar signature, and I do not need to know where to put the const for members
@oschonrock
@oschonrock 3 месяца назад
very useful. Actually a very useful standard c++23... lots of good stuff.
@LawnMeower
@LawnMeower 3 месяца назад
A feature of C++23 I really appreciate are the newly added float types. I think they are cool to optimize neural networks
@cppweekly
@cppweekly 3 месяца назад
Ah yes, that's on my todo list for its own episode!
@Tyranisaur
@Tyranisaur 3 месяца назад
While std::print is a great addition, I feel it only deserves the top spot if you are dealing with code where printing and strings are important. The there are so many ranges additions that it's hard not to considered those as the most impactful changes. I will also mention if consteval and monadic operations as valuable additions.
@kevindelnoye9641
@kevindelnoye9641 3 месяца назад
Ranges enumerate
@ZephyrCheez
@ZephyrCheez 3 месяца назад
One feature that I saw some buzz about right as C++20 released that was originally planned for C++23 was match statements. They seemed very versatile and modern, but it seems the feature was dropped with no word on if/when it would be added
@not_ever
@not_ever 3 месяца назад
There is a new paper as of February P2688R1. I don't know if this is the same author as whatever was supposed to go into C++20
@yogthemuskrat
@yogthemuskrat 3 месяца назад
#11 is actually called "Explicit object parameter", not "explicit this". A very interesting feature, not just for code decoupling. E.g. we've used it to get a properly typed shared_ptr from and object via the "shared_from_this" functionality.
@matthewmatthew2946
@matthewmatthew2946 3 месяца назад
☝️🤓
@deadpin
@deadpin 3 месяца назад
Huge downsides for "expected". Such a shame :(
@lame_lexem
@lame_lexem 3 месяца назад
7:33 can someone explain what optimisation is unavailable here and how it can impact the execution?
@cppweekly
@cppweekly 3 месяца назад
Return value optimization is missing if you don't use expected correctly. You get a copy or a move of the data instead of the optimal thing of creating the object in place. I *just* did an episode about this: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-0yJk5yfdih0.html
@Volker-Dirr
@Volker-Dirr 3 месяца назад
If "print" is the new "cout". What is the new "cin"?
@tiranito2834
@tiranito2834 3 месяца назад
we'll have to wait for C++ 26 or later to find out, I suppose.
@minirop
@minirop 3 месяца назад
is start_lifetime_as related to launder? (not that I understand either, just that their respective example are similar)
@FruchteisMitErdbeer
@FruchteisMitErdbeer 3 месяца назад
Yes, they are used in similar situations. They are both directives that inform the compiler about special object lifetime constraints, and they both are used when operating on objects created over raw bytes or unions. The major difference is that start_lifetime_as starts a lifetime of an object, so can be used to create an object, while launder can only be used to obtain a pointer to an object which already exists, and was created previously (e.g. with start_lifetime_as or placement new).
@cppweekly
@cppweekly 3 месяца назад
Edit: I just realized I missed the bottom half of your comment, after the break. You did get the main point, but I'll still leave my full response intact below: ​@@FruchteisMitErdbeerI don't think this is a correct assertation, or at least misses some key points. for launder, an object of that type must have already been created at that memory location (like with placement-new) and you're now telling the compiler that you are reusing that pointer to point to a new object of the same type. start_lifetime_as says "these bits already represent an object of this type, just trust me" If you do a placement-new on a memory location, then try to read the already existing bits from that memory location, you now have an uninitialized read, which is UB. This is not the case with start_lifetime_as. tldr: normal people might use start_lifetime_as, where as the use cases for launder are very tightly constrained to replacing an object at a given location with a new object. But I could be wrong...
@Zettymaster
@Zettymaster 3 месяца назад
i played around with expected in VS a little the other day and, after being spoiled by Rust's Result, it just felt clunky. it also did some strange things when i tried to chain calls, when i stored it in a variable it went away, which is strange, since it was just a vector (everything by value) that was in there... so im not sure why i ran into memory issues there. (ASAN complained and it was right). not sure if it was just MSVC miscompiling or if i made a mistake
@anon_y_mousse
@anon_y_mousse 3 месяца назад
Considering that Rust makes you explicitly denote it as being a Result every time, i.e. at every return and specify which type of Result it is, I don't see how you can call it clunky by comparison. And then in idiomatic Rust you have to use a match statement to extract it which has its own wonky syntax in which you have to explicitly denote it as a Result and use commas to separate matches, despite the language using semicolons as statement terminators. Don't even get me started on the arrow syntax, or the fact that you can't have a single line conditional without braces. Of course, match is just a clunky way of replacing mass quantities of if/elif/else blocks for non-numeric types that doesn't quite look right and barely saves any time or space, if any at all.
@sjswitzer1
@sjswitzer1 3 месяца назад
A more damning aspect of flat_map is its O(n) insertion time and fetch time of only O(log n). This is because the underlying containers are maintained as sorted. [edit: deleted some nonsense about at() and exceptions :) ] The class is touted as cache-aware but binary search isn’t very cache-aware really since it bounces around in memory. Just not sure what this class was meant to solve. It’s not a data structure I’d ever want to use but it’s disguised as an efficient general purpose map, which it assuredly is not.
@sjswitzer1
@sjswitzer1 3 месяца назад
Explaining my edit: I’d forgotten that ALL maps throw when at() comes up empty because I never use at because it throws :)
@sjswitzer1
@sjswitzer1 3 месяца назад
Anyway what we REALLY need is a modern cache-aware hashmap like other comparable modern languages (Rust, Zig, Go).
@SonicFan535
@SonicFan535 3 месяца назад
One advantage for cache locality is that flat_map is maximally compact since it doesn't need to store any metadata or have any "free slots" like open addressing does. For smaller sizes and in certain use cases, that can be even more important than the actual lookup algorithm (at least according to my benchmarks). Sure, it's not a general-purpose 1:1 replacement for std::unordered_map, which would be nice to also have, but it's definitely a useful alternative in some scenarios.
@sjswitzer1
@sjswitzer1 3 месяца назад
@@SonicFan535Ok, I am beginning to see the light here. Flat_map is cache-aware _relative to_ the (ordered) map’s red-black tree which is positively brutal on the allocator and cache. Amusingly, I long ago concluded that map was impractical for that reason and haven’t ever missed it. unordered_map has met my needs well enough. It never even occurred to me to compare flat_map with (ordered) map but of course that is the map to compare it to. That said, C++ really could use an improved, more cache-aware hashmap. I haven’t felt a need for an ordered map so haven’t sought an improvement there.
@stefanalecu9532
@stefanalecu9532 3 месяца назад
You can have cache-friendly binary search if you use the eytzinger binary search and rearrange the layout a bit and probably the implementation uses something like that
@Evan490BC
@Evan490BC 3 месяца назад
Is this deficiency of std::vector not being constexpr (for variables, because I believe you can use it in costexpr functions) going to be corrected any time soon? Because the problem is in the way the standard libray implements it, via `new`...
@alexb5594
@alexb5594 3 месяца назад
No, it's a really complicated problem, and it's overshadowed by other efforts right now (reflection and metaprogramming)
@Evan490BC
@Evan490BC 3 месяца назад
@@alexb5594I understand; it was more of a rhetorical question. I must say that I am very happy with the general direction modern C++ is heading.
@anon_y_mousse
@anon_y_mousse 3 месяца назад
You may have misunderstood. It's not that vector isn't constexpr because it is now, but that flat_map and flat_set aren't and thus can't make use of the constexpr-ness of vector.
@Evan490BC
@Evan490BC 3 месяца назад
@@anon_y_mousseWell, it depends on how you define the words "is" and "now". If by "is" you mean that vector is _defined_ as constexpr in the Standard, then I agree. If you want to use it in your code _now_ (with the standard definition of "now"), it isn't.
@anon_y_mousse
@anon_y_mousse 3 месяца назад
@@Evan490BC If you have an updated copy of the standard library it is. Doesn't even require compilation to use, nor a more recent compiler, assuming you've got one that can handle C++11 code, which as slow as I am to update I still have.
@PaulMetalhero
@PaulMetalhero 3 месяца назад
Why GCC 13 doesn't support print, if it already supports format?
@cppweekly
@cppweekly 3 месяца назад
These things are rapidly changing, but it's a matter of people writing the code and adding the PR. It just has to be someone's priority.
@wizardy6267
@wizardy6267 3 месяца назад
std::print ~> c++ pythonlization :) I wish C++ could bring something like JSON in JS so developers can work on structured data conveniently. However, JSON is boring
@Bruver-pc8vk
@Bruver-pc8vk 2 месяца назад
I think parsers in the standard library is too much. Just use a third party parser.
@KX36
@KX36 3 месяца назад
The important parts of C++23, also known as C++17.
@kishirisu1268
@kishirisu1268 3 месяца назад
Normal people just use debuger to see values, RU-vidrs: Print! 😂
@stefanalecu9532
@stefanalecu9532 3 месяца назад
Normal people have no damn clue what a debugger is or how they can find it unless they stumble on it by accident, so they'd do a lot of cout's instead, in which case std::print sure is helpful, especially with containers
@higaski
@higaski 3 месяца назад
Re-subscribed because the click-bait seems to be gone.
@cppweekly
@cppweekly 3 месяца назад
I don't know what specifically you are referring to. Was it the CS episodes that I did, where I was trying to get basic Computer Science knowledge into the hands of more people, including my own family?
@01MeuCanal
@01MeuCanal 3 месяца назад
Do you think some code A.I. could be a good static analyzer? It could be used to go beyond normal static analyzers and force memory safety?
@stefanalecu9532
@stefanalecu9532 3 месяца назад
At this point in time, where AI vulnerability detectors are making bogus issues on wget and curl and it's barely capable of having the intelligence of a 5 year old (and that's me being generous), no In 3-4 years from now, maybe, but SonarLint is already doing a good job with that
@01MeuCanal
@01MeuCanal 3 месяца назад
@@stefanalecu9532 A.I. is advancing super fast. I found something about that on the internet. People are already working on that. A.I. may be the solution to all C++ needs.
@01MeuCanal
@01MeuCanal 3 месяца назад
@@stefanalecu9532 Sonarlint can check for C++ core guidelines?
@01MeuCanal
@01MeuCanal 3 месяца назад
@@stefanalecu9532Elon Musk released Grok as open source. May be if we train it specifically for C++ verification and lint it could do the job.
@cppweekly
@cppweekly 3 месяца назад
I think it can help in some situations, as just another tool. I don't know how long it would be before it replaces all the tools
Далее
TYLA DANCE TREND😭 | #shorts #emilydobson
00:12
Просмотров 2,6 млн
how Google writes gorgeous C++
7:40
Просмотров 794 тыс.
Programming Languages I used at Google (C++ rant)
6:14
How To Unlock Your iphone With Your Voice
0:34
Просмотров 26 млн
Все розовые iPhone 💕
0:51
Просмотров 220 тыс.
Купил этот ваш VR.
37:21
Просмотров 292 тыс.
Купил iPhone 15. Первые эмоции!
0:58