【发布时间】:2012-12-20 15:33:47
【问题描述】:
下面的 boost 代码是否可以转换为纯 c++11 标准库?
我看到了std::tuple 和std::for_each,但我似乎无法让他们一起玩。
我目前使用的是 gcc 4.7.2。
代码
#include <string>
#include <algorithm>
#include <iostream>
#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/fusion/include/boost_tuple.hpp>
struct DoOutput
{
template<typename T>
void operator()(T const& t) const
{
std::cerr << t << std::endl;
}
void operator()(std::string const& t) const
{
std::cerr << "'" << t << "'" << std::endl;
}
};
int
main( int argc, char* argv[] )
{
boost::tuple< std::string, int > t = boost::make_tuple( "foo", 42 );
boost::fusion::for_each( t, DoOutput() );
return 0;
}
【问题讨论】: