Algorithms + Data Structures = Programs - Episode 90: C++23

Episode Date: August 12, 2022

In this episode, Bryce and Conor talk about C++23.Link to Episode 90 on WebsiteTwitterADSP: The PodcastConor HoekstraBryce Adelstein LelbachShow NotesDate Recorded: 2022-08-09Date Released: 2022-08-12...Bighorn SheepKate Gregory on TwitterAPL Toronto Meetup on Sep 1APL New York Meetup on Sep 7C23 is Finished: Here is What is on the MenuC++North 2022 Trip Report by Timur DoumlerSy Brand Tweet on What’s New in C++23C++23 if constevalJason Turner’s C++ Weekly - Ep 304 - C++23’s if constevalJason Turner’s C++ Weekly - Ep 308 - if consteval - There’s More To This StoryC++23 Deducing thisDeducing this Patterns - Ben Deane - CppCon 2021North Denver Metro CPP Meetup - September 2021 - Deducing this Patterns - Ben DeaneC++ CRTP (Curiously recurring template pattern)RAPIDS libcudf CRTP ExampleC++23 std::stackstraceC++23 std::is_scoped_enumC++23 std::basic_string::containsC++23 std::to_underlyingC++ Namespaces (Nested)C++ Namespace AliasesIntro Song InfoMiss You by Sarah Jansen https://soundcloud.com/sarahjansenmusicCreative Commons — Attribution 3.0 Unported — CC BY 3.0Free Download / Stream: http://bit.ly/l-miss-youMusic promoted by Audio Library https://youtu.be/iYYxnasvfx8

Transcript
Discussion (0)
Starting point is 00:00:00 And folks have to tune in next time to hear the explanations of these. But we'll start with Zip. Do not, do not, do not edit this episode like that. That would be terrible. Welcome to ADSP, the podcast episode 89, recorded on August 9th, 2022. My name is Connor and today with my co-host Bryce, we talk about the upcoming features that you can look forward to in C++23. Not much. I am still in Arizona. My audio is going to be terrible today because I don't have the Yeti. That's all right.
Starting point is 00:00:45 But did I send you this picture? I don't think the Yeti. That's all right. But did I send you this picture? I don't think I sent you this picture. Oh, that's right. I was supposed to include in the show notes of the last episode the picture of Looney. Yeah. Oh, I got better pictures of the dog. I didn't do that.
Starting point is 00:01:00 I apologize to the listener if you were really hanging on for that. Go check out your Twitter. I took this picture. I'm very impressed with myself. Wow. Look at that. Folks, I'm staring at what looks like a ram? A bighorn sheep.
Starting point is 00:01:18 A bighorn sheep? I mean, for all we know, folks, those are the same thing in front of the Grand Canyon. Quite epic. Yeah. Yeah. It looks like the sheep posed. It looks like it knew. Yeah.
Starting point is 00:01:33 Well, the dog. I thought the dog was going to get into a confrontation with the sheep. But the dog looked at the sheep, growled a little bit. The sheep did nothing. And the dog is like, yeah, you know, you seem pretty docile and also bigger than me. So I'm just going to chill out. I promise the listener when I tweet out the episode 90, which is what this is we're recording right now. I will tweet this photo of said bighorn sheep and the Grand Canyon. And the dog.
Starting point is 00:02:12 Yeah. Before we get to hop into the episode, we've got to make some announcements. Announcement number one, Kate Gregory is not with us today. She probably will be featured on episodes 92, 93, maybe 94. We'll see how long we record for. We are setting up a recording with her in the next couple weeks. So she will be our next guest. We mentioned that in the previous podcast that we were going to bring on. Potentially, Kate, it's going to happen. We're making it happen. That's announcement number one. Announcement
Starting point is 00:02:48 number two, if you are in Toronto, Canada on September 1st, and you feel like learning something about array languages and APL, or you already love APL and you'd want to come to a meetup, there's going to be an in-person meetup held in downtown Toronto, exact location to be determined from six to eight and a social afterwards, somewhere else. And announcement number three, and you can find the links for that in the show notes
Starting point is 00:03:15 that are being hosted on meetup. Announcement number three, if you are in New York, New York, America, on September 7th, same deal, interested in array languages or array language curious New York, America on September 7th. Same deal. Interested in array languages or array language curious or already love APL and array languages. There will be a very similar meetup, but hosted somewhere in New York. A lack exact location to be determined.
Starting point is 00:03:37 Check the show notes for that meetup event as well. But I won't be in New York, New York on September 7th. Yeah, no, that's unfortunate. Will you be in New York, New York on September 7th? I will be in New York from new york on september 7th yeah no that's unfortunate will you be in new york new york on september i will be in new york from september 7th to september 9th what the heck man i mean didn't we didn't this come up no maybe it was off air when i mentioned it uh i think it was off air um maybe when we were talking with i can't remember who we were talking maybe tony was there anyway you can't remember who we were talking. Maybe Tony was there.
Starting point is 00:04:10 Anyway, you can't move your schedule around a week. No, it's not based. I'm not the one hosting it. Morton Cromberg, who is the CTO of Dialogue Limited. Give me his phone number. I'll call him up and explain the situation. I mean, the meetups, the meetups are already under underway. So you'll have to wait till you should stay. you should stay until the 11th because wait when do i fly back i already booked my tickets it's too late change your tickets you know that's a lot of work it was just it was a lot of work just for me to get on the website and to book don't you want to see me bro i do but we decide each other in uh in july and um potentially i'll be back in new york my parents might be visiting at some point and so I said I might swing down if they are. Anyways.
Starting point is 00:04:47 I literally get, I arrive on the 10th. If you stayed one more day, we could hang out. Really? Well, you should have told me that because I definitely would have just flown back on Saturday or Sunday if that was the case. Just change your flight. I do think actually there is a 24-hour policy that you're allowed to cancel.
Starting point is 00:05:07 I'm not sure if you're allowed to modify. But I'll look into it because I did book them just like earlier this morning. All right, folks. Maybe we will be recording in person from New York. You should stay until Sunday. You can crash on my couch, which is very comfortable. The problem is now is that I didn't plan on bringing carry-on i was just going to bring a backpack four days though now you can you can you can do laundry that's true that's true
Starting point is 00:05:34 now we're getting into like details that the listener definitely doesn't care about whether will connor do laundry or bring carry-on to new york in order to hang out. All right. When do you fly back in on Saturday? I will be there. Hang on. Let me make sure that the time zones are correct. I feel like there was a reason I flew back on Friday. I think there's a 10K race I was going to run on Saturday, but it's all right. I haven't signed up yet. So I'll blow that race off for you. Don't worry, buddy. Good. My fitness is being affected by our friendship, though. Yeah, yeah. So I get back in on Saturday at, I will arrive at 6 a.m. Perfect.
Starting point is 00:06:13 So we got all two days together. Yeah. And I've been to New York once, twice. Really? Just, wow. Just once or twice. I mean, I had held off on going to New York for the longest time because back when I wanted to be a quant while I was becoming an actuary, I thought for sure that
Starting point is 00:06:29 there was going to be a year or two period of my life where I was going to end up working there. So it was never at the top of my list of places I wanted to visit, even though I definitely wanted to go there because I just figured at some point I'll end up working there, which never came to fruition. And now that I've worked in tech where you don't have to be in front of your desk between the hours of 930 and four, which is what basically all quant or trader jobs. Like there are some quant shops that are like backend people that they don't require you to there. But in general, if you work for an HFT company or a finance company, like they require you
Starting point is 00:06:56 to be in front of your desk when the stock markets, you know, NASDAQ and NYC, et cetera, the American ones are open. Yeah. And that's just like once you've worked a flexible job at a tech company where you can, as long as you get your work done and you're there for meetings, if you want to go to the gym or go for a walk, like in the middle of the day, I can't, I can't, I can't go back from that. Like I need to be able to get up from my desk and like do a little bit of exercise to get
Starting point is 00:07:20 the blood flowing and, you know, brain working a little bit better. Anyways, point is that was a long windeded monologue never ended up living in new york that's why i've only been there a couple times but i've i think we've talked about this on the podcast not a big fan of new york uh because it smells like garbage but apparently bryce says this is untrue it's not you admit it on air that it is true that it does smell like garbage smell like garbage if you don't if you if you adapt to the smell and it doesn't actually smell like that it smells like nothing so if you live there long enough that you don't notice garbage in my neighborhood yes there are certain neighborhoods especially closer to the water i don't know what you call that uh but um
Starting point is 00:08:01 the good parts of town yeah so anyways So anyways, I'll be there. Bryce will show me the New York that I haven't seen that will supposedly make me fall in love with it. And, and, and no, I mean, I do like New York. I've always enjoyed visiting New York.
Starting point is 00:08:16 I just have like, people talk about it as like, you know, the best city in the world. And it's like, there's no, there's no city that compares to it. The field,
Starting point is 00:08:22 the body, everyone's going places, doing, you're saying, you're just saying truths and like i just didn't get that vibe and like even when i went to central park it was so crazy busy i mean maybe i was there in the summer which is the wrong time to go i was there in like july the last time i went but i was just like this is not like a break from the city this is just like moving all the people in the buildings to people in the park and like we wanted i can't remember i can't remember exactly but we wanted to do this like a paddle boat thing in one of the ponds there and there was like there was like a 200 person lineup
Starting point is 00:08:53 for a paddle boat like yeah if you if you go try to do the touristy thing this is gonna be line man anyways enough about new york yeah for those of you in town sept September 7th uh well look we got a little bit of a vacuum in the background someone vacuuming the hallway I cannot record on August 20th because I will be in Scotland gotcha so if Kate Gregory's listening to this I mean it'll come up probably after she responds to the email but that was tentatively when we were going to record anyways what are we talking about today post what are we talking about today post announcements are we talking about today i mean i've got a couple topics if we want to do a combinatory logic part two although i'm not sure i mean i'm obviously i could probably end
Starting point is 00:09:37 up rambling on um but that's not super topical yeah i don't have topics. It's really hot here, in my defense. In my defense, it's really, it's like 105 degrees here. What can we talk about? I don't think we've recorded since C++23 was finalized. So a few people have written blog articles about um all the features in c++ 23 maybe we could go read one of those blog articles and uh and talk about some of those features that we're excited about um i don't know if we've done an episode like that before. All right. That'll be a good one. C++23. So let us find... We'll see who finds the better articles. C++23, features, blog. I thought Quarantine or somebody wrote one.
Starting point is 00:10:39 Tools. We want this to be released in the last past month. Probably, yeah. Yeah, that's that yes yeah there is one from jean-hied manid hopefully i'm pronouncing that correctly oh that's c23 that's c23 we should do that we should do that after we do c++ but yeah we should do that because there's a lot of exciting stuff going into C23. Oh, yeah. I'll also include in the show notes. We won't go over it, but since CPP North has happened, there's been a couple of blog posts. The one most recently that I read, I think, was Teamers, which was great. I think there was a couple of people upset when they read it and discovered that there was maple tarts and they didn't get any maple tarts on the first day.
Starting point is 00:11:28 They were like, what? There was maple tarts? Yeah. I didn there was maple tarts and they didn't get any maple tarts on like the first day they were like what there was maple tarts yeah i i didn't get maple tarts either i saw them on the first day but i was like diet so i shouldn't have any and i was like i'm sure they'll have them the next day but then there were no maple tarts i was really upset i want to be maple tarts every day next year don Don't worry. I'll talk to the organizers. C++23, who did you say wrote one? Corentin? Maybe I'm just thinking of the C23 blog article. I mean, was there a Reddit post? Maybe it was a Twitter thread. Maybe it was a Twitter thread.
Starting point is 00:12:01 Could have been a Twitter thread. But see, this is one of the problems with c++ is that c++ is like not searchable anywhere because search engines don't really recognize the pluses interesting i just literally went to reddit and then on one of my reddit subreddits apl is is a Reddit post for my meetup that I set up that I did not post. That was odd. I was like, I didn't post on Reddit. Oh, okay. I found it.
Starting point is 00:12:30 It's Cybrand did a thread. They said, I'm letting you talk on what's new and see this was 23. So while I'm doing that, here's a thread of new features. And we will go through that. I'm going to send you a link so that we can we can
Starting point is 00:12:46 literally on their twitter profile scrolling down they tweet quite a bit they do tweet quite a bit oh these are some beautiful that's a retweet yeah size size cats oh my god i um i love those cats yeah just send me a tweet because i'm like... I sent you the tweet. I'm back to August 5th and I missed it somehow, I think. Share the tweet. All right, you start and comment on thoughts. So the first exciting thing that I see in this... Wait, we're not going to go order that they posted?
Starting point is 00:13:18 No, we're going to go in the order that they posted, but the order of exciting things. So not in the order of like exciting things so not in the order it's going to be a ranges views filter on the sequence of things that cy posted but filtered for the ones that bryce thinks is interesting correct yeah okay gotcha so the first one is um uh if const val. And that lets you branch inside of a constexpr function based on whether or not that function is being evaluated at compile time or at runtime. Now, you might think that you could do this
Starting point is 00:14:01 in earlier C++ by doing, like, if constexpr stood is constant evaluated. But that's actually a huge anti-pattern, because if you do an if constexpr, the condition that it's going to evaluate is always going to be evaluated at compile time. And so is constant evaluated if evaluated at compile time is going to return true. So if you write if constexpr std is constant evaluated, that's going to always be true. So instead you had to write like if is constant evaluated and then else. But the problem with doing that is that you didn't get those nice if constexpr semantics where it wouldn't like instantiate the branch that wasn't taken. Now, with if consteval, you don't have that problem. All right. You get to go next.
Starting point is 00:15:03 Yeah. I'll also link in the show notes. Jason Turner, co-host of CPPcast, rest in peace, and also owner of the C++ Weekly YouTube channel, did several months ago, I don't know, sometime in the past, a video on constexpr versus consteval versus std colon colon is constevaluated. And I think it's a short five to 10 minute video that goes through all the different cases and when you want to use each. So that's a great reference if you'd like to learn more about what Bryce just talked about. Moving on, and just for the listener,
Starting point is 00:15:39 just in case you're curious, the two features that Cy, or should we mention them? I won't even mention them. I'll just say that Bryce skipped two features. I will skip zero features from the third feature that Bryce just read. And it is deducing this, which according to Cy, lets you deduce the CV ref qualifiers of a member function. This has a ton of implications, not all of which I understand. And there are two talks, or is it one talk that's been given twice? It's one talk that's been given twice by Ben Dean that I think there's also other folks that have given talks about this. And I apologize if I'm missing if there's, because I know, I want to say Ben gave two
Starting point is 00:16:23 talks recently, and one of them was a co-talk. He had a co-presenter. But anyways, I might be messing this up. All the links will be in the show notes. He gave the talk once at the C++ North Denver user group meeting. Then he gave the same talk, I believe, at CppCon 2021. And yes, we will leave links in the show notes to that. I think the example, the first example is what you expect to see in Python and Rust,
Starting point is 00:16:53 which is where they have the sort of self parameter. The second one lets you basically, it's showing that you no longer need to use the Y combinator for recursive lambdas because you can call your first parameter this auto self and then reference self as the name of the lambda. I believe, you know, I could be messing all this up. Who knows? And what's the third example? Turns out that this is also a replacement for the CRTP, aka the curiously recurring template pattern, which I have actually never used in Anger. Wow. Surprised you that.
Starting point is 00:17:32 I mean, I know that it gets used in Rapids, the team that I used to work on at NVIDIA, and it gets used in a ton of different places, but I never have been the implementer of said pattern anywhere. And I know that this is only a list of three things that you can do with deducing this so it's like this really awesome small feature that enables a bunch of um cool patterns and simplifies a lot of code and i feel like i write i feel like i write a lot of crtp because
Starting point is 00:17:57 it's a pretty simple and zero overhead way to uh uh to do like mixins um and uh so yeah i feel like that's pretty common pretty common thing for me to write like i have some functionality that i don't want to just like duplicate the code um across like three different things um and so i just implement a crtp base class um and then you know the three three derived classes. Yeah. There's actually a part two to this, deducing this, which reads, this feature also solves a currently unsolvable problem regarding Sphinae unfriendly callables being passed
Starting point is 00:18:35 to const overloaded member functions. You can read the paper for more details at, not going to read that URL out, check out the show notes if you'd like to read that paper. It would just be, hang on on let me get the paper number it would just be wg21.link uh slash p zero eight four seven r seven yeah it was not loading the number for me. All right. I'm going to skip over. Back over to Bryce.
Starting point is 00:19:10 He's going to skip how many? One? No. Two. Three. Three. Stack Trace Library. I think this is actually a pretty cool one. It's one of the library features that I'm more excited about. So we've added a functionality to the standard library
Starting point is 00:19:27 for capturing stack traces and enumerating stack traces. And this is pretty useful for debugging, for producing error messages. This, I think, is the perfect example of something that we should standardize because it is something that is very platform specific. There's going to be a different way to do this on every platform. And so if you want to do this yourself in your own code, then you have to write some code for three or four different platforms. And so this is a perfect example of the standard library
Starting point is 00:20:12 encapsulating platform specific differences and providing a portable interface. And this is something that also needs some amount of language support and that's deeply coupled to the compiler and the implementation and the platform so it's sort of non-trivial to do this in a third-party library and yeah I think it's a great little library there's some work for future standards to add support to make it easy for exceptions to sort of automatically or on request capture a stack trace so that when you get an exception, you can just get a stack trace from where that exception was thrown. That's not going into C++23, but hopefully it'll go into C++26.
Starting point is 00:21:04 Pretty exciting. I'm up. All right. I'm going to skip std colon colon is scoped enum, but I'll read what it says anyways. That doesn't count me covering it though. Type trait for getting whether an entity is a scoped enumerator or not. Pretty straightforward. std basic string contains just a member function that does what it sounds like, which is a pretty nice utility function because previously you have to do, you know, the does not equal, you know, past the last element iterator or the std colon colon n pos or whatever that thing is. Std colon colon string colon colon n pos. I can never remember. colon colon string colon colon n pos i can never remember uh stood colon colon to underlying gonna skip that ranges algorithm starts with and ends with which are just really nice things we should just do all the ranges algorithms right now all right
Starting point is 00:21:58 that's i was kind of skipping these because i specifically wanted to get to size i was sort of hoping that you would do contain so that I could go and steal the ranges algorithms from you. This tweet from Cy, stood colon colon ranges colon colon and these are believe all views. So the stood... I'm actually
Starting point is 00:22:17 surprised. I don't... I think that these are... Yeah. That's actually incorrect. The text of the subtweet is incorrect. It should be either std colon colon views colon colon, and then the names of the views, or std colon colon ranges colon colon views.
Starting point is 00:22:34 The std colon colon views is a shortcut for std colon colon ranges colon colon views. Namespaces are a bad idea in the standard library, and I wish we'd not done that i mean most of the times in my code examples i just go use or namespace rv equals stood colon colon ranges colon colon views let's let's talk about why nested namespaces are um all right small digression why nested namespaces are bad? Go. Because they have a lot of overhead in terms of real estate. Like, let's say that instead of calling these things stood colon colon views colon colon zip, we just called it stood colon colon zip underbar view.
Starting point is 00:23:28 You know, that's one less character. Because every time you introduce a nested namespace, you've got two colons. But I think it's worse than that because these things tend to be, you know, a prefix that we put in front of a lot of things. And so you really want it to be as short as possible. You talk to most people about what's the ideal namespace length. Usually you hear like three or four or five. And don't make your top level namespace more than five characters, because that's just long. But so if our general guidance for prefixes is that we want to keep the namespace names to be three or four or five characters, as soon as you go to one level of nested namespace,
Starting point is 00:24:23 you're just immediately adding a ton of overhead because now you've got four colons instead of just two colons here. Um, and then you just end up with super verbose names. Um, so I think that, uh, that oftentimes we, we use, uh, nested namespaces as a way to try to let us use the better name in the inner namespace. But like, it would have been way better if we just called it like stood colon colon zip underbar v. Like that would have been a way better world than making people type stood colon colon views colon colon zip. Well, I mean, I mean, mean well my first thought is that you can't
Starting point is 00:25:09 call it underscore v because that's already has semantics attached to it um for the underscore underscore vw uh i mean i definitely agree that the tax of a double colon and a namespace is not ergonomic at all. It hurts my soul. That being said, I'm not necessarily sure I like underscore VW or underscore something better because I can just do my name. What are they? Are they namespace aliases? Is that the standard term for it? Namespace aliases where you just go namespace, insert your shortcut, RV equals, you know,
Starting point is 00:25:56 and then your std colon colon ranges, colon colon views, semicolon. If we would just introduce the namespace aliases, like if we would just make std v a standard alias for std colon colon views, that'd be great, but we're not going to do that for a variety of reasons. I mean, it is technically a reserved. I think we did reserve std and followed by any characters, but we might have reserved stood followed by numbers. Anyways, let's talk about what new ranges things we put into Sympathia's 2020. I think we can agree that stood colon colon
Starting point is 00:26:33 ranges colon colon views colon colon insert the name of your view is awful. And there is a better solution out there. What it is, I'm sure we could bike shed on. But yeah, it is. I mean, I don't think i would be very surprised i would i would be willing to bet a very significant sum of money that the majority of people do not actually type out stood colon colon ranges colon colon views colon colon when
Starting point is 00:26:58 actually using views for every view like there's there's probably no way that's happening i guess my point at the end of the day is that like if the ideal namespace name is three characters long, which I do think that's true for top level namespaces, then it's really unfortunate that like if you're using that namespace, two fifths of what you're typing is noise. Like you have three letters of meaning, thepace name and then and then two characters of colon colon yeah it would have been great if we could have found a way to have a single character um uh namespace uh separator yeah i definitely agree with that um anyways digression over maybe we'll talk about it again in a future episode the views that sy mentions are zip zip underscore transform adjacent and adjacent transforms um that is actually not a comprehensive set of all of the views they probably mentioned them uh later uh uh because they were the one that originally wrote Cartesian product.
Starting point is 00:28:09 Oh yeah. They're all, they're all mentioned here. No, they didn't actually mention Cartesian product. The thing that they worked on. Cartesian product. Oh yeah.
Starting point is 00:28:18 So chunk and slide and chunk by get mentioned later on join with as well. And ranges too. That's ranges colon colon T-O not T-O-O and not T-W-O not the numeric two. You should explain what these things do. So yeah, let's go by them. Let's go through them.
Starting point is 00:28:37 Oh yeah, we're at about the 30 minute mark. I might cut the episode off. Boom! Right here. Thanks for listening. We hope you enjoyed and have a great day.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.