C++ Templates - Part 1: Why do we need templates?

  Рет қаралды 14,934

oneproduct

oneproduct

Күн бұрын

Пікірлер: 18
@ItsBaffledd
@ItsBaffledd Жыл бұрын
I hope you're doing well, came across your videos a few days ago about move semantics and keep getting your stuff recommended.
@BrewskaySA
@BrewskaySA 3 жыл бұрын
3 years later after watching this video, my main take away is that "it needs to be fooable!"
@kostiantynreminnyi3507
@kostiantynreminnyi3507 Жыл бұрын
Good job.
@LV-ei1ce
@LV-ei1ce 5 жыл бұрын
Brilliant explanation !
@chilinouillesdepommesdeter819
@chilinouillesdepommesdeter819 6 жыл бұрын
how could I master c++ like you?
@valizeth4073
@valizeth4073 5 жыл бұрын
Code a lot in it, doesn't really matter what, just be active in the language and always question why you're doing certain things.
@KeenlyJohnas
@KeenlyJohnas 3 жыл бұрын
Good work! Concepts will be closer to natural language programming than ever. Still C++ is quite challenging though.
@dnavas7719
@dnavas7719 6 жыл бұрын
Awesome explanation. Thanks.
@marcin1694
@marcin1694 2 жыл бұрын
I really like that video :)
@zakiachen5443
@zakiachen5443 3 жыл бұрын
really nice! thank you
@valizeth4073
@valizeth4073 5 жыл бұрын
The reason why java has Integer, Double, ... classes is because generics (sorta templates) in java don't allow primitive types, for some dumb reason. So you'll have to pass a wrapper to it.
@MGSncB
@MGSncB 3 жыл бұрын
The reason isn't dumb, actually. In java, when you create a reference type variable, what is pushed onto the stack is, well... A "reference". Which is sort of like a handle, a descriptor (for those who are familiar with WinAPI). It is opaque, and it has nothing to do with the actual address (unlike a raw pointer), you give it to the runtime and in return you get access to data. But most importantly, it is just a NUMBER, an integer (int32 or int64, depends on the targeted platform). Let's say you could create a generic method in java for primitive "int" as , with T t as method parameter. What IS that T at runtime? The JVM does not know, it is just a number AFA it knows. The type info is erased. And the body for that generic method is shared across types, so... Is that an int? A float? A reference on 32-bit platforms? Java generics is just a compiler trick with inserting casts, they are garbage (see article "Java type system is unsound"). .NET guys got it right (see "reification" - the CLR/CoreCLR preserves type information at runtime, you can do very cool things with it. Also, the JIT compiler generates a body for each value type, so you can use "int"). Not as powerful as C++ templates, though.
@amrtcpp6203
@amrtcpp6203 4 жыл бұрын
Thanks
@fuchsto
@fuchsto 6 жыл бұрын
I like everything about this video except the title: It should be "Why do we need concepts?". Concepts are about expressions. They are typically realized by means of templates but concepts and templates are independent. For example, a native pointer `int *` would satisfy the random access iterator concept.
@unusualfashion
@unusualfashion 6 жыл бұрын
As this little series is about templates overall, I think the fact that these concept-like problems are typically solved using templates is a fine enough reason to emphasize that part of it. Mostly I want to introduce people to other forms of polymorphism other than inheritance, so I don't mind tying in the mechanism with the ideal. It would also likely be confusing to include the word "concepts" in the title when I'm not talking about concepts as they are/are going to be in the near future, and it would certainly make this video appear in search results where it isn't relevant and not show up in searches where people are trying to learn about templates for the first time. There's also the other use case of templates which I mention a bit when talking about vectors, where the type itself doesn't necessarily even need to have any particular concepts and is truly generic. This isn't strictly true with a vector, as certain operations require a few basic concepts (particularly if you want to talk about constructible-level things), but you could imagine some use case that is actually fully generic.
@fuchsto
@fuchsto 6 жыл бұрын
Ah, sorry, I did not realize this is part of a series. So that is to say I like everything about this video. Especially how you illustrated the comparison with interfaces.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 334 М.
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 44 МЛН
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 52 МЛН
Emulating a CPU in C++ (6502)
52:28
Dave Poo
Рет қаралды 1 МЛН
C++ Templates - Part 4 : Curiously Recurring Template Pattern
12:22
Learn Any Programming Language In 3 Hours!
22:37
Code With Huw
Рет қаралды 603 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН
C++ Tutorial 14 : Templates & Iterators
22:13
Derek Banas
Рет қаралды 74 М.
Templates in C++
17:58
The Cherno
Рет қаралды 605 М.
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 44 МЛН