fork download
  1. #include <type_traits>
  2.  
  3. template<typename U>
  4. struct Explicit
  5. {
  6. bool value;
  7. template<typename T = U, typename = std::enable_if_t<std::is_same<std::decay_t<T>, U>::value>>
  8. Explicit(T&& value) : value(value) { }
  9. operator U() { return value; }
  10. };
  11.  
  12.  
  13. void Foo(Explicit<bool> arg1 = false, int arg2 = 10, int arg3 = 20) { }
  14.  
  15. int main(int argc, char ** argv)
  16. {
  17. int x = 40, y = 50;
  18. Foo();
  19. Foo(true, x, y);
  20. Foo((bool)x, y);
  21. Foo(x, y);
  22. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main(int, char**)':
prog.cpp:21:10: error: could not convert 'x' from 'int' to 'Explicit<bool>'
  Foo(x, y);
          ^
stdout
Standard output is empty