fork download
  1. #include<vector>
  2. #include<iostream>
  3. #include<utility>
  4.  
  5. namespace named_operator {
  6. template<class D>struct make_operator{make_operator(){}};
  7.  
  8. template<class T, char, class O> struct half_apply { T&& lhs; };
  9.  
  10. template<class Lhs, class Op>
  11. half_apply<Lhs, '+', Op> operator+( Lhs&& lhs, make_operator<Op> ) {
  12. return {std::forward<Lhs>(lhs)};
  13. }
  14.  
  15. template<class Lhs, class Op, class Rhs>
  16. auto operator+( half_apply<Lhs, '+', Op>&& lhs, Rhs&& rhs )
  17. -> decltype( named_invoke( std::forward<Lhs>(lhs.lhs), Op{}, std::forward<Rhs>(rhs) ) )
  18. {
  19. return named_invoke( std::forward<Lhs>(lhs.lhs), Op{}, std::forward<Rhs>(rhs) );
  20. }
  21. }
  22.  
  23. namespace ops {
  24. struct concat_t:named_operator::make_operator<concat_t>{};
  25. static const concat_t concat{};
  26. template<class T, class A, class A2>
  27. std::vector<T,A> named_invoke( std::vector<T,A> lhs, concat_t, std::vector<T,A2> const& rhs){
  28. lhs.insert(lhs.end(), rhs.begin(), rhs.end());
  29. return std::move(lhs);
  30. }
  31. }
  32. using ops::concat;
  33.  
  34. int main(){
  35. std::vector<int> a{1,2,3};
  36. std::vector<int> b{7,8,9};
  37.  
  38. for( auto x: a +concat+ a +concat+ b )
  39. std::cout <<x<<'\n';
  40. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
1
2
3
1
2
3
7
8
9