fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3. #include <cassert>
  4.  
  5. int main() {
  6. auto foo = [](auto x, auto y) -> decltype(x) {
  7. return x + y;
  8. };
  9.  
  10. if(typeid(foo(2, 3.14f)) == typeid(int)) {
  11. std::cout << "int" << std::endl; // GCC
  12. } else if(typeid(foo(2, 3.14f)) == typeid(float)) {
  13. std::cout << "float" << std::endl; // VS2015
  14. }
  15.  
  16. assert(typeid(foo(2, 3.14f)) == typeid(int)); // this fails on VS2015
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
int