Variadic Templates are Funadic

The C++ Standard Library expanded and evolved massively between C++98/03 and C++11. It's easy to forget the magnitude of these changes, because they happened gradually and sometimes invisibly. Some things (like shared_ptr, regex, and function) were developed in Boost in the early 2000s, before making their way into TR1 in 2005 and then C++11. Other things, like container move semantics, automatically improve programs without human intervention. Sometimes I can hardly believe that programmers used to live without non-intrusive deterministically reference-counted smart pointers! We are fortunate to live in such an advanced and enlightened age.
In this presentation, I'll explore how some of the C++11 Standard Library's magic works, including how the Standardization Committee fixed pair's constructors (I bet you think that pair is the simplest type in the world - ha! wrong!) and how I saved a million zillion bytes of memory across all the programs using VC10+'s make_shared<T>().
Oh, and I will also reveal a secret that has never been announced before.
how do i watch this session on-demand?
Because of my office, I could not watch yesterday's event. I would appreciate if you share the link to watch this event. Thank you !
At 35:12, you start talking about move semantics in the context of the flip function taking a string by value, but there are no move semantics involved here. Since the arguments are const char arrays, the string variable s is simply initialized by the constructor string(const char*), as it always has been.
I was taking shortcuts - move semantics would have been involved if the sources were str + "stuff" - but the point still holds.
Compare:
flip(const string& s) { string ret(s); // #1, reverse and return ret
versus:
flip(string s) { // #2, reverse and return s
Given flip("meow"), #1 creates a temporary string, binds the const reference s to it, then (unnecessarily!) copies it into ret. #2 constructs s from "meow", as you mentioned, then flips and move-returns it.
So, #2 made sense even in C++98/03, and it plays nice with move semantics.
Great talk, it's always a joy to hear you talking! I hope you'll have a little bit more time for your Advanced STL series once VS11 is out.
Then, any particular reason that nearly every slide was titled with a TVTrope?
(Also, can we get access to these slides?)
What are cars, putters and stoods??!
2 days ago, STL wrote
Compare:
flip(const string& s) { string ret(s); // #1, reverse and return ret
versus:
flip(string s) { // #2, reverse and return s
Given flip("meow"), #1 creates a temporary string, binds the const reference s to it, then (unnecessarily!) copies it into ret. #2 constructs s from "meow", as you mentioned, then flips and move-returns it.
So, #2 made sense even in C++98/03, and it plays nice with move semantics.
So, when we have a C++ class X and we want to modify a copy of it inside a function/method, does it make sense (also in C++98/03) to always use signature like your #2? i.e.
DoSomething( X x )
instead of the more usual DoSomething(const X &) ?
Thanks.
Audio, at least on the "High Quality MP4", is out of sync with the video. Either that or STL can add ventriloquism to his already impressive list of skills and credentials ;-)
Haven't downloaded the other qualities, maybe it's just the HQ MP4. FWIW, I downloaded the other videos, this seems to be the only one that's buggered.
Thanks for making the videos & slides for the talks available, much appreciated. The only problem is that now I regret even more not being able to attend :-(
By "downloaded the other videos", I meant the other talks, sorry if that wasn't clear...
By "downloaded the other videos", I meant the other talks, sorry if that wasn't clear...
Thank you, Dan. I noticed that too (when the file was intitially released). It was re-encoded to hopefully fix the HQ MP4 audio sync issue. Looks like it didn't work
We'll figure it out.
C
c9xeo> Great talk, it's always a joy to hear you talking!
Thanks!
c9xeo> I hope you'll have a little bit more time for your Advanced STL series once VS11 is out.
Me too. You can think of this as "Advanced STL, Part Infinity" for the time being. :->
c9xeo> Then, any particular reason that nearly every slide was titled with a TVTrope?
I came up with "Twenty Minutes Into The Future" and "The Reveal" first, and I liked them so much, I had to follow the pattern. :->
c9xeo> (Also, can we get access to these slides?)
The links are above: "Slides (view online)"
someone> What are cars, putters and stoods??!
I pronounce "char", "ptr", and "std" as "care" (it's the prefix of "character"), "putter", and "stood".
C64> So, when we have a C++ class X and we want to modify a copy of it inside a function/method, does it make sense (also in C++98/03) to always use signature like your #2?
Yes. It's sometimes better, and never worse. The advantage increases in C++11, but is present in C++98/03.
(never mind)
As always i enjoy reading this awesome content, i hope you can find as much enjoyable content from me in return.
> Me too. You can think of this as "Advanced STL, Part Infinity" for the time being. :->
Heh, topic suggestion: Template meta programming! With things like Expression SFINAE, writing ones own type traits (like how to find out if a class has a certain member function), like you did in part 5 of Advanced STL.
Maybe also about constexpr? But that isn't implemented in VS, right?
Hmm, what else... I'll think about it some more and report back.
Edit: Oooh, another idea! I know this doesn't really count as STL, since they don't belong in that subpart of the library, but what about IOstreams? Especially the streambufs, locales, facets, codecvt stuff. As far as I know, there's only one real book on IOstreams, and it's from 2000 (IIRC). And personally, I think IOstreams are one of the more advanced topics, if you go beyond simple streaming to existing streams.
Hi guys,
I just wanna ask you guys, what question did Bjarne Stroustrup ask during the last few minutes? I didn't hear it clearly
> I am definitely thinking I'll do a "Core C++" series
Yes, please!
> iostreams fills me with dread and loathing. Maintaining the stuff is just about all I can handle.
Then make it a "Bash the IOstreams" session? Tell us what's so horrible about them!
@STL
Thanks
Here is the future sample code:
string flip(string s) {
reverse(begin(s), end(s));
return s;
}
vector<future<string>> v;
v.push_back(async( [] {return flip(" ,gnol oS"); }));
v.push_back(async( [] {return flip(" dlrow"); }));
v.push_back(async( [] {return flip("\n.ti wonk ew sa"); }));
for(auto& e : v) { cout << e.get(); }
Thanks,
Comet
purr more, hiss less
Feb 10, 2012 at 7:43 PM, c9xeo wrote
> I am definitely thinking I'll do a "Core C++" series
Yes, please!
> iostreams fills me with dread and loathing. Maintaining the stuff is just about all I can handle.
Then make it a "Bash the IOstreams" session?
Tell us what's so horrible about them!
The Core C++ series has begun: https://channel9.msdn.com/Shows/Going+Deep/Stephan-T-Lavavej-Core-C-1-of-n
STL rocks!
C
What is matter your eyes?