Template Specialization In C++

  Рет қаралды 16,950

CppNuts

CppNuts

Күн бұрын

Пікірлер: 28
@treyquattro
@treyquattro 4 жыл бұрын
so here's a question: what are the relative merits and disadvantages of providing the functionality in the video via: 1. using a template specialization 2. using a non-template function predicated on the specialized type (basically the addAll string specialization but drop the template 3. compile-time specialization in the ordinary template version via if constexpr(...) (put the extra string-specific code in compile-time conditional blocks) I think if the algorithm is substantially the same then option 3 above is a good solution: we want to avoid copying code as much as possible (ODR). Thoughts?
@kanishkjain2767
@kanishkjain2767 2 жыл бұрын
great job would be better if u have shown an example for class template specialization too
@CppNuts
@CppNuts 2 жыл бұрын
Thanks man!!
@SimplySpiceIt
@SimplySpiceIt 5 жыл бұрын
addAll() could have taken the std::vector as const-ref(no reason to work with the copy); on the other hand, primitive types, you doN't need that, just copy( for(T element: list)). count should have been std::vector::size_type. Other than that, to demonstrate the concept, the given example is fine.
@CppNuts
@CppNuts 5 жыл бұрын
Hi Paterolen Exactly!!
@CppNuts
@CppNuts 5 жыл бұрын
@@SimplySpiceIt, may be we didn't understood you correctly, please provide some working example of what are you trying to explain here. (paste working code here)
@SimplySpiceIt
@SimplySpiceIt 5 жыл бұрын
@@CppNuts Apologies. I took the literal meaning of `count`, All that you doing a simple summation of elements, where we must use T as the @Paterolen mentioned. However, the identifier count made all confusion.
@SimplySpiceIt
@SimplySpiceIt 5 жыл бұрын
@@CppNuts However, my first two points are still valid. Here is what you could have done instead: template T addAll(const std::vector &list) { return std::accumulate(list.cbegin(), list.cend(), static_cast(0)); } template std::string addAll(const std::vector &list) { std::size_t sum = 0; // naming made all confusion for (const std::string &str : list) for (const char chr : str) sum += chr; return std::to_string(sum); } int main() { std::cout
@pramodkumarkar8153
@pramodkumarkar8153 5 жыл бұрын
@@SimplySpiceIt exactly aggre
@qureshiowais6951
@qureshiowais6951 3 жыл бұрын
is this function overloading?
@ChandanKr.16
@ChandanKr.16 3 жыл бұрын
Kindly make one long video for templates
@CppNuts
@CppNuts 3 жыл бұрын
Ok I will try
@ChandanKr.16
@ChandanKr.16 3 жыл бұрын
@@CppNuts thanks sir
@preetikhanna7034
@preetikhanna7034 4 жыл бұрын
What is: for(auto& elem: list)
@CppNuts
@CppNuts 4 жыл бұрын
Here is my video it's called range-based for loop. kzbin.info/www/bejne/mqfEon-kl8l4ma8
@enzomannaert7324
@enzomannaert7324 4 жыл бұрын
A ranged based for loop, it goes over every element in de list.
@pramodkumarkar8153
@pramodkumarkar8153 5 жыл бұрын
Excellent !!
@CppNuts
@CppNuts 5 жыл бұрын
Thanks!!
@ramezanikebrya
@ramezanikebrya 4 жыл бұрын
Thanks for the nice video, but too many ads come while you are watching!
@CppNuts
@CppNuts 4 жыл бұрын
Sorry man, that's all I can say.
@ramezanikebrya
@ramezanikebrya 4 жыл бұрын
@@CppNuts No problem. Thanks for the interesting video.
@mockingbird3809
@mockingbird3809 4 жыл бұрын
Amazing video! Do we have a Discord? (or IRC)
@tinuchoudhary.
@tinuchoudhary. 4 жыл бұрын
Could you explain in hindi
@CppNuts
@CppNuts 4 жыл бұрын
I can but i have to create new channel for that..
@gayathrichagani665
@gayathrichagani665 4 жыл бұрын
Video is not clear the screen is full blurr sir. Please make sure that your video is clear
@CppNuts
@CppNuts 4 жыл бұрын
KZbin have reduced the resolution for mobiles if you want to see e good quality video please please watch it from computer.
@abhishekgupta-yh2vn
@abhishekgupta-yh2vn 5 жыл бұрын
Dogs barking at 4:29 :P
@CppNuts
@CppNuts 5 жыл бұрын
Don't have much control on environment.
Multithreading In C++
18:10
CppNuts
Рет қаралды 206 М.
Overloading Function Template In C++
19:32
CppNuts
Рет қаралды 14 М.
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
Pure Virtual Function In C++
16:15
CppNuts
Рет қаралды 14 М.
Virtual Function In C++
15:08
CppNuts
Рет қаралды 36 М.
Template In C++
10:36
CppNuts
Рет қаралды 33 М.
Virtual Destructor In C++
10:17
CppNuts
Рет қаралды 16 М.
reinterpret_cast In C++
14:33
CppNuts
Рет қаралды 44 М.
Static Data Member And Static Member Function In C++
17:19
CppNuts
Рет қаралды 52 М.
const Keyword Behaviour With Function Overloading In C++
6:32
Assignment Operator Overloading In C++
13:14
CppNuts
Рет қаралды 13 М.
Const Data Member In C++
15:03
CppNuts
Рет қаралды 23 М.
Templates in C++
17:58
The Cherno
Рет қаралды 605 М.
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН