Boost logo

Boost Users :

From: Christian Henning (chhenning_at_[hidden])
Date: 2007-03-26 16:14:33


Thanks Daniel, my mistake.

On 3/26/07, Daniel <boost_at_[hidden]> wrote:
> > Date: Mon, 26 Mar 2007 11:24:08 -0400
> > From: "Christian Henning" <chhenning_at_[hidden]>
> > Subject: [Boost-users] [bind] static array vs. pointer vector
> > To: boost-users_at_[hidden]
> > Message-ID:
> > <949801310703260824n31c76204pcd63bb686169e15c_at_[hidden]>
> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> >
> > Hi there, I have posted this question last Friday, already. But maybe
> > my example was too confusing. Here is a more simple example.
> > Basically, I don't see what the big difference is when using
> > boost::bind with a pointer vector ( std::vector<info*> ) and a static
> > array of info.
> >
> > Please consider the following code:
> >
> > #include <string>
> > #include <algorithm>
> > #include <functional>
> > #include <vector>
> >
> > #include <boost/bind.hpp>
> >
> > using namespace std;
> > using namespace boost;
> >
> > struct info
> > {
> > int a;
> > string s;
> > };
> >
> > static info table[] =
> > {
> > { 16, "Hello" },
> > { 18, "Moin" }
> > };
> >
> > string& get_s( info* p )
> > {
> > return p->s;
> > }
> >
> > int _tmain(int argc, _TCHAR* argv[])
> > {
> > {
> > vector<info*> v;
> > find_if( v.begin(), v.end()
> > , bind( equal_to<string>()
> > , bind( &get_s, _1 )
> > , "Moin" ));
> > }
> >
> > {
> > find_if( &table[0], &table[0] + 2
> > , bind( equal_to<string>()
> > , bind( &get_s, _1 )
> > , "Moin" ));
> >
> > }
> > }
> >
> > The second find_if wont complie using MSVC 7.1. The errors are:
> >
> > c:\boost\boost\bind.hpp(219) : error C2664: 'std::string &(info *)' :
> > cannot convert parameter 1 from 'info' to 'info *'
> [snip]
> >
> > Any ideas?
> >
> > Christian
>
> In 1st case, when you dereference vector<info*> iterator, you will get
> info* pointer. But in 2nd case, your iterator is info* pointer, so you
> get info object when you dereference it. This is also mentioned at
> beginning of error message - "cannot convert parameter 1 from 'info' to
> 'info *'". Therefore you should change your get_s() function to accept
> info (or info&), or your binding expression to convert info to info*.
>
> Daniel
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net