Listing 7

template<class ReflectedClass> struct AllAttributes
{
    enum {TotalNumAttributes = ReflectedClass::NumAttributes};
    template<int Pos> struct SingleAttributeHelper
    {
        template<class Function> static void 
        processSingleAttribute(ReflectedClass& recordData, Function& function)
        {  
            typedef typename ReflectedClass::template 
                GetNameTag<Pos>::type
                CurrentAttributeTag;
            function(recordData.getByTag(CurrentAttributeTag()),
                    CurrentAttributeTag(),&recordData);
        }
    };
    template<class Function, int RestToDo> struct Iter: 
             SingleAttributeHelper<TotalNumAttributes-RestToDo>
    {
        static void process(ReflectedClass& recordData, Function& function)
        {
            processSingleAttribute(recordData,function);
            Iter<Function,RestToDo-1>::process(recordData,function);
        }
    };
    template<class Function> struct Iter<Function,1>:
                    SingleAttributeHelper<TotalNumAttributes-1>
    {
        static void process(ReflectedClass& recordData,
                            Function& function)
        {
            processSingleAttribute(recordData,function);
        }
    };
    template<class Function> static void 
    doForeach(ReflectedClass& dataTuple, Function& function)
    {
        Iter<Function,TotalNumAttributes>::process(dataTuple,function);
    }
};
template<class ReflectedClass, class Function> 
void foreachAttribute(ReflectedClass& dataTuple, Function& function)   
{
    AllAttributes<ReflectedClass>::doForeach(dataTuple, function);
}