C++ boost mpl vector
- by Gokul
I understand that the following code won't work, as i is a runtime parameter and not a compile time parameter. But i want to know, whether there is a way to achieve the same. i have a list of classes and i need to call a template function, with each of these classes.
void 
GucTable::refreshSessionParams()
{
    typedef  boost::mpl::vector< SessionXactDetails, SessionSchemaInfo  >   SessionParams;
    for( int i = 0; i < boost::mpl::size<SessionParams>::value; ++i )
        boost::mpl::at<SessionParams, i>::type* sparam = 
                        g_getSessionParam< boost::mpl::at<SessionParams, i>::type >();
        sparam->updateFromGucTable(this);
    } 
}
Can someone suggest me a easy and elegant way to perform the same? i need to iterate through the mpl::vector and use the type to call a global function and then use that parameter to do some run-time operations.
Thanks in advance,
Gokul.
Working code
typedef  boost::mpl::vector< SessionXactDetails, SessionSchemaInfo  >   SessionParams;
class  GucSessionIterator
{
private:
    GucTable& m_table;
public:
    GucSessionIterator(GucTable& table)
        :m_table(table)
    {
    }
    template< typename U > void operator()(const U& )
    {
        g_getSessionParam<U>()->updateFromGucTable(m_table);
    }
};
void 
GucTable::refreshSessionParams()
{
    boost::mpl::for_each< SessionParams >( GucSessionIterator(*this) );
    return;
}