David (dblume) wrote,

Sometimes you need lambda::bind()

Note to self, next time you mix smart pointers and lambda, remember what to do if things don't resolve automatically. Ex.

#include <iostream>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>

using namespace std;
using namespace boost;
using namespace lambda;

struct B {
  explicit B(int a) : a_(a) {}
  int get_a() const { return a_; }
  int a_;

ostream& operator << (ostream &s, const B &b)
  s << b.get_a();
  return s;

int main()
  shared_ptr<B> b1(new B(10));
  shared_ptr<B> b2(new B(5));
  vector<shared_ptr<B> > v;
  for_each(v.begin(),v.end(), cout << *_1 << ' ');
  cout << endl;
  cout << count_if( v.begin(), v.end(), bind(&B::get_a, *_1) > 7);
Tags: programming

  • Progress on my Google+ and LJ backups

    Since Google is going to shut down Google+, I decided it was time to really make a home for my LiveJournal backup and my Google+ backup. Working…

  • Getting Shit Done

    I came across an old LifeHacker article Get Shit Done Blocks Distracting Web Sites So You Can Do As the Name Instructs, that mentions a productivity…

  • Happy Birthday, Me. I got you data portability!

    My list of addresses has made its way from a physical address book, to a Palm Pilot, to Microsoft Outlook, to Google Contacts to the iPhone Contacts…

  • Post a new comment


    Comments allowed for friends only

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded