#include <iostream>
#include <functional>
class VoidType{
public :
template < class ...Arge >
virtual int operator( ) ( Arge ...Arges ) { return 0 ; } //戻り型がチープ。継承先の戻り型を設定したい。
} ;
template < class F>
class AnyFunction: VoidType{
std:: function < F> Fun;
public :
AnyFunction( std:: function < F> F) {
Fun = F;
}
AnyFunction( ) = delete ;
template < class ...Arge >
typename std:: function < F> :: result_type operator ( ) ( Arge ...Arges ) {
return Fun( Arges...) ;
}
} ;
int main( ) {
AnyFunction< int ( int ) > F( [ ] ( int N) - > int { std:: cout << N << std:: endl ; return N; } ) ;
VoidType& Fn = F;
int R = Fn( 10 ) ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KCmNsYXNzIFZvaWRUeXBlewoKcHVibGljOgoJdGVtcGxhdGU8Y2xhc3MgLi4uQXJnZT4KCXZpcnR1YWwgaW50IG9wZXJhdG9yKCkoQXJnZSAuLi5Bcmdlcyl7cmV0dXJuIDA7IH0vL+aIu+OCiuWei+OBjOODgeODvOODl+OAgue2meaJv+WFiOOBruaIu+OCiuWei+OCkuioreWumuOBl+OBn+OBhOOAggp9OwoKCnRlbXBsYXRlPGNsYXNzIEY+CmNsYXNzIEFueUZ1bmN0aW9uOlZvaWRUeXBlewoJc3RkOjpmdW5jdGlvbjxGPiBGdW47CgpwdWJsaWM6CglBbnlGdW5jdGlvbihzdGQ6OmZ1bmN0aW9uPEY+IEYpewoJCUZ1biA9IEY7Cgl9CglBbnlGdW5jdGlvbigpID0gZGVsZXRlOwoKCXRlbXBsYXRlPGNsYXNzIC4uLkFyZ2U+Cgl0eXBlbmFtZSBzdGQ6OmZ1bmN0aW9uPEY+OjpyZXN1bHRfdHlwZSBvcGVyYXRvciAoKShBcmdlIC4uLkFyZ2VzKXsKCQlyZXR1cm4gRnVuKEFyZ2VzLi4uKTsKCX0KfTsKCmludCBtYWluKCl7CglBbnlGdW5jdGlvbjxpbnQoaW50KT4gRihbXShpbnQgTiktPmludHtzdGQ6OmNvdXQgPDwgTiA8PCBzdGQ6OmVuZGw7IHJldHVybiBOOyB9KTsKCVZvaWRUeXBlJiBGbiA9IEY7CglpbnQgUiA9IEZuKDEwKTsKCgoJcmV0dXJuIDA7Cn0=
compilation info
prog.cpp:8:2: error: templates may not be ‘virtual’
virtual int operator()(Arge ...Arges){return 0; }//戻り型がチープ。継承先の戻り型を設定したい。
^
prog.cpp:8: confused by earlier errors, bailing out
Preprocessed source stored into /home/GDRMha/cciVKy2q.out file, please attach this to your bugreport.
stdout