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.
@CodeForYourself9 ай бұрын
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?
@zamf9 ай бұрын
@@CodeForYourself Absolutely. The explanation was great and clear. I'm probably rushing into the next video already :)
@CodeForYourself9 ай бұрын
Yeah, I’m dreading preparing that video. Really a lot of things to think and tell about 😅
@bsdooby9 ай бұрын
Looking forward to the series!
@KotlasBoy7 ай бұрын
Great gratitude from 1 course student!
@CodeForYourself7 ай бұрын
Thanks for sticking around! 🙏
@longvuong26009 ай бұрын
Ah very first view! 😁 Thank you for the video as usual!
@CodeForYourself9 ай бұрын
Thanks for watching! 🙏
@MateusDuarttee9 ай бұрын
Great video! One doubt, template metaprogramming, is just using templates inside templates?
@CodeForYourself9 ай бұрын
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?
@MateusDuarttee9 ай бұрын
@@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?
@CodeForYourself9 ай бұрын
@@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?
@MateusDuarttee9 ай бұрын
@@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!