fork download
  1. #include<iostream>
  2. #include <type_traits>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. template <class TO, class FROM>
  8. typename enable_if<!is_pointer<FROM>::value, TO>::type
  9. punning_cast(const FROM &input) {
  10. cout << "reference version" << endl;
  11. }
  12.  
  13. template <class TO, class FROM>
  14. typename enable_if<is_pointer<FROM>::value, TO>::type
  15. punning_cast(const FROM input) {
  16. cout << "pointer version" << endl;
  17. }
  18.  
  19. int main()
  20. {
  21. int k(0);
  22. int *p = &k;
  23.  
  24. punning_cast<void>(k);
  25. punning_cast<void>(p);
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
reference version
pointer version