Say I have a macro, FOO(name), and some template class Bar<> that takes one parameter (what type of parameter is the question). Everytime I call FOO with a different name, I want to get a different instantiation of Bar. The Bar<> template doesn't actually need to be able to get at the name internally, I just need to be sure that different names create different instances of Bar<> and that using the same name (even in different translation units) always gets at the same instance of Bar<>. So here's a rough first attempt:
template<const char* x>
class Bar
{
//... stuff
};
#define FOO(name) Bar<#name>
This would work, except that char literals can't be passed as template parameters because they don't have external linkage. If there was someway in the preprocessor to get a consistent hash of 'name' to say, an int (which can then be passed to the template) that would work, but I don't see any way to do that.
Ideas?