Re: sizeof
Jeremy <mutexed@gmail.com> wrote:
I wanted to use it to count the number of arguments represented by
__VA_ARGS__ in a macro, knowing they were a specific type.
If you are happy to limit yourself to some fixed maximum number, you
could do something like this:
namespace detail {
template <typename T1>
char (&size_calculator(T1))[1];
template <typename T1, typename T2>
char (&size_calculator(T1, T2))[2];
template <typename T1, typename T2, typename T3>
char (&size_calculator(T1, T2, T3))[3];
// Follow the pattern up to a desired maximum.
// You don't need to implement these functions, just declare them.
}
#define ArgCount(...) sizeof(detail::size_calculator(__VA_ARGS__))
If you only need to count ints, then size_calculator doesn't need to be
a template.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925