language: C++11 (gcc-4.7.2)
date: 550 days 3 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
#include <stdio.h>
#include <string.h>
#include <functional>
 
class Simple {
public:
    Simple( int value ) { puts( "Constructing simple!" ); this->value = value; }
    Simple( const Simple& rhs ) { puts( "Copying simple!" ); this->value = rhs.value; }
    Simple( Simple&& rhs ) { puts( "Moving simple!" ); this->value = rhs.value; }
    ~Simple() { puts( "Destroying simple!" ); }
    int Get() const { return this->value; }
 
private:
    int value;
};
 
int main()
{
    Simple test( 5 );
 
    std::function<int ()> f =
        [test] ()
        {
            return test.Get();
        };
 
    printf( "%d\n", f() );
}