P
Patrick Kowalzick
Dear all,
I just wondered if it is possible to count the number of classes created via
a template class at compile time.
To show what I mean I post an example, which is not working but carries the
idea:
static int counter = 0; // this variable can be changed only at runtime...
template <typename T> struct want_to_be_counted;
{
static const int help_counting = counter++; // so this is always 0 (or
even better undefined?)
};
Each time when the compiler creates class with a new type, it shall
increment a variable.
want_to_be_counted< int > ----> counter = 1;
want_to_be_counted< float > ----> counter = 2;
want_to_be_counted< int > ----> counter = still 2;
Any ideas or hints where to read? Thank you,
Patrick
I just wondered if it is possible to count the number of classes created via
a template class at compile time.
To show what I mean I post an example, which is not working but carries the
idea:
static int counter = 0; // this variable can be changed only at runtime...
template <typename T> struct want_to_be_counted;
{
static const int help_counting = counter++; // so this is always 0 (or
even better undefined?)
};
Each time when the compiler creates class with a new type, it shall
increment a variable.
want_to_be_counted< int > ----> counter = 1;
want_to_be_counted< float > ----> counter = 2;
want_to_be_counted< int > ----> counter = still 2;
Any ideas or hints where to read? Thank you,
Patrick