#include <type_traits>
#include <string>
class A {
public:
A(const std::wstring&, const std::wstring&)
{}
template<typename T>
A(const std::wstring& n, typename std::enable_if<std::is_arithmetic<T>::value, T>::type v)
{}
};
int main() {
A(L"n", 1234); // does not compile
A(L"n", 2.7); // does not compile
A(L"n", L"n"); // compiles
return 0;
}
I2luY2x1ZGUgPHR5cGVfdHJhaXRzPgojaW5jbHVkZSA8c3RyaW5nPgoKY2xhc3MgQSB7CnB1YmxpYzoKCUEoY29uc3Qgc3RkOjp3c3RyaW5nJiwgY29uc3Qgc3RkOjp3c3RyaW5nJikKCXt9CgkKCXRlbXBsYXRlPHR5cGVuYW1lIFQ+CglBKGNvbnN0IHN0ZDo6d3N0cmluZyYgbiwgdHlwZW5hbWUgc3RkOjplbmFibGVfaWY8c3RkOjppc19hcml0aG1ldGljPFQ+Ojp2YWx1ZSwgVD46OnR5cGUgdikKCXt9Cn07CgppbnQgbWFpbigpIHsKCUEoTCJuIiwgMTIzNCk7IC8vIGRvZXMgbm90IGNvbXBpbGUKCUEoTCJuIiwgMi43KTsgLy8gZG9lcyBub3QgY29tcGlsZQoJQShMIm4iLCBMIm4iKTsgLy8gY29tcGlsZXMKCXJldHVybiAwOwp9
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