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

CppCon · 68K views · 2016 · 57:45

Open on YouTube

C, C++, Rust, Go & systems languagesProgramming language designtalk

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about template type deduction, forwarding references, specialization and explicit instantiation.

Recommended by 6 people across 6 different months, 2016 to 2018.

What it is

Part 1 of Arthur O'Dwyer's CppCon 2016 talk on everyday C++ templates, avoiding SFINAE, recursion and type traits. It covers function and class templates, variable templates, template aliases, a deep dive into template type deduction, full and partial specialization, and explicit instantiation.

What people said

Recommends StoryTeller - Unslander Monica · 2016-11 · Stack Overflow · on “#define or typed function?”

@Bathsheba, explicit instantiation notwithstanding, there is no point in marking a template as inline. A good lecture on the subject from this years cppcon [this video]

Recommends 463035818_is_not_an_ai · 2016-11 · Stack Overflow · on “what does the < > beside the struct do?”

Yes you are right. Here [this video] is a video that explains in detail type deduction for templates. He also mentions at some point the case where a specialization introduces an additional template parameter. I will also edit the answer, trying to make it a bit more clear

Recommends Michael Nastenko · 2017-03 · Stack Overflow · on “C++ Method definition with templates”

I can recommend a talk from **CppCon 2016: Arthur O'Dwyer "Template Normal Programming"** Part1 [this video] and Part2 [LINK]

Recommends jbalestr42 · 2017-06 · Stack Overflow · on “Move semantics for lvalue”

To help you understand what type your template deduced, you can use the macro __PRETTY_FUNCTION__ template<class T> void test(T&& v) { std::cout<< __PRETTY_FUNCTION__ << std::endl; v++; } Also this guys explains a lot of things about template deduction (your case at 35') [this video]

Recommends Jellybaby · 2017-07 · Stack Overflow · on “Are const and & ignored in std::function?”

A gentleman with a rather handsome beard named Arthur O'Dwyer gave a talk at CppCon 2016 on templates and template type deduction which is available on youtube [this video]

Recommends StoryTeller - Unslander Monica · 2017-08 · Stack Overflow · on “Why don't forwarding references work with template template parameters?”

@ixSci - *"`Container ` gets deduced when the function is called"*. No, because it's not a parameter of the template. The parameters of the template, and the only things that can be deduced are `T` and `Container`. They can indeed be deduced from the type of the argument being passed to the function. If you want an approachable explanation with standard quotes sprinkled in, watch this two parter from CppCon 2016 [this video] .

Recommends Arda Aytekin · 2018-03 · Stack Overflow · on “Seeking clarification on std::forward”

There is a distinction between void f1(int&& a) {} template<class T> void f2(T&& a) {} The first version is defining f1 to work on rvalues. The second version, on the other hand, is a template function accepting a universal (or in some references, forwarding) reference as its argument. To understand the mechanics of std::forward , you should call f2 with different arguments, as in: #include <iostream> template <class T> void f2(T &&a) { std::cout << __PRETTY_FUNCTION__ << '\n'; } int main() { int a{5}; f2(5); f2(a); return 0; } When you compile the code, say with g++ , you get the following output from your program: ./a.out void f2(T &&) [T = int] void f2(T &&) [T = int &] As you can see, in

Cites Quuxplusone · 2017-05 · Stack Overflow · on “C++ static template function causes armcc compilation error (304)”

@Kobi: No; `template<>` is the syntax for a full specialization. `template` is the syntax for an explicit instantiation, which is indeed what we want here. Shameless plug: [this video]