Can you correctly guess what this does?
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 33 34 35 36 37 38 39 40 41
|
#include <iostream>
struct Bystander
{
Bystander()
{
std::cout << "Innocent Bystander appears" << std::endl;
}
~Bystander()
{
std::cout << "Innocent Bystander was shot" << std::endl;
}
};
struct Accomplice
{
Bystander const &b;
Accomplice(Bystander const &b)
: b(b)
{
std::cout << "Accomplice received Innocent Bystander" << std::endl;
}
~Accomplice()
{
std::cout << "Accomplice abandoned Innocent Bystander" << std::endl;
}
};
auto Perpetrator(Bystander const &b)
-> Accomplice
{
std::cout << "Committing a Crime by giving Innocent Bystander to Accomplice" << std::endl;
return b;
}
int main()
{
std::cout << "About to interact with Perpetrator" << std::endl;
auto a = Perpetrator(Bystander());
std::cout << "Finished interacting with Perpetrator" << std::endl;
}
|
http://ideone.com/8ZTaDO |
http://coliru.stacked-crooked.com/a/fb925186c8f09a93
Last edited on
Hah, I forgot how recent that was. Still, there's some humor here.
Hang on. Shouldn't Accomplice be uncopiable?
They're taking advantage of their next door neighbor, Mr. Copy Elision.