Mam ten kod, mam nadzieję, że będą dwie różne wersje operatora ()
w zależności od typu parametru szablonu.Dlaczego tutaj nie działa opcja enable_if?
#include <string>
#include <type_traits>
template<typename T>
struct Impl
{
std::enable_if_t<!std::is_pointer<T>::value,T> operator()(const std::string& key, int node)
{
return static_cast<T>();
}
std::enable_if_t<std::is_pointer<T>::value,T> operator()(const std::string& key, int node)
{
return new T();
}
};
int main()
{
}
Zamiast tego pojawia się błąd kompilacji: 'std::enable_if_t<std::is_pointer<_Tp>::value, T> Impl<T>::operator()(const string&, int)' cannot be overloaded with 'std::enable_if_t<(! std::is_pointer<_Tp>::value), T> Impl<T>::operator()(const string&, int)'
Nit Pick: Czym jest 'static_cast();'? –
WhiZTiM
@ WhiZTiM [ftfy] (http://coliru.stacked-crooked.com/a/4418f30d119f86fe) –