lundi 6 mars 2023

template struct declared twice for checking method existence

I am trying to understand that block of code found in an answer of this question : template template class, call a function if it exists

template <typename T, typename = int>
struct HasReserve : std::false_type { };

template <typename T>
struct HasReserve <T, decltype(&T::reserve, 0)> : std::true_type { };

The templated struct HasReserve is defined twice with different parameters. I guess, the second declaration is hidden due to SFINAE when T has no reserve method. But I do not understand how the compiler deals with this double declaration.

Aucun commentaire:

Enregistrer un commentaire