CppCon 2016: Arthur O'Dwyer “Template Normal Programming (part 1 of 2)”

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


What is "template normal programming"? It's template metaprogramming without so much of the "meta" part! During this talk, I promise not to mention SFINAE, or recursion, or standard type traits. We'll focus on the common scenarios "I think this code could benefit from templates, but I don't understand how to organize it;" "I can't get anything to compile without errors;" and "My coworker wrote some template code and I don't understand any of it."

In Part I of the talk, we'll start with function templates and class templates, then explain variable templates (new in C++14) and template aliases (new in C++11). We'll do a deep dive into template type deduction; then talk about full and partial specialization; and finish up with an example that motivates the final feature of C++11 template syntax, explicit instantiation.

In Part II of the talk, we'll begin by demystifying tag dispatch and traits classes; discuss situations in which you have to add disambiguating "template" or "typename" keywords (and why); and do a deep dive into the rules of what gets instantiated when and where. We'll revisit template type deduction just long enough to explain how it works for variadic templates; and explain two common template idioms — the Curiously Recurring Template Pattern and the Mixin Pattern.
Time permitting, we'll finish by exploring the big new features of templates according to the C++17 Draft Standard:
- template
- type deduction for class template constructors
- explicit deduction guides
--
Arthur O'Dwyer worked for many years at Green Hills Software, making the world's most optimizing C and C++ compilers. Now he works at Mixpanel in San Francisco, where he organizes a monthly C++ meetup.
--

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

The fact that <> types "overrule" type deduction is something I wish I had learned the first time I heard about templates

leocelente
Автор

Great presentation and content. I am not a C++ programmer by profession. But I learned so much from this. Thanks a lot.

JobinAugustine
Автор

Oh wow, thank you for fixing the title (bottom right)! Wasn't expecting a reupload and got excited thinking it was part 2. :')

YuTe
Автор

Great material and brilliant presenter! Really enjoyed the talk.

RedRumIzzy
Автор

51:30 UPDATE: c++17 standard added class template deduction types. I've checked, it works. Enjoy folks ;)

lisekSL
Автор

Nice description of why templates are useful. Thanks for the talk.

IllumTheMessage
Автор

34:21 "I'm going to assume some knowledge of lvalues and rvalues... it's been five years, people." This speaks to the ridiculousness of Rvalue References and move operations than anything else.

Knuckler
Автор

1:07 ..wait, that's good, right?
We write templates, sometimes for performance reasons.
If not much time is spent doing meaningful work, then the this goal has been achieved.

playerguy
Автор

Worth it for PRETTY_FUNCTION explanation. Neato.

AtomkeySinclair
Автор

Not only a good content but an excellent presentation too. Thanks!

dans.
Автор

This would be much more interesting if pointer parameters to the function would be type deducted as well. In that case parameter passed can be both const type or const pointer.

wpavada
Автор

Is someone able to explain the is_void to me. I must have missed something because I do not understand how making T void has any bearing on the output here.

seditt
Автор

awesome talk. and whoever contributes to the subtitle, a great job.

YasasCPerera
Автор

Nice explanation.I have below doubt on iterator Why we need to provide specialization in iterator


template <typename Iterator>
void process(Iterator begin, Iterator end)
{
for (; itr != end; ++itr) {
process(*itr);
}
}


why i can't write


void process(Iterator begin, Iterator end)
{
for (; itr != end; ++itr) {
process(*itr);
}
}


please explain

TarunSingh-jemy
Автор

Can we now put template implementations in source as opposed to header files now?

sivabudh