samedi 5 janvier 2019

Can nullptr be used as a type?

I was learning about the usage of enable_if and I stumbled upon the following code.

template <class T,
         typename std::enable_if<std::is_integral<T>::value,
                                 T>::type* = nullptr>
void do_stuff(T& t) {
  std::cout << "do_stuff integral\n";
    // an implementation for integral types (int, char, unsigned, etc.)
}

The thing that bothers me is that in the template parameter, nullptr is used as a default parameter to the std::enable_if<std::is_integral<T>::value, T>::type* which is also a type.

I am not sure how we can assign a literal to the type. Shouldn't it be nullptr_t instead?

Thanks

Aucun commentaire:

Enregistrer un commentaire