fork(2) download
  1. #include <iostream>
  2. #include <array>
  3. #include <algorithm>
  4.  
  5. const int N = 3;
  6. const int M = 5;
  7.  
  8. std::array<int, N+M> operator<<(const std::array<int, N> &one,
  9. const std::array<int, M> &two)
  10. {
  11. std::array<int, N+M> 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. // needed to support "a << b" and "b << a"
  29. std::array<int, N+M> operator<<(const std::array<int, M> &one,
  30. const std::array<int, N> &two)
  31. {
  32. return operator<<(two, one);
  33. }
  34.  
  35. int main() {
  36. std::array<int, N> a = {1, 2, 3};
  37. std::array<int, M> b = {8, 7, 6, 5, 4};
  38.  
  39. auto result = b << a; // the type is std::array<int, N+M>
  40.  
  41. for (auto item : result) {
  42. std::cout << item << "|";
  43. }
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1|2|3|4|5|6|7|8|