Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typedef of unique_ptr List

I'd like to make a typedef for std::list<std::unique_ptr<>>, so I could type PtrList<A> and it would be replaced by std::list<std::unique_ptr<A>>.

I know the way to do that with #define:

#define PtrList(x) std::list<std::unique_ptr<x>>

But I think typedef would be proper. However I don't know how to realize that. Could someone tell me how to typedef this ?

like image 919
Antoine C. Avatar asked Dec 17 '25 18:12

Antoine C.


1 Answers

First, try not to use #define to generate code. Except for conditional compilation, #define should be avoided.

A correct type alias:

template<class T> using PtrList = std::list<std::unique_ptr<T>>;

Example use:

PtrList<int> intPtrList; 
like image 104
utnapistim Avatar answered Dec 20 '25 08:12

utnapistim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!