From: Sergey Sadovnikov [mailto:flex_ferrum@artberg.ru]
Sent: Thursday, February 05, 2009 10:02 PM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] boost and std collisons in c++0x

MF> If you want to use boost, use boost::.  If you want to use the STD

MF> library, use std::.

Perfectly! What you can say about following pieces of code:


std::vector<std::shared_ptr<SomeClass>> vec;

std::for_each(vec.begin(), vec.end(), std::bind(&std::shared_ptr<SomeClass>::get, std::placeholders::_1, std::bind(&SomeClass::foo, std::placeholders::_1, 10)));


and


vector<shared_ptr<SomeClass>> vec;

for_each(vec.begin(), vec.end(), bind(&shared_ptr<SomeClass>::get, _1, bind(&SomeClass::foo, _1, 10)));

 

 

Here's what I do, for every class that's put in shared_ptr's (I'm very disciplined in this way):

 

// SomeClassFwd.h:

 

class SomeClass;

typedef std::shared_ptr<SomeClass> SomeClassPtr;

typedef std::vector<SomeClassPtr> SomeClassCollection;

 

Now, your code becomes:

 

SomeClassCollection vec;

std::for_each(vec.begin(),
              vec.end(),
              std::bind(&SomeClassPtr::get,
                        std::placeholders::_1,
                        std::bind(&SomeClass::foo, std::placeholders::_1, 10)));

I would agree C++ can be very verbose. Using typedef can limit this a lot though.

 

/Daniel Lidström