Hi Guys,
I am studying templates in C++, and just run into this question:"Does template specialization have any use?", because I think if no general type argument, what does these templates use for?
Template metaprogramming requires specialization to make decisions, thus specialization is required to write recursive metafunctions, otherwise they would never terminate (at least not without the compiler rejecting the program or crashing).
My only objection with your example is that it compiles and runs correctly whether or not you have the "template specialization" syntax in there or not -- which, if it's the only example, reinforces OP's original thought. (I'm not too knowledgeable on template specialization myself so I can't really give my own proper example.)
@Thomas1965
I got it from your examples. Template specialization talks about templates' specialization. First
of all, templates are used for defining a bunch of similar functions/classes, but if there're special cases like needing different behaviors under certain data types, we need template specialization. Thx all guys, really helpful community here.
yes, but as JLBorges correctly points out, for function templates overloading is better in every way. Specializations are for class templates (and variable templates).
Speaking of less, here's an example of a full specialization of a class template in standard C++: http://en.cppreference.com/w/cpp/utility/functional/less_void