I'm trying to write some class templates to ascertain whether a given
class defines a given member type.
I have been using SFINAE and the "sizeof trick" to do so and, in
general, all works well. The code snippet, below, demonstrates my
problem however. The test fails when I try and ascertain whether the
class defines a "reference" member type because I cannot declare a
pointer to a reference. Uncommenting the penultimate line of code
will result in the compiler telling me just that. Fair enough and
understood.
My question is simply "how should I proceed"?
Kind regards,
Angus
#include <iostream>
#include <vector>
typedef char One;
typedef struct { char a[2]; } Two;
template <typename T>
One has_value_type(typename T::value_type const *);
template <typename T>
Two has_value_type(...);
template <typename T>
One has_reference(typename T::reference const *);
template <typename T>
Two has_reference(...);
int main()
{
typedef std::vector<int> IntVec;
std::cout << "IntVec has value_type? "
<< (sizeof(has_value_type<IntVec>(0)) == 1)
<< std::endl;
std::cout << "IntVec has reference? "
<< (sizeof(has_reference<IntVec>(0)) == 1)
<< std::endl;
//has_value_type<IntVec>((IntVec::reference const *)0);
return 0;
}