What is “template<class T> using owner = T;”?

我只是一个虾纸丫 提交于 2019-12-12 08:11:58

问题


Below is excerpted from gsl.h of Microsoft's 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 cannot understand what the following alias template means:

template<class T>
using owner = T;

Any explanations?


回答1:


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




回答2:


It can be used as annotation to show which pointers are 'owner' ie:

Example of non owning raw pointer

template<typename T>
class X2 {
    // ...
public:
    owner<T*> p;  // OK: p is owning
    T* q;         // OK: q is not owning
};


来源:https://stackoverflow.com/questions/38449366/what-is-templateclass-t-using-owner-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!