C++ boost::lambda std::map

C++ boost::lambda std::map,c++,boost,lambda,bind,boost-lambda,C++,Boost,Lambda,Bind,Boost Lambda,我想通过使用boost::lambda简化我的代码。这是我的密码: // Declare container: typedef std::map< PageId, Page* > Pages; Pages m_pages; // For serialization: template < class DataType > TPair< DataType > makePair( const std::string& identification, co

我想通过使用boost::lambda简化我的代码。这是我的密码:

// Declare container:
typedef std::map< PageId, Page* > Pages;
Pages m_pages;

// For serialization:
template < class DataType > TPair< DataType > makePair( const std::string& identification, const DataType& dataType )
{
    return TPair< DataType >( identification, dataType );
}

#define SERILIZE_CLASS( _value ) ::Tools::Serilizer::makePair< ::Tools::Serilizer::Serilizable >( EXTRACT_NAME( _value ), _value )



// This does work and should be simplified by....
for( BOOST_AUTO( i, m_pages.begin( ) ); i != m_pages.end( ); ++i )
{
    obj << SERILIZE_CLASS( *i->second );
}

// this code but itdoes not compile
std::for_each( m_pages.begin( ), m_pages.end( ), 
obj << SERILIZE_CLASS( boost::lambda::bind( &Pages::value_type::second, boost::lambda::_1 ) ) );
//声明容器:
typedef std::mapPages;
页面Mu页面;
//对于序列化:
模板TPairmakePair(const std::string&identification,const DataType&DataType)
{
返回TPair(标识,数据类型);
}
#定义SERILIZE_类(_值)::工具::Serilizer::makePair<::工具::Serilizer::Serilizable>(提取_名称(_值),_值)
//这是可行的,应该简化为。。。。
for(BOOST_AUTO(i,m_pages.begin());i!=m_pages.end();+i)
{
obj(第二);
}
//这是一段代码,但它不编译
std::for_each(m_pages.begin(),m_pages.end(),

obj我认为您的问题是将lambdas(即函数)与lambdas返回的值混合在一起:

例如:

boost::lambda::bind( &Pages::value_type::second, boost::lambda::_1 )
返回一个函数

所以调用带有结果的
序列化类(…)
对我来说没有意义


也就是说,我没有深入研究您的代码。我发现它有点混乱。

Boost.Lambda已被正式弃用;请在新代码中使用。我认为您是对的。使用Boost::Lambda::bind(&Pages::value\u type::second,Boost::Lambda::\u 1)我只想访问map::pair的第二项。但结果是一个函子。有什么建议如何处理?