0

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 ?

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Maik
  • 541
  • 4
  • 15
  • Boost.Lambda is officially deprecated; please use [Boost.Phoenix](http://www.boost.org/libs/phoenix/) instead in new code. – ildjarn Apr 15 '12 at 16:47

1 Answers1

0

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.

cdiggins
  • 17,602
  • 7
  • 105
  • 102
  • I think you are right. With boost::lambda::bind( &Pages::value_type::second, boost::lambda::_1 ) I only want to access the second term of the map map::pair. But the result is a functor. Any suggestions how to handle this ? – Maik Apr 15 '12 at 17:19