Sehgal delivers a concise masterclass on how `deducing_this` finally resolves the long-standing frustration of redundant member function overloads. It is an essential update for developers looking to balance modern C++ elegance with high-frequency performance requirements.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Lightning Talk: Cut the boilerplate with C++23 deducing_this - Sarthak Sehgal - CppCon 2025Added:
You get to meet people. There's there's the there's a the secret track which is just walking around having a coffee talking to people you don't know. Oh, what do you do? I do this. You learn so much and you extend your network amazingly well. And you cannot do this online. It has to be in person.
Hey everyone, I'm Sarduk. I'm going to be talking about C++ 23 deducing this.
Um, quick intro. I'm a C++ uh loaded latency execution engineer at Maven Securities. Uh, we have offices in Chicago, London, and Amsterdam. So, if you're ever curious about the space, feel free to reach out to me and let's dive right into it. Um, so say you have a you start creating a class. Uh, in this example, I have a chessboard which is a 8 + 8 chessboard. Um, I'm storing it in a 8 + 8 array. um and you want to give the clients access to the elements inside this chessboard. So you would typically start off by uh providing some accessor like this at function which takes in the row and column and returns an LV value reference to the chess piece. Um well this looks nice but very soon you would realize that the object calling or like the chessboard object might be a const object. So you would want to provide a con uh you would want to provide a const overload to this which would u hopefully return a con ref and it will look something like this.
You can also go a step further and have r value overloads and uh rv value con const overloads for this and very soon it becomes it starts becoming very cumbersome and you would realize that there's a lot of code duplication going on. Well if you're on C++ 23 this is a conditional box of shame. uh you can get rid of all of this code and simply replace it by three lines at the bottom.
And this is what reducing this does. It als it also does some other stuff, but I think it's really cool that we can now replace all of this boiler plate code uh just by using these three lines of code.
Um and that's it. I could give you back three and a half minutes, but I think I'm going to bore you with some more details of uh deducing this. Um so taking a step back, the chessboard looks something like this. I have uh a non-const overload of this at accessor and I have a const overload of the same accessor. Um now pre C++ 23 there's still code duplication and as programmers we don't really like to repeat uh code. So how how would we deal with this pre- C++ 23+ >> uh pre C++ 23 uh so what you could do is you could have a static member function which is uh now at the top I have the static um at accessor which is like a private method um and the first parameter that it takes is is a auto reference to self um and if you notice the member functions like the two member functions the non-const overload and the const overload uh they now pass the the dreference against this pointer that is the object um to the static member function. So you we've avoided code duplication now and the nice thing about the solution is that uh the order reference in the static member function is now going to be deduced as either an LV value reference if you call the uh if the if the object is uh non-const um or a constell value reference if the other add accessor is called and you could do this pre C++ 23 and I think this is a pretty cool solution um reducing this basically addresses this as I previously highlighted Um I wanted to highlight a few things here. Uh the first parameter in deducing like in a member function which uses deducing this is um this like weird thing this auto ref. Uh this is a forwarding reference. Uh one thing to notice that deduce this deducing this function is a non-static member function not a static member function. Um and since it's it's using a forwarding reference uh I'm using stood forward here. Uh so I want to perfectly forward it and then access the um the data member.
Now consider this piece of code. I have a chessboard uh and I'm trying to access a chess piece um and instead of simply calling chessboard at uh I'm moving the chessboard just for the sake of this example and calling the at um at member function. Um what I would expect is this to happen is that it would resolve uh this like the type of chessboard is going to be uh like this type of explicit object parameter auto reference self is going to be an R value um an unconstar value to be uh to be clear and that is that is what happens that that's expected but now would my chess piece be copy constructed or move constructed well because I'm using a non-construct value reference I would expect it to be move constructed But in my current code, it's copy constructed and C++ was actually this happens because when I do stood forward uh on the self parameter, it is an R value. That's true. But as soon as I access the board, that's that now returns an LV value reference to the board and which ultimately returns u an LV value reference to the chess piece uh and it copy constructs. So this is no good. uh C++ 23 introduces stood forward like which basically instead of uh which basically uh you would access the board u in the class and then wrap it with the same uh reference properties as um as the object itself. Um so I think straightforward I guess is pretty cool and that's it. Thank you so much.
[applause]
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 viewsβ’2026-05-28
How agent o11y differs from traditional o11y β Phil Hetzel, Braintrust
aiDotEngineer
450 viewsβ’2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanationπ―β
LearnwithSahera
1K viewsβ’2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 viewsβ’2026-05-29
Search Algorithms Explained in 60 Seconds! π€π¨
samarthtuliofficial
218 viewsβ’2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 viewsβ’2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 viewsβ’2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 viewsβ’2026-06-01











