$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-03-17 05:55:11
Kevin Wheatley wrote:
> Subsequently, the containers now contain std::pair's to shared_ptrs,
> so I have even more composition going on, which for a one off
> 'function' is getting messy, with Lambda it should be much simpler so
> I'd certainly like to know if I missed something with this.
Extracting a member of a pair is equally painful with Bind and Lambda: 
bind(&Pair::second, _1). Lambda also supports _1->*&Pair::second for 
ordinary pointers, but not for shared_ptr, where you'll need something like 
&*_1->*&Pair::second.
The current CVS bind now supports
!bind(...)
bind(...) == value
bind(...) == _1
bind(...) == bind(...)
and similarly for !=, <, <=, >, >=. You may be able to avoid some of the 
compositions.
Other notable differences between Bind and the bind subset of Lambda are the 
number of supported placeholders and support for function<>::contains. They 
also differ in their handling of the first argument when it's a nested 
lambda/bind expression or a placeholder; Lambda can do bind( _1, _2 ), Bind 
cannot. Bind also respects its const qualifier so that when a non-const 
bind( f, 1 ) is called, the non-const operator() of f is called and it can 
mutate the stored copy of 1. Most of these are of no concern for ordinary 
use. Well, maybe except for cool examples:
#include <boost/bind.hpp>
#include <algorithm>
#include <iostream>
#include <iterator>
int next( int & x )
{
    return ++x;
}
int main()
{
    std::generate_n( std::ostream_iterator<int>( std::cout, " " ), 8,
        boost::bind( next, 0 ) );
}