fork download
  1. #include <iostream>
  2. #include <array>
  3. #include <algorithm>
  4.  
  5. template< typename T,
  6. size_t sizeA,
  7. size_t sizeB >
  8. std::array<T, sizeA+sizeB> operator<<(const std::array<T, sizeA> &one,
  9. const std::array<T, sizeB> &two)
  10. {
  11. std::array<T, sizeA + sizeB> result;
  12.  
  13. // copy first part to the new array
  14. auto endOfFirst = std::copy(std::cbegin(one),
  15. std::cend(one),
  16. std::begin(result));
  17.  
  18. // copy a rest of elements from second array
  19. std::copy(std::cbegin(two),
  20. std::cend(two),
  21. endOfFirst);
  22.  
  23. // sort results
  24. std::sort(std::begin(result),std::end(result));
  25. return result;
  26. }
  27.  
  28. int main() {
  29. std::array<int, 3> a = {1, 2, 3};
  30. std::array<int, 5> b = {8, 7, 6, 5, 4};
  31.  
  32. auto result = b << a; // the type is std::array<int, N+M>
  33.  
  34. for (auto item : result) {
  35. std::cout << item << "|";
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1|2|3|4|5|6|7|8|