CppCon 2014: Walter E. Brown 'Modern Template Metaprogramming: A Compendium, Part I'

preview_player
Показать описание

--
Template metaprogramming has become an important part of a C++ programmer's toolkit. This talk will demonstrate state-of-the-art metaprogramming techniques, applying each to obtain representative implementations of selected standard library facilities.

Along the way, we will look at void_t, a recently-proposed, extremely simple new new type_traits candidate whose use has been described by one expert as "highly advanced (and elegant), and surprising even to experienced template metaprogrammers."
--
With broad experience in industry, academia, consulting, and research, Dr. Walter E. Brown has been a C++ programmer for over thirty years, joining the C++ standards effort in 2000. Among numerous other contributions, he is responsible for introducing such now-standard C++ library features as cbegin/cend and common_type as well as headers random and ratio , and has significantly impacted such core language features as alias templates, contextual conversions, and variable templates. He conceived and served as project editor for the International Standard on Special Mathematical Functions in C++.

When not playing with his grandchildren, Dr. Brown is an Emeritus participant in the C++ standards process, with several more core and library proposals under consideration. He was recently appointed an associate project editor for the C++ standard itself.
--

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

This is the best presentation, I have seen on cppcon. It is very obvious that the speaker put a lot of effort for preparing this presentation. Timing, design of content, slides, examples chosen just excellent.

akurmustafa_
Автор

"Mathematics is after all just a small branch of Computer Science". That is now my favorite quote of all time.

SasLuca
Автор

Words cannot describe how useful, interesting and enlightening this talk is.
As someone in the audience said at the end of the second part, you really really rock sir Brown 😊

Thank you and congrats

matteobarnaba
Автор

It is simply mind-boggling, the way his guy makes this really weird subject become understandable.

daggawagga
Автор

Loved the Borland Turbo C++ color scheme.

AdrianoDelVigna
Автор

Producing such a collection of slides requires a tremendous amount of effort and knowledge, similar to writing a research paper. I admire Mr. Brown's work.

TheMR-
Автор

great speaker! pauses at the right places and all, not hyperactive. clean slides, to the point. subject is so interesting and very well introduced when you're not a TMP wiz.

eepp
Автор

This is a magnificent lecture. Thank you Walter E. Brown for the execellent presentation and teaching!

smarthumanism
Автор

Template metaprogramming is fun. Well only after I watched Mr Walter talks.

moderncpp
Автор

That was truly mind-blowing.
(while listening to the talk, I am coming to a conclusion, that...)
Despite knowing everything about C++, I didn't know anything.

TheMR-
Автор

This is an amazing introduction for Template Metaprogramming. It's too late I reached here, but still worth the knowledge.

iam_Raavanan
Автор

Quick summary:

templates were originally meant for use.


eg:

template <typename T>
struct Blah {...}; // The template seems pointless if you don't use it

However, with SFINAE we can use our templates to perform checks:

template <typename T, typename S = decltype(T())>
struct Blah {...}; // Now we make sure that T is default constructible.
// This can still make sense even if we don't use S

(FYI, because of this, we don't have to give S a name):
template <typename T, typename = decltype(T())>
struct Blah {...};


So Dr. Brown suggests that its better to throw all of these expressions
(where we only care about their validity, and not their evaluated type)
into one place (a kind of "black hole"), void_t:

template <typename...>
using void_t = void; // He had to implement it in a slightly
// more awkward way for clang

So if you call it:
void_t<expression1, expression2, ...., expresssionN>;

Then it checks the validity of the expressions:
if all are valid, it returns void,
if not, it's SFINAE-ed out.

The fact that it has a single and predictable return type is key to its
usefulness.

As I understand it, that's the purpose of the presentation: to introduce
this little tool and show that it's useful. FYI it's now part of the
standard library with his suggested name.

Now, if someone could help me

What is the aim of the code on slides 34/35 (in part II)?
His wording here seems super confusing. Is he looking for:

1. Whether T has a member named "type" (where, confusingly, we don't
care about its type)
1. --> this option seems the most obvious, except that his code won't
compile because of the line 'typename T::type', because 'type' doesn't
name a type.

2. Whether T has a member of a certain 'type', but we don't care about
its name.
2. --> Again, this won't compile at the same line (expected
identifier before 'type')

3. Whether T has an inner type (eg. class/struct/enum declared within
it)?
3. --> this compiles and performs the check correctly, but has
nothing to do with members of T, so doesn't make sense to me in the
context of his presentation.

Did he mean to write:

struct has_type_member< T, void_t< decltype( T::member ) > > : true_type
{ };
instead of:
struct has_type_member< T, void_t< typename T::member > > : true_type
{ };
? This would make 1. work....

elliott
Автор

Amazing job, Walter. The last CppCon talk I watched was from the STL guy. I think his slides were smart but I can't really tell because I couldn't follow. But I grasped everything here. Very intuitive and crisp presentation. Thank you so much

DimitrisAndreou
Автор

Absolutely stellar talk as usual from Dr. Brown!
Is there another recording out there with better audio quality? It got pretty crispy in some parts.

ultradude
Автор

Clear explanations though many aspects are probably familiar for someone who has survived the Boost.Mpl documentation. I think it's also an improvement to drop the required comment in static_assert, although the use cases shown in the video could have benefit from some extra explanatory text.

The modern aspects are handled in part 2.

gast
Автор

Dr Brown performs like G. This is mind expanding stuff !!!

mykhailomykytyn
Автор

I finally understand what SFINAE actually means now thank you

colin
Автор

53:00 Concepts are in C++20, and it looks like this:
template <std::integral T>
maxint_t f(T val) { … }

Bolpat
Автор

40:00 I had a couple of questions about it, for a long time.
- How the unnamed struct will be declared, if it inherits from another class/struct?
- and how the CRTP will be handled in unnamed struct/class?

TheMR-
Автор

Great talk, though you could get a better mic for about 10 dollars

thisisnotanick