using owner = T;"? Below are excerpts from the gsl.h Microsoft gsl library ( https://github.com/microsoft/gsl ): ...">

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
source share
2 answers

This means that for every T , owner<T> is an alias for T

+5
source

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
source

All Articles