I'd like to reduce some visual noise in the code and hide shared_ptr
behind a typedef like this:
typedef boost::shared_ptr<SomeLongClass> SomeLongClassPtr;
So this:
void foo(const boost::shared_ptr<SomeLongClass>& a,
boost::shared_ptr<SomeLongClass>& b);
becomes this:
void foo(const SomeLongClassPtr& a, SomeLongClassPtr& b);
On the other hand I'm worried that I'm reducing the explicitness of the code.
Which is a better style?
Given that std::string is itself a typedef, I think you are fine. I do it myself.
Even Scott Meyers recommends typedef for ease of reading code in cases like yours.
EDIT: Effective C++, Second Edition, Page 120, Item 28, fourth paragraph. "...provide typedefs that remove the need..."
More Effective C++, 7th printing, Page 237, Item 31 First paragraph.
More Effective C++, 7th printing, Page 238, Item 31 First paragraph after code sample.
In essence, no worries. :-)
We use TypePtr
typedefs in our code for shared_ptr<Type>
objects. It is also useful to have a TypeConstPtr
for shared_ptr<const Type>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With