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?
@kanishkjain27672 жыл бұрын
great job would be better if u have shown an example for class template specialization too
@CppNuts2 жыл бұрын
Thanks man!!
@SimplySpiceIt5 жыл бұрын
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.
@CppNuts5 жыл бұрын
Hi Paterolen Exactly!!
@CppNuts5 жыл бұрын
@@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)
@SimplySpiceIt5 жыл бұрын
@@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.
@SimplySpiceIt5 жыл бұрын
@@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
@pramodkumarkar81535 жыл бұрын
@@SimplySpiceIt exactly aggre
@qureshiowais69513 жыл бұрын
is this function overloading?
@ChandanKr.163 жыл бұрын
Kindly make one long video for templates
@CppNuts3 жыл бұрын
Ok I will try
@ChandanKr.163 жыл бұрын
@@CppNuts thanks sir
@preetikhanna70344 жыл бұрын
What is: for(auto& elem: list)
@CppNuts4 жыл бұрын
Here is my video it's called range-based for loop. kzbin.info/www/bejne/mqfEon-kl8l4ma8
@enzomannaert73244 жыл бұрын
A ranged based for loop, it goes over every element in de list.
@pramodkumarkar81535 жыл бұрын
Excellent !!
@CppNuts5 жыл бұрын
Thanks!!
@ramezanikebrya4 жыл бұрын
Thanks for the nice video, but too many ads come while you are watching!
@CppNuts4 жыл бұрын
Sorry man, that's all I can say.
@ramezanikebrya4 жыл бұрын
@@CppNuts No problem. Thanks for the interesting video.
@mockingbird38094 жыл бұрын
Amazing video! Do we have a Discord? (or IRC)
@tinuchoudhary.4 жыл бұрын
Could you explain in hindi
@CppNuts4 жыл бұрын
I can but i have to create new channel for that..
@gayathrichagani6654 жыл бұрын
Video is not clear the screen is full blurr sir. Please make sure that your video is clear
@CppNuts4 жыл бұрын
KZbin have reduced the resolution for mobiles if you want to see e good quality video please please watch it from computer.