我想通過使用boost :: lambda簡化我的代碼。這裏是我的代碼:boost :: lambda std :: map
// 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)));
最後,這是所產生的錯誤代碼:
錯誤C2664: '工具:: Serilizer :: makePair':不能將參數2從「常量的boost ::拉姆達:: lambda_functor'到'const Tools :: Serilizer :: Serilizable &'
任何提示如何解決這個問題?
Boost.Lambda已正式被棄用;請使用[Boost.Phoenix](http://www.boost.org/libs/phoenix/)代替新代碼。 – ildjarn 2012-04-15 16:47:27