boost::lambda std::map

不羁的心 提交于 2019-12-13 05:50:01

问题


I want to simplify my code by using boost::lambda. Here is my code:

// 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 ) ) );

Finally this is the resulting error code:

error C2664: 'Tools::Serilizer::makePair' : cannot convert parameter 2 from 'const boost::lambda::lambda_functor' to 'const Tools::Serilizer::Serilizable &'

Any hints how to solve this ?


回答1:


I think your problem is mixing lambdas (that is functions) with the values returned by the lambdas:

For example:

boost::lambda::bind( &Pages::value_type::second, boost::lambda::_1 )

Returns a function.

So calling serialize_class(...) with its result doesn't make sense to me.

That said, I haven't studied your code in much depth. I found it a bit confusing.



来源:https://stackoverflow.com/questions/10163980/boostlambda-stdmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!