language: C++11 (gcc-4.7.2)
date: 326 days 13 hours ago
link:
visibility: public
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
#include <iostream>
#include <cstdlib>
 
using namespace std;
 
struct Noisy {
        int n;
        Noisy() :n(0) { cout << "Noisy()\n"; }
        Noisy(const Noisy & o) :n(o.n) { cout << "copy Noisy\n"; }
        Noisy(Noisy&& o) :n(o.n) { cout << "move Noisy\n"; }
};
 
Noisy foo(bool x)
{
        Noisy a;
        a.n = 5;
        Noisy b;
        b.n = 10;
 
        // does this not exclude the possibility of copy elision?
        if (x) return a;
        else return b;
}
 
int main()
{
        // does this not move?  See output below
        Noisy n = foo(rand()%2==0);
        cout << n.n;
}