HTML & JS
// A C++ program to demonstrate working of non-type
// parameters to templates in C++.
#include <iostream>
using namespace std;
 
template <class T, int max>
int arrMin(T arr[], int n)
{
   int m = max;
   for (int i = 0; i < n; i++)
      if (arr[i] < m)
         m = arr[i];
 
   return m;
}
 
int main()
{
   int arr1[]  = {10, 20, 15, 12};
   int n1 = sizeof(arr1)/sizeof(arr1[0]);
 
   char arr2[] = {1, 2, 3};
   int n2 = sizeof(arr2)/sizeof(arr2[0]);
 
   // Second template parameter to arrMin must be a constant
   int x = 10000;
   cout << arrMin<int, x>(arr1, n1) << endl;
   cout << arrMin<char, 256>(arr2, n2);
   return 0;
}

Generated URL:

Output:

No Output
Report Bug