20 #ifndef MULTI_POLICY_CONTAINER_H_
21 #define MULTI_POLICY_CONTAINER_H_
25 #include <boost/mpl/inherit_linearly.hpp>
26 #include <boost/mpl/at.hpp>
33 template<
class Base,
class Value>
35 policy_wrap(Base& base)
42 template<
class Base,
class Super ,
44 struct inherit_with_base : Super, Value {
45 inherit_with_base(Base& base)
52 update(
typename Base::iterator item)
54 Value::value_.update(item);
59 insert(
typename Base::iterator item)
61 bool ok = Value::value_.insert(item);
65 ok = Super::insert(item);
67 Value::value_.erase(item);
74 lookup(
typename Base::iterator item)
76 Value::value_.lookup(item);
81 erase(
typename Base::iterator item)
83 Value::value_.erase(item);
90 Value::value_.clear();
96 struct empty_policy_wrap {
97 empty_policy_wrap(Base& base)
102 update(
typename Base::iterator item)
106 insert(
typename Base::iterator item)
111 lookup(
typename Base::iterator item)
115 erase(
typename Base::iterator item)
124 template<
class Base,
class Vector>
125 struct multi_policy_container
126 :
public boost::mpl::
127 fold<Vector, empty_policy_wrap<Base>,
128 inherit_with_base<Base, boost::mpl::_1 ,
129 policy_wrap<Base, boost::mpl::_2> >>::type {
130 typedef typename boost::mpl::
131 fold<Vector, empty_policy_wrap<Base>,
132 inherit_with_base<Base, boost::mpl::_1 ,
133 policy_wrap<Base, boost::mpl::_2> >>::type super;
135 typedef typename boost::mpl::at_c<Vector, 0>::type::iterator iterator;
136 typedef typename boost::mpl::at_c<Vector, 0>::type::const_iterator const_iterator;
141 return this->get<0>().begin();
146 return this->get<0>().begin();
152 return this->get<0>().end();
157 return this->get<0>().end();
163 return this->get<0>().size();
166 multi_policy_container(Base& base)
173 typedef typename boost::mpl::at_c<Vector, N>::type type;
180 return static_cast<policy_wrap<Base, T>&
>(*this).value_;
187 return static_cast<const policy_wrap<Base, T>&
>(*this).value_;
191 typename boost::mpl::at_c<Vector, N>::type&
194 typedef typename boost::mpl::at_c<Vector, N>::type T;
195 return static_cast<policy_wrap<Base, T>&
>(*this).value_;
199 const typename boost::mpl::at_c<Vector, N>::type&
202 typedef typename boost::mpl::at_c<Vector, N>::type T;
203 return static_cast<const policy_wrap<Base, T>&
>(*this).value_;
214 #endif // MULTI_POLICY_CONTAINER_H_