Boost logo

Boost Users :

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


Thanks David. Must be Monday, again. ;-)

Here the working code:

#include <string>
#include <algorithm>
#include <functional>
#include <vector>

#include <boost/any.hpp>
#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[])
{
   {
      info* p = find_if( &table[0], &table[0] + 2
             , bind( equal_to<string>()
                   , bind( &get_s, _1 )
                   , "Hello" ));

      assert( p != &table[0] + 2 );

   }
}

On 3/26/07, David Klein <dave_chp_at_[hidden]> wrote:
> Christian Henning wrote:
> > 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.
> >
> > string& get_s( info* p )
> > {
> > return p->s;
> > }
> >
> >
> Shouldn't this be:
>
> string & get_s( info & ) {...}
>
> because you have 'info' and not 'info *' in the array?
>
> --
> Regards,
> dave
>
> _______________________________________________
> 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