lundi 30 mars 2020

std:: add_pointer, what the try_add_pointer for in the possible implementation?

In cppreference add_pointer, it is said we may implement it as:

namespace detail {

template <class T>
struct type_identity { using type = T; }; // or use std::type_identity (since C++20)

template <class T>
auto try_add_pointer(int) -> type_identity<typename std::remove_reference<T>::type*>;
template <class T>
auto try_add_pointer(...) -> type_identity<T>;

} // namespace detail

template <class T>
struct add_pointer : decltype(detail::try_add_pointer<T>(0)) {};

My question is what is the try_add_pointer for? I know it is SFINAE. But why the implementation need it here?

Aucun commentaire:

Enregistrer un commentaire