Interview Question

What is template specialization?

Specialization customizes a template for selected arguments.

💡 Concept ✅ Quick Revision 🧠 C++

Answer

Template specialization supplies behavior for particular template arguments. • An explicit specialization replaces the primary template for a matching argument list. • Class templates may be partially specialized for a family of arguments. • Function templates cannot be partially specialized, though they can be overloaded.

💡 C++ Example

template<class T> struct TypeName { static constexpr const char* value = "other"; }; template<> struct TypeName<int> { static constexpr const char* value = "int"; };

⚡ Quick Revision

Specialization customizes a template for selected arguments.