What is the "template <class T> using owner = T;"?
Below are excerpts from the gsl.h Microsoft gsl library ( https://github.com/microsoft/gsl ):
namespace gsl { // // GSL.owner: ownership pointers // using std::unique_ptr; using std::shared_ptr; template<class T> using owner = T; ... }; I do not understand what the following alias pattern means:
template<class T> using owner = T; Any explanation?
+5
2 answers
It can be used as an annotation to show which pointers are the "owner", ie:
Example of not owning a raw pointer
template<typename T> class X2 { // ... public: owner<T*> p; // OK: p is owning T* q; // OK: q is not owning }; 0