据我所知,这是
#include <boost/mpl/list.hpp>
#include <algorithm>
namespace mpl = boost::mpl;
class RunAround {};
class HopUpAndDown {};
class Sleep {};
template<typename Instructions> int doThis();
template<> int doThis<RunAround>() { /* run run run.. */ return 3; }
template<> int doThis<HopUpAndDown>() { /* hop hop hop.. */ return 2; }
template<> int doThis<Sleep>() { /* zzz.. */ return -2; }
int main()
{
typedef mpl::list<RunAround, HopUpAndDown, Sleep> acts;
// std::for_each(mpl::begin<acts>::type, mpl::end<acts>::type, doThis<????>);
return 0;
};
我该如何完成这个? (我不知道是否应该使用 std::for_each,只是根据此处的另一个答案进行猜测)
Use mpl::for_each用于类型列表的运行时迭代。例如。:
struct do_this_wrapper {
template<typename U> void operator()(U) {
doThis<U>();
}
};
int main() {
typedef boost::mpl::list<RunAround, HopUpAndDown, Sleep> acts;
boost::mpl::for_each<acts>(do_this_wrapper());
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)