template<typename T>
struct identity {};
template<unsigned N>
struct unsigned_ { enum { value = N }; };
template<typename T>
char (&extract_unsigned_value(T))[1 + T::value];
struct detail //важно
{
template<typename T>
struct return_type
{
typedef unsigned_<1 + sizeof(extract_unsigned_value(star_count(identity<T>()))) - 1> type;
};
template<typename T>
static unsigned_<0> star_count(identity<T>);
template<typename T>
static typename return_type<T>::type star_count(identity<T*>);
};
template<typename T>
struct star_count
{
enum
{
value = sizeof(extract_unsigned_value(detail::star_count(identity<T>()))) - 1
};
};
int main()
{
char _[star_count<int >::value == 0];
char a[star_count<int *>::value == 1];
char b[star_count<int **>::value == 2];
char c[star_count<int ***>::value == 3];
char d[star_count<int ****>::value == 4];
char e[star_count<int *****>::value == 5];
char f[star_count<int ******>::value == 6];
char g[star_count<int *******>::value == 7];
char h[star_count<int ********>::value == 8];
char j[star_count<int *********>::value == 9];
char k[star_count<int **********>::value == 10];
char l[star_count<int ***********>::value == 11];
char m[star_count<int ************>::value == 12];
char n[star_count<int *************>::value == 13];
char o[star_count<int **************>::value == 14];
char p[star_count<int ***************>::value == 15];
//итд
} |