arrtemp.cpp 627 B

12345678910111213141516171819202122232425262728
  1. // arrtemp.cpp -- using template functions with array template
  2. #include <iostream>
  3. #include <array>
  4. #include <string>
  5. template <class T, size_t n>
  6. void display(const std::array<T, n> & ar);
  7. int main()
  8. {
  9. std::array<int, 5> ai = {1,2,3,4,5}; //,6,7,8,9,22};
  10. std::array<std::string, 5> as =
  11. {
  12. "string under construction",
  13. "stupid string indeed",
  14. "there's nothing to see",
  15. "nothing to do",
  16. "but enjoy all that is"
  17. };
  18. display(ai);
  19. display(as);
  20. // std::cin.get();
  21. return 0;
  22. }
  23. template <class T, size_t n>
  24. void display(const std::array<T, n> & ar)
  25. {
  26. for (int i = 0; i < 5; i++)
  27. std::cout << ar[i] << std::endl;
  28. }