fork(1) download
  1. #include<type_traits>
  2.  
  3. namespace detail
  4. {
  5. enum enabler {};
  6. }
  7.  
  8. template <int overload, typename Condition>
  9. using EnableIf = std::enable_if_t<Condition::value, detail::enabler>;
  10.  
  11. template <typename T,
  12. EnableIf<0, std::is_same<T, int>>...>
  13. T twice(T t) { return 2 * t; }
  14.  
  15. template <typename T,
  16. EnableIf<0, std::is_same<T, float>>...>
  17. T twice(T t) { return 2 * t; }
  18.  
  19. int main()
  20. {
  21. twice(1);
  22. twice(1.f);
  23. return 0;
  24. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty