fork download
  1. #include <type_traits>
  2. #include <iostream>
  3.  
  4. struct my_abstract_class { virtual int x() = 0; };
  5. struct my_incomplete_class;
  6.  
  7. template<typename T, typename = void>
  8. struct can_be_returned_from_function: std::false_type { };
  9.  
  10. template<typename T>
  11. struct can_be_returned_from_function<T,
  12. typename std::enable_if<!std::is_abstract<T>::value,
  13. decltype(std::declval<T()>(), (void)0)>::type>
  14. : std::true_type { };
  15.  
  16.  
  17. int main()
  18. {
  19. ::std::cout
  20. << can_be_returned_from_function<int>::value << ::std::endl
  21. << can_be_returned_from_function<int[]>::value << ::std::endl
  22. << can_be_returned_from_function<int[2]>::value << ::std::endl
  23. << can_be_returned_from_function<int()>::value << ::std::endl
  24. << can_be_returned_from_function<my_abstract_class>::value << ::std::endl
  25. << can_be_returned_from_function<my_incomplete_class>::value << ::std::endl
  26. ;
  27. return 0;
  28. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from prog.cpp:1:0:
/usr/include/c++/4.7/type_traits: In instantiation of ‘struct std::is_abstract<my_incomplete_class>’:
prog.cpp:25:62:   required from here
/usr/include/c++/4.7/type_traits:536:12: error: invalid use of incomplete type ‘struct my_incomplete_class’
prog.cpp:5:8: error: forward declaration of ‘struct my_incomplete_class’
stdout
Standard output is empty