fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <vector>
  5.  
  6. template <class T>
  7. class A
  8. {
  9. public:
  10. A(const T* a, size_t count): a_(a, a + count) {}
  11. void f()
  12. {
  13. std::for_each(a_.begin(),
  14. a_.end(),
  15. [](const T& a_t) { std::cout << a_t << "\n"; });
  16. }
  17. private:
  18. std::vector<T> a_;
  19. };
  20.  
  21. int main()
  22. {
  23. A<char> a("hello", 5);
  24. a.f();
  25.  
  26. int ints[] = { 1, 2, 3, 4, 5 };
  27. A<int> my_ints(ints, sizeof(ints)/sizeof(ints[0]));
  28. my_ints.f();
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 3060KB
stdin
Standard input is empty
stdout
h
e
l
l
o
1
2
3
4
5