Templates under the hood

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

Code for yourself

Code for yourself

Күн бұрын

Пікірлер: 17
@zamf
@zamf 9 ай бұрын
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 9 ай бұрын
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 9 ай бұрын
@@CodeForYourself Absolutely. The explanation was great and clear. I'm probably rushing into the next video already :)
@CodeForYourself
@CodeForYourself 9 ай бұрын
Yeah, I’m dreading preparing that video. Really a lot of things to think and tell about 😅
@bsdooby
@bsdooby 9 ай бұрын
Looking forward to the series!
@KotlasBoy
@KotlasBoy 7 ай бұрын
Great gratitude from 1 course student!
@CodeForYourself
@CodeForYourself 7 ай бұрын
Thanks for sticking around! 🙏
@longvuong2600
@longvuong2600 9 ай бұрын
Ah very first view! 😁 Thank you for the video as usual!
@CodeForYourself
@CodeForYourself 9 ай бұрын
Thanks for watching! 🙏
@MateusDuarttee
@MateusDuarttee 9 ай бұрын
Great video! One doubt, template metaprogramming, is just using templates inside templates?
@CodeForYourself
@CodeForYourself 9 ай бұрын
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 9 ай бұрын
@@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 9 ай бұрын
@@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 9 ай бұрын
@@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 9 ай бұрын
@@MateusDuarttee glad it helped!
@Partey-xh3fr
@Partey-xh3fr 9 ай бұрын
Маєш файну футболку
@CodeForYourself
@CodeForYourself 9 ай бұрын
Не кажи 😉
How to use FUNCTION TEMPLATES - a comprehensive guide for modern C++
23:33
Code for yourself
Рет қаралды 2,6 М.
Why use templates in modern C++
12:32
Code for yourself
Рет қаралды 2,1 М.
1, 2, 3, 4, 5, 6, 7, 8, 9 🙈⚽️
00:46
Celine Dept
Рет қаралды 89 МЛН
Motorbike Smashes Into Porsche! 😱
00:15
Caters Clips
Рет қаралды 23 МЛН
СОБАКА ВЕРНУЛА ТАБАЛАПКИ😱#shorts
00:25
INNA SERG
Рет қаралды 3,6 МЛН
Don't use static (outside of classes) in modern C++
15:56
Code for yourself
Рет қаралды 6 М.
"Hello, World" in 5 CURSED languages that no one should use
13:08
Dreams of Code
Рет қаралды 553 М.
Re-inventing move semantics in modern C++ in 13 minutes
13:20
Code for yourself
Рет қаралды 7 М.
Why I Use C | Prime Reacts
13:00
ThePrimeTime
Рет қаралды 175 М.
Abstraction is not the enemy... lack of documentation is.
17:41
1, 2, 3, 4, 5, 6, 7, 8, 9 🙈⚽️
00:46
Celine Dept
Рет қаралды 89 МЛН