I have a class that accepts a list of policy classes using boost::mpl. Each policy class contains an identifying tag. I would like MyClass to produce the OR-ed result of each policy class' identifying tag. Unfortunately, I'm having some trouble figuring out how to correctly use the boost::mpl::fold<> functionality. If anybody can help, I would appreciate it.
#include <boost/mpl/vector.hpp>
#include <boost/mpl/bitor.hpp>
#include <boost/mpl/inherit.hpp>
#include <boost/mpl/inherit_linearly.hpp>
namespace bmpl = boost::mpl;
template< class ListOfPolicies >
class CMyClass : public bmpl::inherit_linearly< ListOfPolicies, bmpl::inherit< bmpl::_1, bmpl::_2 > >::type
{
public:
int identifier() const
{
// error C2039: 'tag' : is not a member of 'PolicyA'
return bmpl::fold< ListOfPolicies, bmpl::int_< 0 >, bmpl::bitor_< bmpl::_1, bmpl::_2 > >::value
}
};
template< class T >
class PolicyA
{
public:
enum { MY_IDENTIFIER = 0x00000001 };
};
class PolicyB
{
public:
enum { MY_IDENTIFIER = 0x00000010 };
};
int _tmain(int argc, _TCHAR* argv[])
{
CMyClass< PolicyA, PolicyAB > AB
assert( AB.identifier() == ( PolicyA::MY_IDENTIFIER | PolicyB::MY_IDENTIFIER ));
return 0;
}
Thanks, PaulH