#include <iostream>
#include <vector>
#include <tr1/functional>
class foo {
private:
int val;
foo() {}
foo(int v) : val(v) {}
public:
static foo create(int v) { return foo(v); }
int value() const { return val; }
};
class bar {
private:
int val;
bar(const bar&) {}
public:
bar() {}
bar(int v) : val(v) {}
int value() const { return val; }
void value(int v) { val = v; }
};
class baz {
private:
int val;
baz() {}
baz(int v) : val(v) {}
baz(const baz&) {}
public:
int value() const { return val; }
static baz create(int v) { return baz(v); }
};
int main()
{
using namespace std;
{
vector<foo> v;
v.push_back(foo::create(1));
cout << v[0].value() << endl;
}
{
vector<tr1::reference_wrapper<bar> > v;
bar x(2);
v.push_back(tr1::ref(x));
bar& y = v[0];
cout << v[0].get().value();
y.value(3);
cout << ' ' << v[0].get().value() << ' ' << x.value() << endl;
}
{
vector<tr1::reference_wrapper<const baz> > v;
const baz& x = baz::create(4);
v.push_back(tr1::ref(x));
const baz& y = v[0];
cout << y.value() << ' ' << v[0].get().value() << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8dHIxL2Z1bmN0aW9uYWw+CgpjbGFzcyBmb28gewogIHByaXZhdGU6CiAgICBpbnQgdmFsOwogICAgZm9vKCkge30KICAgIGZvbyhpbnQgdikgOiB2YWwodikge30KICBwdWJsaWM6CiAgICBzdGF0aWMgZm9vIGNyZWF0ZShpbnQgdikgeyByZXR1cm4gZm9vKHYpOyB9CiAgICBpbnQgdmFsdWUoKSBjb25zdCB7IHJldHVybiB2YWw7IH0KfTsKCmNsYXNzIGJhciB7CiAgcHJpdmF0ZToKICAgIGludCB2YWw7CiAgICBiYXIoY29uc3QgYmFyJikge30KICBwdWJsaWM6CiAgICBiYXIoKSB7fQogICAgYmFyKGludCB2KSA6IHZhbCh2KSB7fQogICAgaW50IHZhbHVlKCkgY29uc3QgeyByZXR1cm4gdmFsOyB9CiAgICB2b2lkIHZhbHVlKGludCB2KSB7IHZhbCA9IHY7IH0KfTsKCmN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