1
我有一个类接受使用boost :: mpl的策略类列表。每个策略类都包含一个识别标签。我希望MyClass生成每个策略类'标识标签的OR-ed结果。不幸的是,我在计算如何正确使用boost :: mpl :: fold功能时遇到了一些麻烦。如果有人能帮助,我将不胜感激。使用boost :: mpl :: bitor_
#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;
}
感谢, PaulH
我现在明白了。谢谢你的帮助。 – PaulH 2009-10-21 13:22:28