fork(37) download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template <typename T>
  5. struct A {
  6. int val = 0;
  7.  
  8. template<typename Integer
  9. ,typename = typename std::enable_if<T::value && sizeof(Integer)>::type
  10. >
  11. A(Integer n) : val(n) {};
  12.  
  13. A(...) {}
  14. /* ... */
  15. };
  16.  
  17. struct YES { constexpr static bool value = true; };
  18. struct NO { constexpr static bool value = false; };
  19.  
  20. int main() {
  21. A<YES> y(10);
  22. A<NO> n;
  23. std::cout << "YES: " << y.val << std::endl
  24. << "NO: " << n.val << std::endl;
  25. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
YES: 10
NO:  0