Topic: generating unique template instantiations


Author: tmb@arolla.idiap.ch (Thomas M. Breuel)
Date: 22 Sep 1994 21:18:15 GMT
Raw View
When template classes are instantiated with the same arguments, the
resulting instances are compatible.  I was wondering whether there
is some way of forcing different instantiations of a template
class to generate different types.

The best I can come up with is a pre-processor macro that looks
something like:

 template <int *unique>
 class Int { ... }

 #define DEFINE_Int(N) \
  static int name2(N,_unique_); \
  typedef Int<&name2(N,_unique_)> N;

 DEFINE_Int(an_int);
 DEFINE_Int(another_int);

Is there a better way?

    Thanks,
     Thomas.