fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. class Foo
  5. {
  6. public:
  7. template<typename DT, typename = std::enable_if_t<!std::is_pointer<std::decay_t<DT>>::value>>
  8. Foo(const DT& newValue)
  9. {
  10. std::cout<<"In const DT& version"<<std::endl;
  11. }
  12.  
  13. template<typename DT>
  14. Foo(const DT* newValue)
  15. {
  16. std::cout<<"In const DT* version"<<std::endl;
  17. }
  18. };
  19.  
  20. int main()
  21. {
  22. int i=7;
  23.  
  24. Foo f1(i);
  25. Foo f2(&i);
  26.  
  27. const int i_const = 7;
  28. Foo f3(i_const);
  29. Foo f4(&i_const);
  30.  
  31. int arr[5];
  32. Foo f5(arr);
  33. Foo f6(&arr);
  34. }
Success #stdin #stdout 0s 4524KB
stdin
Standard input is empty
stdout
In const DT& version
In const DT* version
In const DT& version
In const DT* version
In const DT* version
In const DT* version