$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Matyas W Egyhazy (megyha80_at_[hidden])
Date: 2006-09-04 01:37:00
Hello,
I am confused about why two certain lamba expressions work (on VC8) 
while two others do not.  I do not profess to be any sort of expert in 
boost lambda expressions.  This code is being executed in a function 
which is a friend of a template "takostack".  Basically, this function 
deals with a member "contents_" that is a scoped_array of scoped_ptrs.  
It is supposed to iteratively call the << operator for the elements of 
contents_ scoped_array.
template<typename O>
std::ostream& operator<< (std::ostream& os, const 
takostack<boost::scoped_ptr<O> >& s)
{
      /* Works, not sure why */
        for (int i(0); i < s.top_; ++i)
        {
            os << *(&boost::scoped_ptr<O>::get,
                boost::lambda::_1)(s.contents_[i]) << " ";
        }
        /* Works, not sure why */
        std::for_each(&s.contents_[0], &s.contents_[0] + s.top_,
            os << *(&boost::scoped_ptr<O>::get, 
boost::lambda::_1)(boost::lambda::_1)
            << " ");
       
        /* Does not work, don't know why
            std::for_each(&s.contents_[0], &s.contents_[0] + s.top_,
            os << *(boost::lambda::_1 ->* 
&boost::scoped_ptr<O>::get)(boost::lambda::_1)
            << " ");
        */
        /* Does not work, don't know why
            std::for_each(&s.contents_[0], &s.contents_[0] + s.top_,
            os << *(boost::bind(&boost::scoped_ptr<O>::get, 
boost::lambda::_1)(boost::lambda::_1))
            << " ");
        */
}
Basically, I would like to understand why compilation succeeds without 
using bind, and fails when bind or the member pointer operator is used.
The first failed example fails with:
Error    131    error C2784: 'const 
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<Action>,boost::tuples::tuple<boost::lambda::lambda_functor<T>>>> 
boost::lambda::operator *(const boost::lambda::lambda_functor<T> &)' : 
could not deduce template argument for 'const 
boost::lambda::lambda_functor<T> &' from 
'boost::lambda::detail::member_pointer_caller<RET,A,B>'    
d:\source\c\takostack\takostack\takostack.h    135   
Error    132    error C2100: illegal indirection    
d:\source\c\takostack\takostack\takostack.h    135   
Error    133    error C2679: binary '<<' : no operator found which takes 
a right-hand operand of type 
'boost::lambda::detail::member_pointer_caller<RET,A,B>' (or there is no 
acceptable conversion)    d:\source\c\takostack\takostack\takostack.h    
135   
The second failed example fails with:
Error    131    error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' 
: cannot access private member declared in class 
'std::basic_ios<_Elem,_Traits>'    D:\Microsoft Visual Studio 
8\VC\include\ostream    581   
Thanks,
Matt