libmoost
|
Namespaces | |
namespace | detail |
Functions | |
template<typename Sequence , typename Policy > | |
Policy::return_type | search (const Policy &policy) |
Policy::return_type moost::mpl::search | ( | const Policy & | policy | ) | [inline] |
Search type in a type list according to a policy
This template attempts to find a type in a type list using the policy's test() method and then either calls the policy's found() or not_found() method.
Here's an example policy for implementing an object factory:
class factory_policy { public: typedef base *return_type; factory_policy(const std::string& name) : m_name(name) { } template <class T> bool test() const { return m_name == T::name(); } template <class T> return_type found() const { return new T(); } return_type not_found() const { throw std::runtime_error("unknown class " + m_name); } private: const std::string& m_name; };
You could then use the policy like this:
factory_policy policy(name); base *obj = search<class_list>(policy);
Definition at line 120 of file search.hpp.