I honestly can't explain what's going on with the preprocessor there, but it seems that the problem also occurs on comeau tryitout too. However, I wonder if this would be suitable as a workaround
Code:
template <typename destT>
struct type_wrapper
{
typedef destT type;
};
template<class destT>
typename destT::type GetSiteSetting(client& cli, const destT&, const std::string& name)
{
try
{
return boost::lexical_cast<typename destT::type>(cli.GetSiteRef()[name]);
}
catch (boost::bad_lexical_cast& ex)
{
return typename destT::type();
}
}
#define GET_SITE_SETTING(TYPE, NAME) TYPE NAME = GetSiteSetting(cli, type_wrapper<TYPE>(), #NAME)
By wrapping your unsigned long into type_wrapper<>, you are avoiding the issue with having a type containing the qualifier. I can't quite see what the preprocessor doesn't like about them however. (But I do trust comeau to have implemented it correctly; no doubt there is some subtle parsing rule in the C or C++ standards responsible here)
edit - I didn't check the above code in comeau, since it doesn't know about boost::lexical_cast, however I did test this code in comeau and it seemed happy
Code:
#include <string>
template <typename destT>
struct type_wrapper
{
typedef destT type;
};
template<class destT>
typename destT::type GetSiteSetting(const destT&, const std::string& name)
{
return (typename destT::type());
}
#define GET_SITE_SETTING(TYPE, NAME) TYPE NAME = GetSiteSetting(type_wrapper<TYPE>(), #NAME)
int main()
{
GET_SITE_SETTING(unsigned long, foo);
}