I am using smart pointers on my current project, and it seems very cumbersome to have to type long lines of code when using them.
Because I wanted my code to be cleaner and easier to follow I started typedef-ing smart pointers like such:
typedef std::unique_ptr<System> SystemPtr;
So my question is, is it bad practice to typedef a smart pointer?
There is nothing wrong with it, but your choice of name is horrible. Someone reading that has no clue if that is a shared pointer, a unique pointer, an intrusive reference counting com pointer, or just a raw pointer to System
.
If you really need brevity,
template<class T>using up=std::unique_ptr<T>;
is one more character at point of use than your plan up<System>
, and makes it more clear that this is a unique pointer, and does not require a typedef per type. Plus it leads to puns in some cases.
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