language: C++11 (gcc-4.7.2)
date: 204 days 9 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
 
struct C
{
    C(int n_) : n(n_) {};
    C(const C& x) { n = x.n; std::cout << "Copy: " << n << std::endl; }
    C(C&& x)      { n = x.n; std::cout << "Move: " << n << std::endl; }
    int n;
};
 
template <class X, class Y>
struct Pair
{
    X x;
    Y y;
};
 
template <class X, class Y>
Pair<X, Y> make_pair(X&& x, Y&& y)
{
    return Pair<X, Y>{std::forward<X>(x), std::forward<Y>(y)};
}
 
#define MAKE_PAIR(x,y) decltype(make_pair(x,y)){x,y}
 
int main()
{
    auto z1 = Pair<C, C>{C(1),C(2)};
    auto z2 = make_pair(C(3),C(4));
    auto z3 = MAKE_PAIR(C(5),C(6));
}