Templates under the hood

  Рет қаралды 1,431

Code for yourself

Code for yourself

Күн бұрын

Пікірлер: 17
@zamf
@zamf 10 ай бұрын
It is also worth mentioning that templates are usually defined in the header file since they can be used in multiple translation units. Because of this the linker can end up with multiple specializations with the same template arguments but it picks one of them and ignores the rest as it assumes that all of them come from the same template definition and therefore are identical.
@CodeForYourself
@CodeForYourself 10 ай бұрын
Thanks for mentioning this! We will talk about header and source files soon. As well as all the details of how to write templates well and what linkage template functions have. Here I wanted to give an intuitive explanation of what the compiler does when it sees templates. Does this make sense?
@zamf
@zamf 10 ай бұрын
@@CodeForYourself Absolutely. The explanation was great and clear. I'm probably rushing into the next video already :)
@CodeForYourself
@CodeForYourself 10 ай бұрын
Yeah, I’m dreading preparing that video. Really a lot of things to think and tell about 😅
@KotlasBoy
@KotlasBoy 8 ай бұрын
Great gratitude from 1 course student!
@CodeForYourself
@CodeForYourself 8 ай бұрын
Thanks for sticking around! 🙏
@bsdooby
@bsdooby 10 ай бұрын
Looking forward to the series!
@longvuong2600
@longvuong2600 10 ай бұрын
Ah very first view! 😁 Thank you for the video as usual!
@CodeForYourself
@CodeForYourself 10 ай бұрын
Thanks for watching! 🙏
@MateusDuarttee
@MateusDuarttee 10 ай бұрын
Great video! One doubt, template metaprogramming, is just using templates inside templates?
@CodeForYourself
@CodeForYourself 10 ай бұрын
I wouldn’t say so. I would say that template meta programming is writing logic using templates such that its result is available also at compile time. This way it can be used for conditional compilation of just parts of the code. Does that make any sense?
@MateusDuarttee
@MateusDuarttee 10 ай бұрын
@@CodeForYourself yes, so when doing metaprogramming i'm not just trying to do generic programming, but actually do computational steps in compile time, that is right?
@CodeForYourself
@CodeForYourself 10 ай бұрын
@@MateusDuarttee to a degree. They are not always related to the computation that you actually want to do in your main program but they have complex logic and their result must be available at compile time. One example I can give that I’ve done some time ago is this. I had an array of values that represented physical quantities. I was implementing an algorithm that would smooth such values over time by applying certain mathematical operations to the whole array. Now this can be quite error prone if we mix up the order of the values. So I used template meta programming to guard myself. Every value would have a type in association with it. These types would be ordered just like my values. Every operation then would check if the order of these indicator types corresponds to the expected order. All of this at compile time. So if I would try to update, say, speed in my array as if it were position by mistake I would get a compile time error that would protect me from making this mistake. Sorry for a slightly convoluted and hand-wavy example but that’s the best I can do for now. I think we will talk about this later too. Does it answer your question in any way?
@MateusDuarttee
@MateusDuarttee 10 ай бұрын
@@CodeForYourself Thank you a lot for the answer!! Now i guess that the idea of meta programming is more clear in my mind, also congrats for the videos to, great job!
@CodeForYourself
@CodeForYourself 10 ай бұрын
@@MateusDuarttee glad it helped!
@Partey-xh3fr
@Partey-xh3fr 10 ай бұрын
Маєш файну футболку
@CodeForYourself
@CodeForYourself 10 ай бұрын
Не кажи 😉
How to use FUNCTION TEMPLATES - a comprehensive guide for modern C++
23:33
Code for yourself
Рет қаралды 2,8 М.
Why use templates in modern C++
12:32
Code for yourself
Рет қаралды 2,2 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 148 МЛН
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Const correctness in C++
10:02
Code for yourself
Рет қаралды 3,5 М.
Become a bash scripting pro - full course
36:00
CODE IS EVERYTHING
Рет қаралды 72 М.
Re-inventing move semantics in modern C++ in 13 minutes
13:20
Code for yourself
Рет қаралды 7 М.
IPC: To Share Memory Or To Send Messages
14:15
Core Dumped
Рет қаралды 100 М.
When Optimisations Work, But for the Wrong Reasons
22:19
SimonDev
Рет қаралды 1,1 МЛН
Vim Tips I Wish I Knew Earlier
23:00
Sebastian Daschner
Рет қаралды 83 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН