FlashKeepers

C and C++ · College · College and University

C++ III: Templates

Function and class templates, specialization, variadic templates, type traits, SFINAE and C++20 concepts.

About this set

39 basic cards for College C and C++. Set 3 of 7 in C++. It opens with "What does a function template allow you to do?" and "How do you declare a function template?". Study it alongside the other College sets below.

39 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What does a function template allow you to do?
Show answerDefine a function that works with multiple data types by using type parameters instead of specific types.
How do you declare a function template?
Show answerUse the template keyword followed by angle brackets containing type parameters: template<typename T> returnType functionName(T param) { }
What is template instantiation?
Show answerThe process of creating a concrete function or class from a template by substituting actual types for template parameters.
What is template argument deduction?
Show answerThe compiler automatically determines what template arguments to use based on the function arguments passed at the call site.
What are explicit template arguments?
Show answerTemplate arguments you specify directly in angle brackets when calling a function template, overriding automatic deduction.
What is a class template?
Show answerA blueprint for creating classes that work with different data types, declared with the template keyword and type parameters.
How do you define a member function of a class template outside the class?
Show answerUse template<typename T> and scope resolution: template<typename T> ReturnType ClassName<T>::memberName(params) { }
What is a template member function?
Show answerA member function inside a class (template or not) that is itself a template with its own type parameters.
What is full template specialization?
Show answerA complete specialization where all template parameters are replaced with concrete types, providing a custom implementation for specific types.
What is partial template specialization?
Show answerA specialization where some template parameters remain generic while others are constrained, allowing matching multiple related types.
Can you partially specialize function templates?
Show answerNo, function templates do not support partial specialization, only full specialization. Use overloading as an alternative.
How does template specialization affect overload resolution?
Show answerMore specialized versions are preferred over general templates. Full specialization is preferred over partial, and partial over the general template.
What is a variadic template parameter pack?
Show answerA template parameter that can accept a variable number of arguments, declared as typename... Args or class... Args.
How do you expand a parameter pack?
Show answerUse the pack name followed by an ellipsis in a context where expansion makes sense, such as in function arguments or template arguments.
What is a base case in a variadic template?
Show answerA specialization or overload that terminates recursion by handling zero arguments, preventing infinite instantiation.

24 more cards in the app

Study this set free