Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad practice to typedef a smart pointer? [closed]

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?

like image 945
Belfer4 Avatar asked Aug 24 '15 00:08

Belfer4


1 Answers

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.

like image 155
Yakk - Adam Nevraumont Avatar answered Sep 18 '22 23:09

Yakk - Adam Nevraumont