fork download
  1. #include <type_traits>
  2. #include <typeinfo>
  3. #include <iostream>
  4. #include <functional>
  5. using namespace std;
  6.  
  7. template<typename T> void test(){
  8. cout<<typeid(typename function<T>::result_type).name()<<endl; //works
  9. cout<<typeid(typename std::result_of<T>::type).name()<<endl; //compile-time error here.
  10. }
  11.  
  12. template<typename T, typename std::enable_if< std::is_pointer<T>::value&&std::is_function<typename std::remove_pointer<T>::type>::value, int >::type =0>
  13. void push(T val){
  14. test<typename std::remove_pointer<T>::type>();
  15. }
  16.  
  17. int main(){
  18. push(main);
  19. }
  20.  
  21.  
  22.  
  23. Error is:
  24.  
  25. g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
  26. In file included from ../main.cpp:1:0:
  27. /usr/include/c++/4.6/type_traits: In instantiation of ‘std::_Result_of_impl<false, false, int>:
  28. /usr/include/c++/4.6/type_traits:1215:12: instantiated from ‘std::result_of<int()>
  29. ../main.cpp:9:2: instantiated from ‘void test() [with T = int()]
  30. ../main.cpp:14:2: instantiated from ‘void push(T) [with T = int (*)(), typename std::enable_if<(std::is_pointer<_Functor>::value && std::is_function<typename std::remove_pointer<_Functor>::type>::value), int>::type <anonymous> = 0]
  31. ../main.cpp:18:11: instantiated from here
  32. /usr/include/c++/4.6/type_traits:1192:9: error: ‘std::declval [with _Tp = int, typename std::add_rvalue_reference<_Tp>::type = int&&]()’ cannot be used as a function
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:25:49: error: invalid suffix "x" on integer constant
prog.cpp:27:1: error: stray '\342' in program
prog.cpp:27:1: error: stray '\200' in program
prog.cpp:27:1: error: stray '\230' in program
prog.cpp:27:1: error: stray '\342' in program
prog.cpp:27:1: error: stray '\200' in program
prog.cpp:27:1: error: stray '\231' in program
prog.cpp:28:1: error: stray '\342' in program
prog.cpp:28:1: error: stray '\200' in program
prog.cpp:28:1: error: stray '\230' in program
prog.cpp:28:1: error: stray '\342' in program
prog.cpp:28:1: error: stray '\200' in program
prog.cpp:28:1: error: stray '\231' in program
prog.cpp:29:1: error: stray '\342' in program
prog.cpp:29:1: error: stray '\200' in program
prog.cpp:29:1: error: stray '\230' in program
prog.cpp:29:1: error: stray '\342' in program
prog.cpp:29:1: error: stray '\200' in program
prog.cpp:29:1: error: stray '\231' in program
prog.cpp:30:1: error: stray '\342' in program
prog.cpp:30:1: error: stray '\200' in program
prog.cpp:30:1: error: stray '\230' in program
prog.cpp:30:1: error: stray '\342' in program
prog.cpp:30:1: error: stray '\200' in program
prog.cpp:30:1: error: stray '\231' in program
prog.cpp:32:1: error: stray '\342' in program
prog.cpp:32:1: error: stray '\200' in program
prog.cpp:32:1: error: stray '\230' in program
prog.cpp:32:1: error: stray '\342' in program
prog.cpp:32:1: error: stray '\200' in program
prog.cpp:32:1: error: stray '\231' in program
prog.cpp:23:1: error: 'Error' does not name a type
In file included from prog.cpp:4:0:
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/functional: In instantiation of 'std::result_of<int()>':
prog.cpp:9:2:   instantiated from 'void test() [with T = int()]'
prog.cpp:14:2:   instantiated from 'void push(T) [with T = int (*)(), typename std::enable_if<(std::is_pointer<_Tp>::value && std::is_function<typename std::remove_pointer<_Tp>::type>::value), int>::type <anonymous> = 0]'
prog.cpp:18:11:   instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/functional:180:9: error: 'std::declval [with _Tp = int, typename std::add_rvalue_reference<_Tp>::type = int&&]()' cannot be used as a function
stdout
Standard output is empty