|
Boost Users : |
Subject: Re: [Boost-users] boost and std collisons in c++0x
From: Daniel Lidström (daniel.lidstrom_at_[hidden])
Date: 2009-02-10 04:30:24
_____
From: Sergey Sadovnikov [mailto:flex_ferrum_at_[hidden]]
Sent: Thursday, February 05, 2009 10:02 PM
To: boost-users_at_[hidden]
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
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