我已经使用艰苦的工作和其他几个线程,例如:获取 lambda 参数类型
这里是:
namespace details{
template<class FPtr> struct function_traits;
template<class RT, class CT >struct function_traits<RT (CT::*)( ) >{ typedef RT Result; typedef RT (CT::*Signature)( );};
template<class RT, class CT >struct function_traits<RT (CT::*)( )const>{ typedef RT Result; typedef RT (CT::*Signature)( );};
template<class RT >struct function_traits<RT ( ) >{ typedef RT Result; typedef RT Signature ( );};
template<class RT, class CT, class P1T >struct function_traits<RT (CT::*)(P1T ) >{ typedef RT Result; typedef P1T Param1; typedef RT (CT::*Signature)(P1T );};
template<class RT, class CT, class P1T >struct function_traits<RT (CT::*)(P1T )const>{ typedef RT Result; typedef P1T Param1; typedef RT (CT::*Signature)(P1T );};
template<class RT , class P1T >struct function_traits<RT (P1T ) >{ typedef RT Result; typedef P1T Param1; typedef RT Signature (P1T );};
template<class RT, class CT, class P1T, class P2T >struct function_traits<RT (CT::*)(P1T, P2T ) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef RT (CT::*Signature)(P1T, P2T );};
template<class RT, class CT, class P1T, class P2T >struct function_traits<RT (CT::*)(P1T, P2T )const>{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef RT (CT::*Signature)(P1T, P2T );};
template<class RT , class P1T, class P2T >struct function_traits<RT (P1T, P2T ) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef RT Signature (P1T, P2T );};
template<class RT, class CT, class P1T, class P2T, class P3T >struct function_traits<RT (CT::*)(P1T, P2T, P3T ) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef RT (CT::*Signature)(P1T, P2T, P3T );};
template<class RT, class CT, class P1T, class P2T, class P3T >struct function_traits<RT (CT::*)(P1T, P2T, P3T )const>{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef RT (CT::*Signature)(P1T, P2T, P3T );};
template<class RT , class P1T, class P2T, class P3T >struct function_traits<RT (P1T, P2T, P3T ) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef RT Signature (P1T, P2T, P3T );};
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T >struct function_traits<RT (CT::*)(P1T, P2T, P3T, P4T ) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef RT (CT::*Signature)(P1T, P2T, P3T, P4T );};
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T >struct function_traits<RT (CT::*)(P1T, P2T, P3T, P4T )const>{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef RT (CT::*Signature)(P1T, P2T, P3T, P4T );};
template<class RT , class P1T, class P2T, class P3T, class P4T >struct function_traits<RT (P1T, P2T, P3T, P4T ) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef RT Signature (P1T, P2T, P3T, P4T );};
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T >struct function_traits<RT (CT::*)(P1T, P2T, P3T, P4T, P5T ) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef P5T Param5; typedef RT (CT::*Signature)(P1T, P2T, P3T, P4T, P5T );};
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T >struct function_traits<RT (CT::*)(P1T, P2T, P3T, P4T, P5T )const>{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef P5T Param5; typedef RT (CT::*Signature)(P1T, P2T, P3T, P4T, P5T );};
template<class RT , class P1T, class P2T, class P3T, class P4T, class P5T >struct function_traits<RT (P1T, P2T, P3T, P4T, P5T ) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef P5T Param5; typedef RT Signature (P1T, P2T, P3T, P4T, P5T );};
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T, class P6T >struct function_traits<RT (CT::*)(P1T, P2T, P3T, P4T, P5T, P6T ) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef P5T Param5; typedef P6T Param6; typedef RT (CT::*Signature)(P1T, P2T, P3T, P4T, P5T, P6T );};
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T, class P6T >struct function_traits<RT (CT::*)(P1T, P2T, P3T, P4T, P5T, P6T )const>{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef P5T Param5; typedef P6T Param6; typedef RT (CT::*Signature)(P1T, P2T, P3T, P4T, P5T, P6T );};
template<class RT , class P1T, class P2T, class P3T, class P4T, class P5T, class P6T >struct function_traits<RT (P1T, P2T, P3T, P4T, P5T, P6T ) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef P5T Param5; typedef P6T Param6; typedef RT Signature (P1T, P2T, P3T, P4T, P5T, P6T );};
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T, class P6T, class P7T >struct function_traits<RT (CT::*)(P1T, P2T, P3T, P4T, P5T, P6T, P7T ) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef P5T Param5; typedef P6T Param6; typedef P7T Param7; typedef RT (CT::*Signature)(P1T, P2T, P3T, P4T, P5T, P6T, P7T );};
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T, class P6T, class P7T >struct function_traits<RT (CT::*)(P1T, P2T, P3T, P4T, P5T, P6T, P7T )const>{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef P5T Param5; typedef P6T Param6; typedef P7T Param7; typedef RT (CT::*Signature)(P1T, P2T, P3T, P4T, P5T, P6T, P7T );};
template<class RT , class P1T, class P2T, class P3T, class P4T, class P5T, class P6T, class P7T >struct function_traits<RT (P1T, P2T, P3T, P4T, P5T, P6T, P7T ) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef P5T Param5; typedef P6T Param6; typedef P7T Param7; typedef RT Signature (P1T, P2T, P3T, P4T, P5T, P6T, P7T );};
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T, class P6T, class P7T, class P8T>struct function_traits<RT (CT::*)(P1T, P2T, P3T, P4T, P5T, P6T, P7T, P8T) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef P5T Param5; typedef P6T Param6; typedef P7T Param7; typedef P8T Param8; typedef RT (CT::*Signature)(P1T, P2T, P3T, P4T, P5T, P6T, P7T, P8T);};
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T, class P6T, class P7T, class P8T>struct function_traits<RT (CT::*)(P1T, P2T, P3T, P4T, P5T, P6T, P7T, P8T)const>{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef P5T Param5; typedef P6T Param6; typedef P7T Param7; typedef P8T Param8; typedef RT (CT::*Signature)(P1T, P2T, P3T, P4T, P5T, P6T, P7T, P8T);};
template<class RT , class P1T, class P2T, class P3T, class P4T, class P5T, class P6T, class P7T, class P8T>struct function_traits<RT (P1T, P2T, P3T, P4T, P5T, P6T, P7T, P8T) >{ typedef RT Result; typedef P1T Param1; typedef P2T Param2; typedef P3T Param3; typedef P4T Param4; typedef P5T Param5; typedef P6T Param6; typedef P7T Param7; typedef P8T Param8; typedef RT Signature (P1T, P2T, P3T, P4T, P5T, P6T, P7T, P8T);};
template<class T>
typename function_traits<T>::Signature* bar_helper(T);
template<class F>
class FuncTraitsOf{
public:
typedef decltype(bar_helper(&F::operator())) fptr;
typedef typename std::remove_pointer<fptr>::type Signature; //Signature = bool __cdecl(int,float)
typedef typename function_traits< Signature > R; //R = struct function_traits<bool __cdecl(int,float)>
};
template< class FuncTraits>class FDSel;
template<class RT, class CT > struct FDSel< function_traits< RT (CT::*)( ) > >{ typedef fastdelegate::FastDelegate0< RT> R; };
template<class RT, class CT > struct FDSel< function_traits< RT (CT::*)( )const > >{ typedef fastdelegate::FastDelegate0< RT> R; };
template<class RT > struct FDSel< function_traits< RT ( ) > >{ typedef fastdelegate::FastDelegate0< RT> R; };
template<class RT, class CT, class P1T > struct FDSel< function_traits< RT (CT::*)(P1T ) > >{ typedef fastdelegate::FastDelegate1<P1T ,RT> R; };
template<class RT, class CT, class P1T > struct FDSel< function_traits< RT (CT::*)(P1T )const > >{ typedef fastdelegate::FastDelegate1<P1T ,RT> R; };
template<class RT , class P1T > struct FDSel< function_traits< RT (P1T ) > >{ typedef fastdelegate::FastDelegate1<P1T ,RT> R; };
template<class RT, class CT, class P1T, class P2T > struct FDSel< function_traits< RT (CT::*)(P1T, P2T ) > >{ typedef fastdelegate::FastDelegate2<P1T, P2T ,RT> R; };
template<class RT, class CT, class P1T, class P2T > struct FDSel< function_traits< RT (CT::*)(P1T, P2T )const > >{ typedef fastdelegate::FastDelegate2<P1T, P2T ,RT> R; };
template<class RT , class P1T, class P2T > struct FDSel< function_traits< RT (P1T, P2T ) > >{ typedef fastdelegate::FastDelegate2<P1T, P2T ,RT> R; };
template<class RT, class CT, class P1T, class P2T, class P3T > struct FDSel< function_traits< RT (CT::*)(P1T, P2T, P3T ) > >{ typedef fastdelegate::FastDelegate3<P1T, P2T, P3T ,RT> R; };
template<class RT, class CT, class P1T, class P2T, class P3T > struct FDSel< function_traits< RT (CT::*)(P1T, P2T, P3T )const > >{ typedef fastdelegate::FastDelegate3<P1T, P2T, P3T ,RT> R; };
template<class RT , class P1T, class P2T, class P3T > struct FDSel< function_traits< RT (P1T, P2T, P3T ) > >{ typedef fastdelegate::FastDelegate3<P1T, P2T, P3T ,RT> R; };
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T > struct FDSel< function_traits< RT (CT::*)(P1T, P2T, P3T, P4T ) > >{ typedef fastdelegate::FastDelegate4<P1T, P2T, P3T, P4T ,RT> R; };
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T > struct FDSel< function_traits< RT (CT::*)(P1T, P2T, P3T, P4T )const > >{ typedef fastdelegate::FastDelegate4<P1T, P2T, P3T, P4T ,RT> R; };
template<class RT , class P1T, class P2T, class P3T, class P4T > struct FDSel< function_traits< RT (P1T, P2T, P3T, P4T ) > >{ typedef fastdelegate::FastDelegate4<P1T, P2T, P3T, P4T ,RT> R; };
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T > struct FDSel< function_traits< RT (CT::*)(P1T, P2T, P3T, P4T, P5T ) > >{ typedef fastdelegate::FastDelegate5<P1T, P2T, P3T, P4T, P5T ,RT> R; };
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T > struct FDSel< function_traits< RT (CT::*)(P1T, P2T, P3T, P4T, P5T )const > >{ typedef fastdelegate::FastDelegate5<P1T, P2T, P3T, P4T, P5T ,RT> R; };
template<class RT , class P1T, class P2T, class P3T, class P4T, class P5T > struct FDSel< function_traits< RT (P1T, P2T, P3T, P4T, P5T ) > >{ typedef fastdelegate::FastDelegate5<P1T, P2T, P3T, P4T, P5T ,RT> R; };
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T, class P6T > struct FDSel< function_traits< RT (CT::*)(P1T, P2T, P3T, P4T, P5T, P6T ) > >{ typedef fastdelegate::FastDelegate6<P1T, P2T, P3T, P4T, P5T, P6T ,RT> R; };
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T, class P6T > struct FDSel< function_traits< RT (CT::*)(P1T, P2T, P3T, P4T, P5T, P6T )const > >{ typedef fastdelegate::FastDelegate6<P1T, P2T, P3T, P4T, P5T, P6T ,RT> R; };
template<class RT , class P1T, class P2T, class P3T, class P4T, class P5T, class P6T > struct FDSel< function_traits< RT (P1T, P2T, P3T, P4T, P5T, P6T ) > >{ typedef fastdelegate::FastDelegate6<P1T, P2T, P3T, P4T, P5T, P6T ,RT> R; };
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T, class P6T, class P7T > struct FDSel< function_traits< RT (CT::*)(P1T, P2T, P3T, P4T, P5T, P6T, P7T ) > >{ typedef fastdelegate::FastDelegate7<P1T, P2T, P3T, P4T, P5T, P6T, P7T ,RT> R; };
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T, class P6T, class P7T > struct FDSel< function_traits< RT (CT::*)(P1T, P2T, P3T, P4T, P5T, P6T, P7T )const > >{ typedef fastdelegate::FastDelegate7<P1T, P2T, P3T, P4T, P5T, P6T, P7T ,RT> R; };
template<class RT , class P1T, class P2T, class P3T, class P4T, class P5T, class P6T, class P7T > struct FDSel< function_traits< RT (P1T, P2T, P3T, P4T, P5T, P6T, P7T ) > >{ typedef fastdelegate::FastDelegate7<P1T, P2T, P3T, P4T, P5T, P6T, P7T ,RT> R; };
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T, class P6T, class P7T, class P8T> struct FDSel< function_traits< RT (CT::*)(P1T, P2T, P3T, P4T, P5T, P6T, P7T, P8T) > >{ typedef fastdelegate::FastDelegate8<P1T, P2T, P3T, P4T, P5T, P6T, P7T, P8T,RT> R; };
template<class RT, class CT, class P1T, class P2T, class P3T, class P4T, class P5T, class P6T, class P7T, class P8T> struct FDSel< function_traits< RT (CT::*)(P1T, P2T, P3T, P4T, P5T, P6T, P7T, P8T)const > >{ typedef fastdelegate::FastDelegate8<P1T, P2T, P3T, P4T, P5T, P6T, P7T, P8T,RT> R; };
template<class RT , class P1T, class P2T, class P3T, class P4T, class P5T, class P6T, class P7T, class P8T> struct FDSel< function_traits< RT (P1T, P2T, P3T, P4T, P5T, P6T, P7T, P8T) > >{ typedef fastdelegate::FastDelegate8<P1T, P2T, P3T, P4T, P5T, P6T, P7T, P8T,RT> R; };
}
template<class F>
typename details::FDSel< typename details::FuncTraitsOf<F>::R >::R MakeDelegate(F& f){
return fastdelegate::MakeDelegate(&f, &F::operator());
}
将其复制/粘贴到您的 FastDelegate.h 文件中。
不要像这样使用它:
home.visit(fastdelegate::MakeDelegate([&](const Room& a){ /* ... */ }));
而是这样做:
auto d = [&](const Room& a){ /* ... */ };
home.visit(fastdelegate::MakeDelegate(d));
如果我错过了什么,请告诉我。