fork download
  1. #include <type_traits>
  2. #include <iostream>
  3. #include <vector>
  4. #include <array>
  5.  
  6. template <class Tv, class T, size_t cn>
  7. void push_back(std::vector<Tv> & v, std::array<T, cn> const & el)
  8. {
  9. for (int i = 0; i < cn; ++i) {
  10. v.push_back(el[i]);
  11. }
  12. }
  13.  
  14.  
  15. template <class Tv, class T,
  16. typename std::enable_if<std::is_assignable<Tv&, T>::value, bool>::type = 0>
  17. void push_back(std::vector<Tv> & v, T el)
  18. {
  19. v.push_back(el);
  20. }
  21.  
  22.  
  23. int main()
  24. {
  25. std::array<float, 5> a{1, 2, 3, 4, 5};
  26. std::vector<double> v;
  27. push_back(v, a);
  28. push_back(v, 27);
  29. for (double el : v) {
  30. std::cout << el << "\t";
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1	2	3	4	5	27