// C++ function template example with value and type parameters
#include <string>
using namespace std;

// return pointer to new heap array with N copies of val (not quite
// realistic, but shows what’s possible -- better example would be a
// template whose non-type parameter specifies the size of a
// fixed-size queue or list in a class)
template<typename T, int N> 
T* valarray(const T &val) {
  T* a = new T[N];
  for (int i = 0; i < N; ++i)
    a[i] = val;
  return a;
}

int main(int argc, char **argv) {
  int *ip = valarray<int,10>(17);
  string *sp = valarray<string,17>("hello");

  delete[] ip;
  delete[] sp;
  return 0;
}