Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <utility>
- namespace FunctionTraits
- {
- template<typename T>
- struct Type {
- using type = T;
- };
- template<typename T>
- struct FunctionType;
- template<typename T>
- struct FunctionType<T(*)()>
- {
- using ReturnType = T;
- using ParameterType = void;
- using Signature = ReturnType();
- };
- template<typename T, typename P>
- struct FunctionType<T (*)( P )>
- {
- using ReturnType = T;
- using ParameterType = P;
- using Signature = typename Type<ReturnType( ParameterType )>::type;
- };
- template<typename T, typename P>
- struct FunctionType<T(*)( P... )>
- {
- using ReturnType = T;
- using ParameterType = P;
- using Signature = typename Type<ReturnType( ParameterType... )>::type;
- };
- template<typename T, typename ...U>
- auto apply_impl( typename FunctionType<T>::Signature && function, U && ...args ) -> decltype( function ( std::forward<U...>( args...)) ){
- return function( std::forward<U...>( args... ));
- }
- template<typename T, typename ...U>
- auto apply( T && a, U &&...args ) -> decltype ( apply_impl( std::forward<T>( a ), std::forward<U...>( args... ) ) ){
- using tag = typename FunctionType<T>::Signature;
- return apply_impl( std::forward<T>( a ), std::forward<U...>( args... ) );
- }
- template<class T, class ...U>
- using tag = typename FunctionTraits::FunctionType<T(U...)>::Signature;
- }
- int foo ( int a ){
- return a;
- }
- int main()
- {
- using FunctionTraits::tag;
- auto bar = []( tag , tag ) ->void { return; };
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement