I am trying to figure out how to get a C++ template to use a look-up table to perform its functions, but at compile time not run time. I am having trouble putting it into words, so here’s an example, and the ugly template + preprocessor macro combination that I have so far:
template<class T_POD, class T_Corba>
inline void c_to_corba_base(T_POD &In, CORBA::Any &Out) {
Out <<= static_cast<T_Corba>(In);
}
#define C_TO_CORBA_PAIR(T_POD, T_CORBA) \
inline void c_to_corba(T_POD &In, CORBA::Any &Out) { \
c_to_corba_base<T_POD, T_CORBA>(In, Out); \
}
C_TO_CORBA_PAIR(short, CORBA::Short)
C_TO_CORBA_PAIR(long, CORBA::Long)
C_TO_CORBA_PAIR(double, CORBA::Double)
// etc.
So you can see, it typecasts A to B to get C. C is always CORBA::Any. But B depends on A (known at compile time).
I’ve done some research and it looks like Boost::MPL::bind may do what I need (and we already require Boost) but I do not understand the syntax. It could have all been done in the macro, but I’d rather have it as “real” templates if it can be done.
Any suggestions?
Is this better?
I don’t think you’ll need that
typenamekeyword, becausestatic_castalways needs a type, but if you get an error that’ll probably be the fix.