Counting instantiations from literal types

A C++ program defines the function template below and then makes seven calls to it in main.


C++
template < typename T >
T mid(T a, T b) { return a + (b - a) / 2; }

mid(2, 10);
mid(1.5, 4.0);
mid('a', 'e');
mid(6, 9);
mid(2.0f, 3.0f);
mid(0.25, 0.75);
mid(100L, 300L);


How many distinct instantiations of mid does the compiler generate? Give your answer as a whole number.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Generics Questions: