I have a template function that is enabled (through a std::enable_if) its parameter is a raw pointer, or has a std::iterator category or is a std::nullptr_t. In that function, a raw pointer (a data member) is set equal to the parameter, like that :
template<class T> void myFunction(T it)
{
_ptr = &*it;
}
The &* works well for pointer and iterator … but it fails for a std::nullptr_t. Is there any solution available to avoid to write 2 different functions ?
Thank you.
The simplest thing is to change the function to have two overloads, one for raw pointers/
nullptr_tthat just stores the value and one selected by SFINAE for iterators with your current implementation, although you should note that this will fail under some circumstances (in particular ifiterator::value_typeoverloads unaryoperator&).