fork download
  1. #include <iostream>
  2. #include <utility>
  3.  
  4. using namespace std;
  5.  
  6. namespace details {
  7. template <class T1, class T2>
  8. struct tie{
  9. T1& first;
  10. T2& second;
  11.  
  12. tie(T1& x, T2& y) : first(x), second(y) {}
  13.  
  14. tie<T1, T2>& operator=(const pair<T1, T2>& rhs){
  15. first = rhs.first;
  16. second = rhs.second;
  17.  
  18. return *this;
  19. }
  20. };
  21. }
  22.  
  23. template <class T1, class T2>
  24. details::tie<T1, T2> tie(T1& x, T2& y) {
  25. return details::tie<T1, T2>(x, y);
  26. }
  27.  
  28. pair<int, int> test() {
  29. return make_pair(13, 42);
  30. }
  31.  
  32. int main() {
  33. int a = 1, b = 2;
  34. int c = 3, d = 4;
  35.  
  36. details::tie<int, int>(a, b) = test();
  37. tie(c, d) = test();
  38.  
  39.  
  40. cout << a << ' ' << b << endl << c << ' ' << d << endl;
  41.  
  42. }
Success #stdin #stdout 0s 2740KB
stdin
Standard input is empty
stdout
13 42
13 42