fork(1) download
  1. #include <type_traits>
  2. #include <string>
  3.  
  4. class A {
  5. public:
  6. A(const std::wstring&, const std::wstring&)
  7. {}
  8.  
  9. template<typename T>
  10. A(const std::wstring& n, typename std::enable_if<std::is_arithmetic<T>::value, T>::type v)
  11. {}
  12. };
  13.  
  14. int main() {
  15. A(L"n", 1234); // does not compile
  16. A(L"n", 2.7); // does not compile
  17. A(L"n", L"n"); // compiles
  18. return 0;
  19. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:15:14: error: no matching function for call to ‘A::A(const wchar_t [2], int)’
  A(L"n", 1234); // does not compile
              ^
prog.cpp:10:2: note: candidate: template<class T> A::A(const wstring&, typename std::enable_if<std::is_arithmetic<_Tp>::value, T>::type)
  A(const std::wstring& n, typename std::enable_if<std::is_arithmetic<T>::value, T>::type v)
  ^
prog.cpp:10:2: note:   template argument deduction/substitution failed:
prog.cpp:15:14: note:   couldn't deduce template parameter ‘T’
  A(L"n", 1234); // does not compile
              ^
prog.cpp:6:2: note: candidate: A::A(const wstring&, const wstring&)
  A(const std::wstring&, const std::wstring&)
  ^
prog.cpp:6:2: note:   no known conversion for argument 2 from ‘int’ to ‘const wstring& {aka const std::__cxx11::basic_string<wchar_t>&}’
prog.cpp:4:7: note: candidate: constexpr A::A(const A&)
 class A {
       ^
prog.cpp:4:7: note:   candidate expects 1 argument, 2 provided
prog.cpp:4:7: note: candidate: constexpr A::A(A&&)
prog.cpp:4:7: note:   candidate expects 1 argument, 2 provided
prog.cpp:16:13: error: no matching function for call to ‘A::A(const wchar_t [2], double)’
  A(L"n", 2.7); // does not compile
             ^
prog.cpp:10:2: note: candidate: template<class T> A::A(const wstring&, typename std::enable_if<std::is_arithmetic<_Tp>::value, T>::type)
  A(const std::wstring& n, typename std::enable_if<std::is_arithmetic<T>::value, T>::type v)
  ^
prog.cpp:10:2: note:   template argument deduction/substitution failed:
prog.cpp:16:13: note:   couldn't deduce template parameter ‘T’
  A(L"n", 2.7); // does not compile
             ^
prog.cpp:6:2: note: candidate: A::A(const wstring&, const wstring&)
  A(const std::wstring&, const std::wstring&)
  ^
prog.cpp:6:2: note:   no known conversion for argument 2 from ‘double’ to ‘const wstring& {aka const std::__cxx11::basic_string<wchar_t>&}’
prog.cpp:4:7: note: candidate: constexpr A::A(const A&)
 class A {
       ^
prog.cpp:4:7: note:   candidate expects 1 argument, 2 provided
prog.cpp:4:7: note: candidate: constexpr A::A(A&&)
prog.cpp:4:7: note:   candidate expects 1 argument, 2 provided
stdout
Standard output is empty