#include<type_traits>
class foo {
} ;
class bar {
public :
const foo & to_foo( ) const {
return f;
}
foo & to_foo( ) {
return f;
}
private :
foo f;
} ;
template < typename T, typename Enable = void >
class convert { } ;
template < typename T >
struct convert< T, typename std:: enable_if < std:: is_member_function_pointer < decltype( & T:: to_foo ) > :: value > :: type > {
static const foo & call1( const bar & b ) {
return b.to_foo ( ) ;
}
static foo & call2( bar & b ) {
return b.to_foo ( ) ;
}
} ;
int main( ) {
bar b;
foo & f = convert< bar> :: call2 ( b ) ;
return 0 ;
}
I2luY2x1ZGU8dHlwZV90cmFpdHM+CgpjbGFzcyBmb28gewp9OwoKY2xhc3MgYmFyIHsKcHVibGljOgogIGNvbnN0IGZvbyAmIHRvX2ZvbygpIGNvbnN0IHsKICAgIHJldHVybiBmOwogIH0KCiAgZm9vICYgdG9fZm9vKCkgewogICAgcmV0dXJuIGY7CiAgfQpwcml2YXRlOgogZm9vIGY7Cn07Cgp0ZW1wbGF0ZTwgdHlwZW5hbWUgVCwgdHlwZW5hbWUgRW5hYmxlID0gdm9pZCA+CmNsYXNzIGNvbnZlcnQge307Cgp0ZW1wbGF0ZTwgdHlwZW5hbWUgVCA+CnN0cnVjdCBjb252ZXJ0PCBULCB0eXBlbmFtZSBzdGQ6OmVuYWJsZV9pZjwgc3RkOjppc19tZW1iZXJfZnVuY3Rpb25fcG9pbnRlcjwgZGVjbHR5cGUoICZUOjp0b19mb28gKSA+Ojp2YWx1ZSA+Ojp0eXBlID4gewogIHN0YXRpYyBjb25zdCBmb28gJiBjYWxsMSggY29uc3QgYmFyICYgYiApIHsKICAgIHJldHVybiBiLnRvX2ZvbygpOwogIH0KCiAgc3RhdGljIGZvbyAmIGNhbGwyKCBiYXIgJiBiICkgewogICAgcmV0dXJuIGIudG9fZm9vKCk7CiAgfQp9OwoKaW50IG1haW4oKSB7CiAgYmFyIGI7CiAgZm9vICYgZiA9IGNvbnZlcnQ8YmFyPjo6Y2FsbDIoIGIgKTsKICByZXR1cm4gMDsKfQ==