More robust CMS_TEMPLATE implementation