Boost logo

Boost :

From: Michael Nicolella (boost_at_[hidden])
Date: 2006-07-28 14:37:58


Because you're passing a function pointer to bind() - but you didn't say
which version of print_template you want to pass... I think you run into the
same ambiguity with overloaded functions.

-----Original Message-----
From: Joe Van Dyk [mailto:joevandyk_at_[hidden]]
Sent: Friday, July 28, 2006 11:23 AM
To: boost_at_[hidden]
Subject: Re: [boost] lamda question

On 7/27/06, Joe Van Dyk <joevandyk_at_[hidden]> wrote:
> On 7/27/06, Kevin Spinar <spinarkm_at_[hidden]> wrote:
> > On 7/27/06, Joe Van Dyk <joevandyk_at_[hidden]> wrote:
> > > I have Boost 1.33.1 installed. I'm trying to use Boost.Lamda.
> > >
> > > I included all the headers mentioned in the documentation as an
> > > attempt to fix the compile error.
> > >
> > > #include <boost/lambda/lambda.hpp>
> >
> > [snip unneeded includes]
> >
> > #include <algorithm>
> >
> > > #include <list>
> > >
> > > int main()
> > > {
> > > using namespace std;
> > > using boost::lambda;
> > >
> > > list<int> v(10);
> > > for_each(v.begin(), v.end(), _1 = 1);
> > > }
> > >
> > >
> > > % g++ lambda.cpp
> >
> > you should compile with -W -Wall -pedantic -ansi at a minimum.
> >
> > > lambda.cpp: In function `int main()':
> > > lambda.cpp:20: error: `_1' undeclared (first use this function)
> > > lambda.cpp:20: error: (Each undeclared identifier is reported only
once for
> > > each function it appears in.)
> > >
> > > Using gcc 3.3.1.
> >
> > Consider upgrading to gcc 4. With gcc 4, I get:
> >
> > error: namespace 'boost::lambda' not allowed in using-declaration
>
> Ah, thanks. I needed
> using namespace boost::lambda;
>
> Joe
>

Another one:

#include <iostream>
#include <functional>
#include <list>
#include <algorithm>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>

using namespace std;

template<class T> void print_template(const T& value)
{
   cout << "value: " << value << endl;
}

void print(const int& value)
{
   cout << "value: " << value << endl;
}

int main()
{
   using namespace boost::lambda;

   list<int> v;
   v.push_back(3);
   v.push_back(4);
   v.push_back(5);
   for_each(v.begin(), v.end(), bind(print, _1)); // Works

   // Why doesn't this work?
   // for_each(v.begin(), v.end(), bind(print_template, _1));
}
_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk