fork(131) download
  1. // in the normal case, just the identity
  2. template<class T>
  3. struct item_return{ typedef T type; };
  4.  
  5. template<class T>
  6. typename item_return<T>::type foo(){ return T(); }
  7.  
  8. template<>
  9. struct item_return<float>{ typedef int type; };
  10.  
  11. template<>
  12. int foo<float>(){ return 42; }
  13.  
  14. // might want to stick to the following
  15. // so you only need to update the return-type in one place
  16. // namely, the `item_return` specialization
  17. //template<>
  18. //item_return<float>::type foo<float>(){ ... }
  19. // note: No `typename` needed, because `float` is not a dependent type
  20.  
  21. int main(){
  22. }
Success #stdin #stdout 0s 2848KB
stdin
Standard input is empty
stdout
Standard output is empty