Is there an idiom for a strict typedef in C ++, possibly using templates?
Something like:
template <class base_type, int N> struct new_type{ base_type p; explicit new_type(base_type i = base_type()) : p(i) {} }; typedef new_type<int, __LINE__> x_coordinate; typedef new_type<int, __LINE__> y_coordinate;
Therefore, I can make something like a compile-time error:
x_coordinate x(5); y_coordinate y(6); x = y;
__LINE__ looks like this might be a problem, but I would prefer not to manually create a set of constants so that each type is unique.
c ++ idioms types templates
zounds
source share