Since sizeof is a compile-time operator, that should be usable with
templates to select different code paths at compile time.
Thanks to Ben who gave me the idea, I have created a compile time solution:
template <int iclass VcSelectorClass
{
public:
static char Dummy[10];
static void DoStuff(void)
{
//put code for VC2005 RTM here
cout << "RTM" << endl;
}
};
template <class VcSelectorClass<4>
{
public:
static void DoStuff(void)
{
//put code for VC2005 SP1 here
cout << "SP1" << endl;
}
};
//typedef for making things automatic without forcing you to type too much
garbage
typedef VcSelectorClass<sizeof(&VcSelectorClass<0>::Dummy) VcSelector;
int _tmain(int argc, _TCHAR* argv[])
{
//do stuff that depends on the compiler version.
VcSelector::DoStuff();
return 0;
}
It won't look quite the same as preprocessor conditionals though.
Nope. It is slightly more verbose :-)
_CRT_ASSEMBLY_VERSION is also different between RTM and SP1, but that is a
string and not usable with preprocessor conditionals.
_CPPLIB_VER is an integer, but I don't know if that changed or not.
Anyway, the above solution is a good way to impress your coworkers with
black magic C++ incantations. Just be sure to document why you are doing this.
--
Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"