4 ms·
Ah yes, using a typedef would work too, nice. It for sure not quite the same as C++ templates, but if you can tolerate crazy things you can do a lot with the p
by 1wd 10y ago
Ah yes, using a typedef would work too, nice.
It for sure not quite the same as C++ templates, but if you can tolerate crazy things you can do a lot with the preprocessor. See http://www.boost.org/libs/preprocessor/ http://www.boost.org/libs/preprocessor/ (supports both C++ and C).
If you have foo_template.h:
#define FOO_T CONCAT(CONCAT(foo_,X),_t)
struct FOO_T { /* ... */ };
and bar_template.h:
#define X Y/2
#include "foo_template.h"
#define BAT_T CONCAT(CONCAT(bar_,Y),_t)
struct BAR_T {
FOO_T foo;
};
It might almost work, but you'd need to pull out some more tricks I'm sure. Maybe BOOST_PP_DIV(Y,2) would help. In practice I'd prefer something sane. :)