I want to use std::enable_if
to make constructor that matches numbers. I tried the following code, but the constructor is not found. Main function has examples how I want to use this. What should I change to make this work?
#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;
}
Error on Ideone: template argument deduction/substitution failed
Aucun commentaire:
Enregistrer un commentaire