#include <iostream>
void overloaded( int const & arg ) { std:: cout << "by lvalue\n " ; }
void overloaded( int && arg ) { std:: cout << "by rvalue\n " ; }
template < typename t >
void forwarding( t && arg ) {
std:: cout << "via std::forward: " ;
overloaded( std:: forward < t > ( arg ) ) ;
std:: cout << "via std::move: " ;
overloaded( std:: move ( arg ) ) ;
std:: cout << "by simple passing: " ;
overloaded( arg ) ;
}
int main( ) {
std:: cout << "initial caller passes rvalue:\n " ;
forwarding( 5 ) ;
std:: cout << "initial caller passes lvalue:\n " ;
int x = 5 ;
forwarding( x ) ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdm9pZCBvdmVybG9hZGVkKCBpbnQgY29uc3QgJmFyZyApIHsgc3RkOjpjb3V0IDw8ICJieSBsdmFsdWVcbiI7IH0Kdm9pZCBvdmVybG9hZGVkKCBpbnQgJiYgYXJnICkgeyBzdGQ6OmNvdXQgPDwgImJ5IHJ2YWx1ZVxuIjsgfQoKdGVtcGxhdGU8IHR5cGVuYW1lIHQgPgp2b2lkIGZvcndhcmRpbmcoIHQgJiYgYXJnICkgewogICAgc3RkOjpjb3V0IDw8ICJ2aWEgc3RkOjpmb3J3YXJkOiAiOwogICAgb3ZlcmxvYWRlZCggc3RkOjpmb3J3YXJkPCB0ID4oIGFyZyApICk7CiAgICBzdGQ6OmNvdXQgPDwgInZpYSBzdGQ6Om1vdmU6ICI7CiAgICBvdmVybG9hZGVkKCBzdGQ6Om1vdmUoIGFyZyApICk7CiAgICBzdGQ6OmNvdXQgPDwgImJ5IHNpbXBsZSBwYXNzaW5nOiAiOwogICAgb3ZlcmxvYWRlZCggYXJnICk7Cn0KCmludCBtYWluKCkgewogICAgc3RkOjpjb3V0IDw8ICJpbml0aWFsIGNhbGxlciBwYXNzZXMgcnZhbHVlOlxuIjsKICAgIGZvcndhcmRpbmcoIDUgKTsKICAgIHN0ZDo6Y291dCA8PCAiaW5pdGlhbCBjYWxsZXIgcGFzc2VzIGx2YWx1ZTpcbiI7CiAgICBpbnQgeCA9IDU7CiAgICBmb3J3YXJkaW5nKCB4ICk7Cn0K